|
以前做的十字路口交通灯的实验,可以实现东西方向绿灯时,南北方向红灯,数秒后,绿灯闪烁,然后黄灯亮,黄灯之后红灯亮禁止通行。
部分截图展示,第一次发很多不足,多多见谅。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
- #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=TH0;
- EA=1;P1=0xf3;
- delay_t1(10);
- EA=0;P1=i;t0=j;t1=k;TH1=l;TH0=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(10);
- for(k=0;k<3;k++)
- {P1=0xde;
- delay0_5s1();
- P1=0xdf;
- delay0_5s1();
- }
- P1=0xdd;
- delay_t1(4);
- }
- }
复制代码
|
评分
-
查看全部评分
|