#include
//发送程序
unsigned char l,h,key;
sbit cs=P3^7;
void delay(unsigned t)
{ while(t--);}
void main()
{
TMOD=0x20;
TH1=0xe8;
TL1=0xe8;
TR1=1;
SM1=1;
REN=1;
ES=1;
EA=1;
cs=1;
while(1)
{
P2=0xf0;
l=P2;
l=l&0xf0;
if(l!=0xf0)
{
delay(200);
if(l!=0xf0)
{
l=P2&0xf0;
l=l|0x0f;
P2=l;
h=P2;
h=h&0x0f;
l=l&0xf0;
key=h+l;
}
}
switch(key)
{
case 0xee:SBUF=0xc0;while(TI==0);TI=0;break;
case 0xde:SBUF=0xf9;while(TI==0);TI=0;break;
case 0xbe:SBUF=0xa4;while(TI==0);TI=0;break;
case 0x7e:SBUF=0xb0;while(TI==0);TI=0;break;
case 0xed:SBUF=0x99;while(TI==0);TI=0;break;
case 0xdd:SBUF=0x92;while(TI==0);TI=0;break;
case 0xbd:SBUF=0x82;while(TI==0);TI=0;break;
case 0x7d:SBUF=0xf8;while(TI==0);TI=0;break;
case 0xeb:SBUF=0x80;while(TI==0);TI=0;break;
case 0xdb:SBUF=0x90;while(TI==0);TI=0;break;
case 0xbb:SBUF=0x88;while(TI==0);TI=0;break;
case 0x7b:SBUF=0x83;while(TI==0);TI=0;break;
case 0xe7:SBUF=0xc6;while(TI==0);TI=0;break;
case 0xd7:SBUF=0xa1;while(TI==0);TI=0;break;
case 0xb7:SBUF=0x86;while(TI==0);TI=0;break;
case 0x77:SBUF=0x8e;while(TI==0);TI=0;break;
}
}
}
#include
//接收
sbit cs=P3^7;
void main()
{
TMOD=0x20;
TH1=0xe8;
TL1=0xe8;
TR1=1;
SM1=1;
REN=1;
ES=1;
EA=1;
cs=0;
while(1);
}
void receive() interrupt 4
{
P1=SBUF;
while(RI==0);
RI=0;
}
c:
MAX485.zip
阅读(345) | 评论(0) | 转发(0) |