下面是我写的代码,用串口调试助手看发送字符串完全没有问题,但是接收字符串的时候,串口调试助手显示是正确的,但就是用strcmp判断字符串以后LED灯不亮是怎么回事啊?
真心求解答!!
#include<reg52.h>
#include<string.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa[28];
sbit k1=P2^7;sbit k2=P2^6;sbit k3=P2^5;sbit k4=P2^4;
sbit k5=P2^3;sbit k6=P2^2;
uchar code table1[22]="DATA-2-S1-1-0-1-0-DATA";
uchar code table2[22]="DATA-2-S1-1-0-2-0-DATA";
uchar code table3[22]="DATA-2-S1-1-0-3-0-DATA";
uchar code table4[22]="DATA-2-S1-1-0-4-0-DATA";
uchar code table5[28]="DATA-2-S1-1-0-5-T1,5400-DATA";
uchar code table6[22]="DATA-2-S1-1-0-6-0-DATA";
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void init()
{
EA=1;
ES=1;
REN=1;
SM0=0;
SM1=1;
TR1=1;
TMOD=0X20;
TH1=0XFD;
TL0=0XFD;
}
void send(uchar *dis)
{
while(*dis!=' ')
{
SBUF=*dis;
dis++;
while(!
ti);
TI=0; //软件请发送中断
}
}
void main()
{
uint a,m=0;
init();
while(1)
{
if(k1==0)
{
ES=0;
for(a=0;a<22;a++)
{
SBUF=table1[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(k2==0)
{
ES=0;
for(a=0;a<22;a++)
{
SBUF=table2[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(k3==0)
{
ES=0;
for(a=0;a<22;a++)
{
SBUF=table3[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(k4==0)
{
ES=0;
for(a=0;a<22;a++)
{
SBUF=table4[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(k5==0)
{
ES=0;
for(a=0;a<28;a++)
{
SBUF=table5[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(k6==0)
{
ES=0;
for(a=0;a<22;a++)
{
SBUF=table6[a];
while(!TI);
TI=0;
}
while(!k1);
ES=1;
}
if(strncmp(aa,"DATA-2-S1-1-0-1-0-DATA",22)==0)
P0=0XFE;
if(strncmp(aa,"DATA-2-S1-1-0-2-0-DATA",22)==0)
P0=0XFD;
if(strncmp(aa,"DATA-2-S1-1-0-3-0-DATA",22)==0)
P0=0XFB;
if(strncmp(aa,"DATA-2-S1-1-0-4-0-DATA",22)==0)
P0=0XF7;
if(strncmp(aa,"DATA-2-S1-1-0-5-T1,5400-DATA",28)==0)
P0=0XEF;
if(strncmp(aa,"DATA-2-S1-1-0-6-0-DATA",22)==0)
P0=0XDF;
}
}
void serial() interrupt 4
{
uchar n=0;
ES=0;
aa[n++]=SBUF;
RI=0;
send(aa); //用于提示收到的字符串
ES=1;
}
一周热门 更多>