十字路口交通灯的设计方案,是单片机(C语言)的编程!!1
发布网友
发布时间:2022-05-05 04:30
我来回答
共1个回答
热心网友
时间:2022-07-01 13:10
#include<reg51.h>
unsigned char t0,t1;
void delay0_5s1()
{
for(t0=0;t0<0x0a;t0++)
{
TH1=0x3c;
TL1=0xb0;
TR1=1;
while(!TF1);
TF1=0;
}
}
void delay_t1(unsigned char t)
{
for(t1=0;t1<t;t1++)
delay0_5s1();
}
void int_0() interrupt 0
{
unsigned char i,j,k,l,m;
i=P1;
j=t0;
k=t1;
l=TH1;
m=TL1;
P1=0xdb;
delay_t1(20);
P1=i;
t0=j;
t1=k;
TH1=l;
TL1=m;
}
void int_1() interrupt 2
{
unsigned char i,j,k,l,m;
EA=0;
i=P1;
j=t0;
k=t1;
l=TH1;
m=TL1;
EA=1;
P1=0xf3;
delay_t1(10);
EA=0;
P1=i;
t0=j;
t1=k;
TH1=l;
TL1=m;
EA=1;
}
void main()
{
unsigned char k;
TMOD=0x10;
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
while(1){
P1=0xf3;
delay_t1(10);
for(k=0;k<3;k++){
P1=0xf3;
delay0_5s1();
P1=0xfb;
delay0_5s1();
}
P1=0xeb;
delay_t1(4);
P1=0xde;
delay_t1(20);
for(k=0;k<3;k++)
{
P1=0xde;
delay0_5s1();
P1=0xdf;
delay0_5s1();
}恩这样
P1=0xdd;
delay_t1(4);
}
}