這是帶左右轉(zhuǎn)向的交通燈,采用每一個方向9個二極管燈的設計。這是根據(jù)設計任務做的。代碼 仿真都是自己做的。 設計內(nèi)容:1、東西干道和南北干道的通行分左行、右行、直行,其中左行、右行固定15秒;直行固定30 2、信號燈分綠燈(3種)、紅燈、黃燈,每次綠燈換紅燈時,黃燈亮3秒鐘 3 、東西干道和南北干道交替控制,每次干道綠燈交替時,有3秒鐘所有干道的交通燈都是黃燈閃爍3秒鐘,提示已經(jīng)進入路口的車輛迅速通過
0.png (32.74 KB, 下載次數(shù): 104)
下載附件
2016-6-27 14:06 上傳
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit wei1=P3^0;
- sbit wei2=P3^1;
- sbit num1=P3^7;
- sbit e2=P3^4;
- sbit f2=P3^5;
- uchar num,num2,num3,flag;
- uchar code table[]=
- {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- void delayms(uint x)
- {
- uint i,j;
- for(i=x;i>0;i--)
- for(j=110;j>0;j--);
- }
- void lamp()
- { if(num1==0)
- {
- if(num3<=13)
- {
- P0=0x81;
- P2=0x0f;
- }
- if((num3>13)&&(num3<=15))
- {
- P0=0x80;
- P2=0x0f;
- delayms(400);
- P2=0x1f;
- delayms(400);
- }
- if((num3>15)&&(num3<=27))
- {
- P0=0x46;
- P2=0x0e;
- }
- if((num3>27)&&(num3<=30))
- {
- P0=0X42;
- P2=0X4e;
- delayms(400);
- P2=0X0e;
- delayms(400);
- }
- if((num3>30)&&(num3<=42))
- {
- P0=0x42;
- P2=0x0f;
- }
- if(num3>42)
- {
- P0=0x00;
- P2=0xf0;
- e2=1;
- f2=1;
- delayms(400);
- P2=0x00;
- e2=0;
- f2=0;
- delayms(400);
- }
- }
- else
- {
- if(num3<=13)
- {
- P0=0xc8;
- P2=0x0d;
- }
- if((num3>13)&&(num3<=15))
- {
- P0=0xc0;
- P2=0x8d;
- delayms(400);
- P2=0x0d;
- delayms(400);
- }
- if((num3>15)&&(num3<=27))
- {
- P0=0xf0;
- P2=0x03;
- }
- if((num3>27)&&(num3<=30))
- {
- P0=0Xd0;
- P2=0X03;
- f2=1;
- delayms(400);
- f2=0;
- delayms(400);
- }
- if((num3>30)&&(num3<=42))
- {
- P0=0xd0;
- P2=0x0b;
- }
- if(num3>42)
- {
- P0=0x00;
- P2=0xf0;
- e2=1;
- f2=1;
- delayms(400);
- P2=0x00;
- e2=0;
- f2=0;
- delayms(400);
- }
- }
- }
- void xs()
- {
- P1=table[num/10];
- wei1=1;
- delayms(10);
- wei1=0;
- P1=table[num%10];
- wei2=1;
- delayms(10);
- wei2=0;
-
- }
- void main()
- {
- P0=0x00;
- num1=0;num3=0;
- P1=P2=P3=0x00;
- TMOD=0x01;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- lamp();
- xs();
- }
- }
- void T0_time() interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- num2++;
- if(num2==20)
- { num2=0;
- num3++;
- if(num3==45)
- {
- num3=0;
- num1=~num1;
- }
- num=45-num3;
- }
- }
復制代碼
這是用proteus的仿真圖
三刀.rar
(53.7 KB, 下載次數(shù): 25)
2016-6-27 09:30 上傳
點擊文件名下載附件
仿真圖 下載積分: 黑幣 -5
這是用kellc編寫的程序
程序.rar
(12.85 KB, 下載次數(shù): 25)
2016-6-27 09:30 上傳
點擊文件名下載附件
C程序 下載積分: 黑幣 -5
。初次發(fā)帖請各位大神關(guān)照。
|