找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1782|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)定時(shí)器控制交通指示燈代碼與Proteus仿真圖

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
喜歡的可以下載,為了便于快速測(cè)試運(yùn)行效果,本例調(diào)短了指示燈切換時(shí)間
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)



單片機(jī)源程序如下:
  1. /***************   writer:shopping.w   ******************/
  2. #include <reg52.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char

  5. sbit RED_A = P0^0;
  6. sbit YELLOW_A = P0^1;
  7. sbit GREEN_A = P0^2;
  8. sbit RED_B = P0^3;
  9. sbit YELLOW_B = P0^4;
  10. sbit GREEN_B = P0^5;

  11. uchar Time_Count = 0,Flash_Count = 0,Operation_Type = 1;

  12. void T0_INT() interrupt 1
  13. {
  14.          TH0 = -50000/256;
  15.         TL0 = -50000%256;
  16.         switch(Operation_Type)
  17.         {
  18.                  case 1:
  19.                         RED_A=0;YELLOW_A=0;GREEN_A=1;
  20.                         RED_B=1;YELLOW_B=0;GREEN_B=0;
  21.                         if(++Time_Count != 100) return;
  22.                         Time_Count=0;
  23.                         Operation_Type = 2;
  24.                         break;
  25.                 case 2:
  26.                         if(++Time_Count != 8) return;
  27.                         Time_Count=0;
  28.                         YELLOW_A=!YELLOW_A;
  29.                         GREEN_A=0;
  30.                         if(++Flash_Count != 10) return;
  31.                         Flash_Count=0;
  32.                         Operation_Type = 3;
  33.                         break;
  34.                 case 3:
  35.                         RED_A=1;YELLOW_A=0;GREEN_A=0;
  36.                         RED_B=0;YELLOW_B=0;GREEN_B=1;
  37.                         if(++Time_Count != 100) return;
  38.                         Time_Count=0;
  39.                         Operation_Type = 4;
  40.                         break;        
  41.                 case 4:
  42.                         if(++Time_Count != 8) return;
  43.                         Time_Count=0;
  44.                         YELLOW_B=!YELLOW_B;
  45.                         GREEN_B=0;
  46.                         if(++Flash_Count !=10)
  47.                                 return;
  48.                         Flash_Count=0;
  49.                         Operation_Type = 1;
  50.                         break;        
  51.         }
  52. }

  53. void main()
  54. {
  55.          TMOD = 0x01;
  56.         IE = 0x82;
  57.         TR0 = 1;
  58.         while(1);
  59. }
復(fù)制代碼

51hei附件下載:
Keil2代碼與Proteus7.5仿真下載(注意版本一定要是Keil2和Proteus7.5):
41 定時(shí)器控制交通指示燈.zip (26.45 KB, 下載次數(shù): 14)

評(píng)分

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

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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