#define TRUE 1
#define FALSE 0
//$1234567<0x0d><0x0a>
char RxBuf[MAX_BUF_SIZE]; // string of valid data, without start/stop token('$', 0x0a, 0x0d)
int SzBuf; // number of valid data
void UartRxInt( void ) interrupt UART_RXINT_NUMBER
{
static int bStart = FALSE;
char c = SBUF;
if( c == '$' )
{
SzBuf = 0;
bStart = TRUE;
}
else if( bStart )
{
if( (c == '\n') && (RxBuf[SzBuf-1] == '\r') ) // if necessary, if(SzBuf > 0)
{
RxBuf[--SzBuf] = '\0'; // the RxBuf[] is an ANSI string '1234567' end with '\0'
bStart = FALSE; // end of transmit
}
else
{
RxBuf[SzBuf++] = c;
}
}
}
不保证正确,临时写的.我的目的是挣分,呵呵
51好久没用过,写错了心里骂一下吧 |