#if 1 //uart1,2 using T2
//uart1
SCON = 0x50;
#ifdef __DEBUG_VERSION__
S2CON = 0x50; //uart2
#endif
AUXR |= 0x04; //T2 1T
AUXR |= 0x01; //T2 for uart1
T2L = BAUD_RATE;
T2H = BAUD_RATE >> 8;
AUXR |= 0x10; //EN T2
ES = 1; //EN uart1
#ifdef __DEBUG_VERSION__
IE2 |= 0x01; //EN uart2
#endif
#endif
#if 0 //uart1 using T1, uart2 using T2
//T1 for uart1
SCON = 0x50;
AUXR = 0x40;
TMOD = 0x00;
TL1 = BAUD_RATE;
TH1 = BAUD_RATE >> 8;
TR1 = 1;
ES = 1;
//T2 for uart2
S2CON = 0x50;
AUXR |= 0x04;
T2L = BAUD_RATE;
T2H = BAUD_RATE >> 8;
AUXR |= 0x10;
IE2 |= 0x01;
#endif
EA = 1;
cpu.c
#ifdef __DEBUG_VERSION__
void uart2(void) interrupt 8{
if(S2CON & S2RI){
S2CON &= ~S2RI;
g_debug_uart_recvbuf[g_debug_uart_recvtail] = S2BUF;
g_debug_uart_recvtail = (g_debug_uart_recvtail + 1) % DEBUG_UART_RX_BUFSIZE;
}
if(S2CON & S2TI){
S2CON &= ~S2TI;
busy2 = 0;
}
}
#endif //__DEBUG_VERSION__
debug.c
void debug_recvmsg(void){
u8 ch;
u16 tmp_tail;
tmp_tail = g_debug_uart_recvtail;
if(tmp_tail != g_debug_uart_recvhead){
ch = g_debug_uart_recvbuf[g_debug_uart_recvhead];
g_debug_uart_recvhead = (g_debug_uart_recvhead + 1) % DEBUG_UART_RX_BUFSIZE;
debug_send(ch); //echo
tmp_tail = g_debug_uart_recvtail;
}
}
//send str
void debug(BYTE *str){
while(*str){
debug_send(*(str++));
}
}
//send byte
void debug_send(BYTE ch){
while(busy2);
busy2 = 1;
S2BUF = ch;
}