找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 3034|回復(fù): 5
收起左側(cè)

51單片機(jī)交通信號燈Proteus仿真程序 深夜模式 時(shí)間調(diào)整開關(guān)

[復(fù)制鏈接]
ID:1100805 發(fā)表于 2023-12-12 14:02 | 顯示全部樓層 |閱讀模式
基于AT89C52單片機(jī)的交通燈主要具有如下功能。
基本要求如下:
1. 按鍵1為交通燈“深夜模式”開/關(guān),按下后進(jìn)入深夜模式,4個(gè)方向LED(黃)閃爍;再次按下后則退出深夜模式,交通燈正常運(yùn)行。
2. 按鍵2為“時(shí)間調(diào)整”開/關(guān),上電后,交通燈正常運(yùn)行,按下此按鍵后,進(jìn)入調(diào)時(shí)模式,此時(shí)按鍵3和4均有效。
3. 按鍵3為通行“時(shí)間加”,按鍵4為通行“時(shí)間減”。
4. 設(shè)定好通行時(shí)間后,按鍵2再次按下,退出調(diào)時(shí)模式。
5. 交通燈設(shè)置好正常運(yùn)行時(shí),按鍵3和按鍵4均無效。

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.gif

單片機(jī)源程序如下:
  1. #include<reg52.h>
  2. typedef unsigned char uint8;
  3. typedef unsigned int uint16;
  4. sbit renrh=P3^0;          //人行道右紅
  5. sbit renrl=P3^1;// 人行道右綠
  6. sbit rensh=P2^0;  //人上下紅燈
  7. sbit rensl=P2^1; //人上下綠燈
  8. sbit cherh=P2^5; //車左右紅燈
  9. sbit chery=P2^6; //車左右黃燈
  10. sbit cherl=P2^7; //車左右綠燈
  11. sbit chesh=P2^2; //車上下紅燈
  12. sbit chesy=P2^3;//車上下黃燈
  13. sbit chesl=P2^4;//車上下綠燈
  14. uint8 smgduan[16]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,
  15.                              0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
  16. uint8 smgwei[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  17. uint8 sec,sum;
  18. uint8 smgshu[8];
  19. void delay(uint8 i)
  20. {
  21.         uint8 j,k;
  22.         for(;i>0;i--)        
  23.                 for(j=10;j>0;j--)         
  24.                         for(k=130;k>0;k--);
  25. }
  26. void init0()
  27. {
  28.         TMOD=0x01;
  29.         TH1=0x3c;
  30.         TL1=0xb0;  //定時(shí)50ms
  31.         TR0=1;
  32.         ET0=1;
  33.         EA=1;
  34. }
  35. void smgsaomiao()
  36. {
  37.         uint8 i;
  38.         for(i=0;i<8;i++)
  39.         {
  40.                 P0=smgshu[i];
  41.                 delay(1);
  42.                 P1=smgwei[i];
  43.                 //delay(1);
  44.         }
  45. }
  46. void main()
  47. {        
  48.         init0();
  49.         sec=1;
  50.         while(1)
  51.         {
  52.                 if(sec==70)        
  53.                 {
  54.                         sec=1;
  55.                 }
  56.                 if(sec<31)
  57.                 {
  58.                         P2=0xff;
  59.                         P3=0xff;
  60.                         renrh=0;
  61.                         chesl=0;
  62.                         cherh=0;
  63.                         rensl=0;
  64.                         smgshu[0]=0x00;
  65.                         smgshu[1]=0x00;
  66.                         smgshu[2]=smgduan[(30-sec)/10];
  67.                         smgshu[3]=smgduan[(30-sec)%10];
  68.                         smgshu[4]=0x00;
  69.                         smgshu[5]=0x00;
  70.                         smgshu[6]=smgduan[(30-sec)/10];
  71.                         smgshu[7]=smgduan[(30-sec)%10];
  72.                         smgsaomiao();               
  73.                 }
  74.                 if(sec>30&&sec<36)
  75.                 {
  76.                         P3=0xff;
  77.                         P2=0xff;
  78.                         renrh=0;
  79.                         chesy=0;
  80.                         chery=0;
  81.                         rensh=0;
  82.                         smgshu[0]=0x00;
  83.                         smgshu[1]=0x00;
  84.                         smgshu[2]=smgduan[(36-sec)/10];
  85.                         smgshu[3]=smgduan[(36-sec)%10];
  86.                         smgshu[4]=0x00;
  87.                         smgshu[5]=0x00;
  88.                         smgshu[6]=smgduan[(36-sec)/10];
  89.                         smgshu[7]=smgduan[(36-sec)%10];
  90.                         smgsaomiao();        
  91.                 }
  92.                 if(sec>35&&sec<66)
  93.                 {
  94.                         P3=0xff;
  95.                         P2=0xff;
  96.                         renrl=0;
  97.                         chesh=0;
  98.                         cherl=0;
  99.                         rensh=0;
  100.                         smgshu[0]=0x00;
  101.                         smgshu[1]=0x00;
  102.                         smgshu[2]=smgduan[(65-sec)/10];
  103.                         smgshu[3]=smgduan[(65-sec)%10];
  104.                         smgshu[4]=0x00;
  105.                         smgshu[5]=0x00;
  106.                         smgshu[6]=smgduan[(65-sec)/10];
  107.                         smgshu[7]=smgduan[(65-sec)%10];
  108.                         smgsaomiao();        
  109.                 }
  110.                 if(sec>65&&sec<71)
  111.                 {
  112.                         P3=0xff;
  113.                         P2=0xff;
  114.                         renrh=0;
  115.                         chesy=0;
  116.                         chery=0;
  117.                         rensh=0;
  118.                         smgshu[0]=0x00;
  119.                         smgshu[1]=0x00;
  120.                         smgshu[2]=smgduan[(70-sec)/10];
  121.                         smgshu[3]=smgduan[(70-sec)%10];
  122.                         smgshu[4]=0x00;
  123.                         smgshu[5]=0x00;
  124.                         smgshu[6]=smgduan[(70-sec)/10];
  125.                         smgshu[7]=smgduan[(70-sec)%10];
  126.                         smgsaomiao();        
  127.                 }
  128.         }               
  129. }
  130. void time0() interrupt 1
  131. {
  132.         TH1=0x3c;
  133.         TL1=0xb0;
  134.         sum++;
  135.         if(sum==20)        
  136.         {
  137.                 sum=0;
  138.                 sec++;
  139.         }
  140. }
復(fù)制代碼

仿真程序: 交通燈仿真實(shí)驗(yàn).zip (78.25 KB, 下載次數(shù): 30)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評分

回復(fù)

使用道具 舉報(bào)

ID:262 發(fā)表于 2023-12-18 01:31 | 顯示全部樓層
好資料,51黑有你更精彩!!!
回復(fù)

使用道具 舉報(bào)

ID:1122658 發(fā)表于 2024-5-28 11:37 | 顯示全部樓層

好資料,51黑有你更精彩!!!
回復(fù)

使用道具 舉報(bào)

ID:961114 發(fā)表于 2024-5-28 16:27 | 顯示全部樓層
軟件仿真 淘汰 好不好   8H8K64U  自帶硬件USB,可以USB仿真 USB下載 多方便
回復(fù)

使用道具 舉報(bào)

ID:1140438 發(fā)表于 2024-12-19 11:14 | 顯示全部樓層
好資料,51黑有你更精彩!!!
回復(fù)

使用道具 舉報(bào)

ID:1140438 發(fā)表于 2024-12-19 11:15 | 顯示全部樓層
可以問一下仿真版本多少嗎
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表