UINT8 UART_BUFFER[BUFFER_SIZE],temp;
UINT16 u16CNT=0,u16CNT1=0;
bit riflag;
sbit LED=P1^2;
/**
* FUNCTION_PURPOSE: serial interrupt, echo received data.
* FUNCTION_INPUTS: P3.0(RXD) serial input
* FUNCTION_OUTPUTS: P3.1(TXD) serial output
*/
void serial_IT(void) interrupt 4
{
if (RI)
{ /* if reception occur */
clr_RI; /* clear reception flag for next reception */
UART_BUFFER[u16CNT] = SBUF;
u16CNT ++;
riflag =1;
}
if(TI)
{
clr_TI; /* if emission occur */
}
}
/************************************************************************************************************
* Main function
************************************************************************************************************/
void main (void)
{
Set_All_GPIO_Quasi_Mode;
P06_Quasi_Mode; //Set UART GPIO are Quasi Mode
P07_Quasi_Mode;
InitialUART0_Timer1(9600); /* 115200 Baud Rate from timer1*/
SCON = 0xD2; // Special setting the mode 3
set_ES; //enable UART interrupt
set_EA; //enable global interrupt
clr_TB8;
Send_Data_To_UART0(0x53); //Send "start" ascii code show reset initial status
Send_Data_To_UART0(0x74);
Send_Data_To_UART0(0x61);
Send_Data_To_UART0(0x72);
Send_Data_To_UART0(0x74);
LED=0;
while(1)
{
if (riflag)
{
clr_ES;
SCON=0x40; //停止接收
temp = SBUF; //This part send the receive data from RXD to TXD
Send_Data_To_UART0(temp);
set_ES; //enable UART interrupt
SCON = 0xD2; //UART0 Mode1,REN=1,TI=1
riflag = 0;
LED=~LED;
}
}
}