|
2894| 2
|
單片機串口通訊接收數(shù)據(jù)時遇到的邏輯問題 |
|
1黑幣
最佳答案void UART_Interrupt (void) interrupt 4
{
static unsigned char i=0;
// if(RI)這個判斷無意義,既然進(jìn)入串口中斷RI必定=1
RI=0;
DateBuf=SBUF;
if(DateBuf[0]==0xff)//判斷數(shù)據(jù)串第一個字節(jié)正確,否則覆蓋掉
{
if(i==1)//判斷數(shù)據(jù)串第二個字節(jié)錯誤
{
if(DateBuf[1]!=0xc0)
{
i=0;
DateBuf[0]=0x00;//清除后重新接收
DateBuf[1]=0x00;
}
else i++;
}
else
{
...
| ||
相關(guān)帖子
|
||
| ||
| ||
Powered by 單片機教程網(wǎng)