怎么样让第二个
单片机收不到信号的时候让车子停下来?
————————————————————————————我是华丽的分割线——————————————————————————————————
程序:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define key_port P0
#define dis_pors P1
#define dis_port P2
void delay(unsigned char delay_
time)
{
unsigned char i;
while(delay_time--)
for(i=0;i<125;i++);
}
void main (void)
{
uchar key_in=0xff;
SCON=0x50;
TMOD=0x20;
TH1=0xFD;
TR1 = 1;
EA = 1;
ES = 1;
while(1)
{
if (key_in != key_port)
{
delay(10);
if (key_in != key_port)
key_in = key_port;
if((P3&0x80)==0)
{
SBUF=key_in;
}
else
{
SBUF=~key_in;
}
}
}
}
void get_disp (void) interrupt 4 using 0
{
if(RI)
{
if((SBUF)==0x01) dis_pors=0xf9;
else if((SBUF)==0x02) dis_pors=0xf6;
else if((SBUF)==0x04) dis_pors=0xf5;
else if((SBUF)==0x08) dis_pors=0xfa;
else if((SBUF)==0x10) dis_pors=0xef;
else if((SBUF)==0x20) dis_pors=0xdf;
else if((SBUF)==0x40) dis_pors=0xbf;
else if((SBUF)==0x80) dis_pors=0x7f;
else dis_pors=0xff;
if((SBUF)==0xfe) dis_port=0xfe;
else if((SBUF)==0xfd) dis_port=0xfd;
else if((SBUF)==0xfb) dis_port=0xfb;
else if((SBUF)==0xf7) dis_port=0xf7;
else if((SBUF)==0xef) dis_port=0xef;
else if((SBUF)==0xdf) dis_port=0xdf;
else if((SBUF)==0xbf) dis_port=0xbf;
else if((SBUF)==0x7f) dis_port=0x7f;
else dis_port=0xff;
RI=0;
}
else TI=0;
}
一周热门 更多>