我在书上看了一个单片机89c52的通讯程序,但不知道为什么不能编译,大神帮帮我,谢谢。
下面是书本里的程序
#include
#define uchar unsigned char
#define uint unsigned int
void delayms(uint xms)
{
uint i,j;
for(i=xms;i0;i--)
for(j=100;j0;j--);
}
void send(uchar key_num)
{
SBUF=key_num;
while(!TI )
TI=0;
}
void matrixkeyscan()
{
uchar temp,key;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
}
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
key=0;
break;
case 0xde:
key=1;
break;
case 0xbe:
key=2;
break;
case 0x7e:
key=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
send(key);
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
key=4;
break;
case 0xdd:
key=5;
break;
case 0xbd:
key=6;
break;
case 0x7d:
key=7;
break;
}
}
while(temp=!0xf0)
{
temp=P3;
temp=tenmp&0xf0;
}
send(key);
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10) ;
temp=P3;
temp=temp&0xf0;
if(temp!=0xfe)
{
temp=P3;
switch(temp)
{
case 0xeb:
key=8;
break;
case 0xdd:
key=9;
break;
case 0xbb:
key=10;
break;
case 0x7b:
key=11;
break;
}
while(temp=!0xf0)
{
temp=P3;
temp=tenmp&0xf0;
}
send(key);
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10) ;
temp=P3;
temp=temp&0xf0;
if(temp!=0xfe)
{
temp=P3;
switch(temp)
{
case 0xe7:
key=12;
break;
case 0xd7:
key=13;
break;
case 0xb7:
key=14;
break;
case 0x77:
key=15;
break;
}
while(temp=!0xf0)
{
temp=P3;
temp=tenmp&0xf0;
}
send(key);
}
}
void main()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
while(1)
{
matrixkeyscan();
}
}