/*----------------------------
Send a byte data to UART
Input: dat (data to be sent)
Output:None
----------------------------*/
void SendData(BYTE dat)
{
while (busy); //Wait for the completion of the previous data is sent
ACC = dat; //Calculate the even parity bit P (PSW.0)
if (P) //Set the parity bit according to P
{
#if (PARITYBIT == ODD_PARITY)
S2CON &= ~S2TB8; //Set parity bit to 0
#elif (PARITYBIT == EVEN_PARITY)
S2CON |= S2TB8; //Set parity bit to 1
#endif
}
else
{
#if (PARITYBIT == ODD_PARITY)
S2CON |= S2TB8; //Set parity bit to 1
#elif (PARITYBIT == EVEN_PARITY)
S2CON &= ~S2TB8; //Set parity bit to 0
#endif
}
busy = 1;
S2BUF = ACC; //Send data to UART2 buffer
}
/*----------------------------
Send a string to UART
Input: s (address of string)
Output:None
----------------------------*/
void SendString(char *s)
{
while (*s) //Check the end of the string
{
SendData(*s++); //Send current char and increment string ptr
}
}