双片机简单通讯及仿真图


#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit led1=P0^0;
sbit led2=P0^1;
sbit led3=P0^2;
sbit led4=P0^3; 双片机简单通讯及仿真图
文章图片



uchar temp;
void send();
void diskey();
void delay(uint z);
void main()
{
EA=0;
TMOD=0x20;
TH1=0xf4;
TL1=0xf4;
PCON=0x00;
TR1=1;
SCON=0x50;
RI=0;
while(1)
{

diskey();
if(RI){RI=0; P0=SBUF; }
}

}
void send(uchar dat)
{
if(TI)
{
TI=0;
SBUF=dat;
}
else SBUF=dat;
}
【双片机简单通讯及仿真图】void diskey()
{
if(key1==0)
{
delay(10);
if(key1==0)
while(key1==0)
send(0xfe);
}
key1
if(key2==0)
{
delay(10);
if(key2==0)
while(key2==0)
send(0xfd);
}
key2
if(key3==0)
{
delay(10);
if(key3==0)
while(key3==0)
send(0xfc);
}
/key3
if(key4==0)
{
delay(10);
if(key4==0)
while(key4==0)
send(0xf7);
}
/key4
}
void delay(uint z)
{
uint x,y;
for(x=z; x>0; x--)
for(y=120; y>0; y--);
}

    推荐阅读