程序如下
uchar num;
uchar flag;
uchar RBuf[4] = {0x00,0x00,0x00,0x00};
uchar i;
/*------------------主程序--------------------*/
void main(void)
{
uchar key = 0;
ConfigUART();
while(1)
{
if(flag == 1)//当接收到数据
{
ES = 0;//关闭串口中断
for(i=0;i<4;i++)
{
SBUF = RBuf[i];
while(!TI); TI = 0;
}
ES = 1;
flag = 0;
num = 0;
}
}
}
void Uart_Isr() interrupt 4 using 1
{
if(RI)
{
RBuf[4] = SBUF;
while(!RI);
RI = 0;
num++;
}
if(num == 4) flag = 1;
}
SBUF = RBuf[i];
while(!TI); TI = 0;
}
ES = 1;
flag = 0;
num = 0;
}
}
}
void Uart_Isr() interrupt 4 using 1
{
if(RI)
{
RBuf[4] = SBUF;
while(!RI);
RI = 0;
num++;
}
if(num == 4) flag = 1;
}
|