您的位置 首页 ADAS

双片机简略通讯及仿真图

includereg52h>includeintrinsh>defineucharunsignedchardefineuintunsignedintsbitkey1=P1^0;sbitke

#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–);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/adas/260572.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部