51串口存放数据
时间:10-02
整理:3721RD
点击:
databuf中存储了<AD_RST>,可是flag_uart没有变成1,为什么呢?
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar Ddata = 0;
uchar a;
char code dx516[3] _at_ 0x003b; //程序仿真时应加上,烧写时去掉
sbit Reset=P3^2;
sbit Ready= P3^3;
sbit Restart=P2^0;
sbit Error=P3^4;
uchar Temp,flag_uart,NumNow,databuf[8],i=0,flag1,flag;
unsigned char code *finger;
uchar Num;
char Array[17]= {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'} ;
void delay(unsigned int z)
{ unsigned int i,x;
for(i=120;i>0;i--)
for(x=z;x>0;x--);
}
void UartInit()
{
TMOD=0x20;
// TH1=0xfa; //波特率9600 , 22.1184 ,,,仿真时设置
// TL1=0xfa;
TH1=0xfd; //波特率9600,11.0592 ,,,烧写时设置
TL1=0xfd;
TR1=1; //开启定时器1
SM0=0;
SM1=1;
REN=1; //允许接收
EA=1; //开中断
ES=1;
}
void main(void)
{
//Ready = 0;
Temp = 0;
flag_uart = 0;
NumNow = 0;
i=0;
Reset = 0;
Num=0;
P1=0x00;
UartInit();
while(1)
{
if(flag_uart==1)
{
flag_uart=0;
ES=0;
if(databuf[7]=="<AD_RST>"){
P1=0x10;
delay(500);
P1=0x00;
ES=1;
i=0;
}
}
}
}
void serial() interrupt 4
{
RI=0;
databuf[i++]=SBUF;
if(i==0x08)
flag_uart=1;
}
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar Ddata = 0;
uchar a;
char code dx516[3] _at_ 0x003b; //程序仿真时应加上,烧写时去掉
sbit Reset=P3^2;
sbit Ready= P3^3;
sbit Restart=P2^0;
sbit Error=P3^4;
uchar Temp,flag_uart,NumNow,databuf[8],i=0,flag1,flag;
unsigned char code *finger;
uchar Num;
char Array[17]= {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'} ;
void delay(unsigned int z)
{ unsigned int i,x;
for(i=120;i>0;i--)
for(x=z;x>0;x--);
}
void UartInit()
{
TMOD=0x20;
// TH1=0xfa; //波特率9600 , 22.1184 ,,,仿真时设置
// TL1=0xfa;
TH1=0xfd; //波特率9600,11.0592 ,,,烧写时设置
TL1=0xfd;
TR1=1; //开启定时器1
SM0=0;
SM1=1;
REN=1; //允许接收
EA=1; //开中断
ES=1;
}
void main(void)
{
//Ready = 0;
Temp = 0;
flag_uart = 0;
NumNow = 0;
i=0;
Reset = 0;
Num=0;
P1=0x00;
UartInit();
while(1)
{
if(flag_uart==1)
{
flag_uart=0;
ES=0;
if(databuf[7]=="<AD_RST>"){
P1=0x10;
delay(500);
P1=0x00;
ES=1;
i=0;
}
}
}
}
void serial() interrupt 4
{
RI=0;
databuf[i++]=SBUF;
if(i==0x08)
flag_uart=1;
}
你怎么判断出它没有等于1呢?
虚拟串口仿真,看变量,watch1里面啊
需要i==8时才赋值呢,看看i吧