This program was recommended by producing company for "Serial Communication with C51". But somewhere in the program "RXFRMOK" have to be = 0, haven't it?
**********************************************************************************
#define uchar unsigned char
#define uint unsigned int
bit RXAAOK; // The 0xAA header is received by serial port
bit RXFRMOK; // A valid data frame is received by serial port
bit TI0FLAG; // Send a TI sign back to the main program’s serial port
uchar RXBUF[32]; // Buffer is received and saved by serial port. But the buffer must be remove
// 0XAA frame head and the UART LCM response of un-fixed format has the
// length return. So it needs to record length
uchar Rx_P; // Data position is received and saved by serial port
void UART0_ISR() interrupt 4
{
uchar i;
if(RI)
{
i=SBUF;
RI=0;
if(RXFRMOK==0) //if RXFRMOK=1 means that the current data is not be processed in foreground and remove
{
if(RXAAOK) //received 0xAA
{
RXBUF[Rx_P]=i;
if((Rx_P>3) && (RXBUF[Rx_P-3]==0xCC) && (RXBUF[Rx_P-2]==0x33) && (RXBUF[Rx_P-1]==0xC3) && (RXBUF[RX_P]==0x3C))
{
RXFRMOK=1; // My question: When will RXFRMO be = 0 again ?
RXAAOK=0;
}
Rx_P++;
}
if(!RXAAOK && (i==0xaa))
{
RXAAOK=1; Rx_P=0;
}
}
}
if(TI) //********The interrupt is sent by serial port******************
{
TI=0;
TI0FLAG=1;
}
}
******************************************************************************************************