|
智能交通燈的proteus仿真圖分享給大伙
1.倒計(jì)時(shí)到10秒后,黃燈警告,準(zhǔn)備交換亮紅燈。
2..數(shù)碼管32和28秒倒計(jì)時(shí)功能.
3.增加鍵盤手動(dòng)調(diào)節(jié)功能
A:設(shè)置鍵:按一次后,數(shù)碼管停止倒計(jì)數(shù)。按三次設(shè)置鍵恢復(fù)正常。
B:向上鍵:每按一次實(shí)現(xiàn)加一秒,沒有限制秒。
C:向下鍵:每接一次向下鍵,實(shí)現(xiàn)數(shù)碼管減一,減到0時(shí)恢復(fù)到32秒。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png (48.03 KB, 下載次數(shù): 120)
下載附件
2017-6-20 00:07 上傳
0.png (41.3 KB, 下載次數(shù): 114)
下載附件
2017-6-20 00:05 上傳
0.png (52.81 KB, 下載次數(shù): 115)
下載附件
2017-6-20 00:04 上傳
單片機(jī)源程序如下:
- #include <reg51.h>
- #include <stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key1=P3^2;
- sbit key2=P3^3;
- sbit key3=P3^4;
- sbit key4=P3^5;
- uchar h,count,num,dat,flag,dat1,num1,key1num,temp;
- uint r=0;
- uint s;
- uchar code dis[]={
-
- 0Xc0,/*0*/
- 0Xf9,/*1*/
- 0Xa4,/*2*/
- 0Xb0,/*3*/
- 0X99,/*4*/
- 0X92,/*5*/
- 0X82,/*6*/
- 0Xf8,/*7*/
- 0X80,/*8*/
- 0X90,/*9*/
- 0Xff,/*NULL*/
- };
- void delay(uint c)
- {
- uint i,j;
- for(i=0;i<c;i++)
- for(j=0;j<100;j++);
-
- }
- void init()
- {
- TMOD=0x11;//設(shè)置定時(shí)器0為工作方式1
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- TH1=(65536-20000)/256;
- TL1=(65536-20000)%256;
- EA=1;//開總中斷
- ET0=1;//開定時(shí)器0中斷
- ET1=1;
- TR0=1;//啟動(dòng)定時(shí)器0
- TR1=1;
- num=66;
- // P0=0xeb;
- }
- void display(dat) //送顯示
- {
-
- if(dat<=33)
- {
- if(dat>3&&dat<33)
- {
- P0=0xdd;//紅燈
- P1=0x00;
- P2=0xff;
- P1=0x01;
- P2=dis[dat/10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x02;
- P2=dis[dat%10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x04;
- P2=dis[(dat-3)/10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x08;
- P2=dis[(dat-3)%10];
- delay(1);
- }
- if(dat<=3)
- {
- P0=0xd4;//黃燈
- P1=0x00;
- P2=0xff;
- P1=0x02;
- P2=dis[dat%10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x08;
- P2=dis[(dat-3)%10];
- delay(1);
-
-
- }
- // break;
- }
- if(dat>=33&&dat<=66)
- {
- if(dat>36&&dat<=66)
- {
- P0=0xeb;
- P1=0x00;
- P2=0xff;
- P1=0x01;
- P2=dis[(dat-33)/10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x02;
- P2=dis[(dat-33)%10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x04;
- P2=dis[(dat-36)/10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x08;
- P2=dis[(dat-36)%10];
- delay(1);
- }
- if(dat>=33&&dat<=36)
- {
- P0=0xe2;//黃燈
- P1=0x00;
- P2=0xff;
- P1=0x02;
- P2=dis[(dat-33)%10];
- delay(1);
- P1=0x00;
- P2=0xff;
- P1=0x08;
- P2=dis[(dat-33)%10];
- delay(1);
- }
- // break;
- }
-
- }
- void keyscan() //鍵盤檢測(cè)
- {
- if(key1==0)
- {
- delay(5);
- if(key1==0)
- {
- key1num++;
- while(!key1)
- {
- display(num);
- }
- if(key1num==1)
- {
- TR0=0;
- TR1=0;
- }
- if(key1num==2)
- {
- TR0=1;
- TR1=1;
- P1=temp;
- key1num=0;
- }
- }
-
- }
- if(key1num!=0)
- {
- if(key2==0)
- {
- delay(5);
- if(key2==0)
- {
- while(!key2)
- {
- display(num);
- }
- if(key1num==1)
- {
- num++;
- display(num);
-
- }
- if(key1num==2)
- {
- num++;
- display(num);
- }
- }
- }
- if(key3==0)
- {
- delay(5);
- if(key3==0)
- {
- while(!key3)
- {
- display(num);
- }
-
- if(key1num==1)
- {
- if(num==0)
- num=32;
- num--;
- }
- if(key1num==2)
- {
- if(num1==0)
- num1=56;
- num1--;
- }
-
- }
- }
- }
- }
- void main() //主函數(shù)
- {
- init();
- while(1)
- {
- keyscan();
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
c40b0a76b361af601ed40d66db712331.rar
(144.53 KB, 下載次數(shù): 38)
2017-6-19 12:11 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|