384
Simulation
Explanation
Software UART is created with digital I/Os. Thus, the very first task we need to do is to initialize these
pins. The SW_UART header file states which pins and ports are used. So, you only need to set these
first. All of my codes are modular and so once you set these properly the functions and the definitions
associated take care of other tasks. This, in turn, makes the codes easily to use and ready for quick
modifications/deployments.
#define SW_UART_RXD_DIR P1DIR
#define SW_UART_TXD_DIR P1DIR
#define SW_UART_RXD_OUT P1OUT
#define SW_UART_TXD_OUT P1OUT
#define SW_UART_RXD_IN P1IN
#define SW_UART_RXD_IN_RES P1REN
#define SW_UART_RXD_PIN BIT1
#define SW_UART_TXD_PIN BIT2
Once the pins are set as per requirement, it is needed to initialize them for software UART
functionality.
void SW_UART_init(void)
{
SW_UART_TXD_DIR_OUT();
SW_UART_RXD_DIR_IN();
SW_UART_TXD_OUT_HIGH();
delay_ms(10);
}