標(biāo)題:
求解C51編寫單片機(jī)程序 ,十字路口交通燈
[打印本頁]
作者:
CS520
時間:
2015-12-28 12:12
標(biāo)題:
求解C51編寫單片機(jī)程序 ,十字路口交通燈
C51編寫單片機(jī)程序 ,十字路口交通燈
作者:
GYY0529
時間:
2015-12-28 12:49
有什么要求丫,說來聽聽
作者:
admin
時間:
2015-12-29 03:12
單片機(jī)十字路口交通燈:
http://www.torrancerestoration.com/bbs/dpj-19356-1.html
作者:
953164692
時間:
2016-11-20 22:07
我也在做,加我QQ953164692交流交流
作者:
zl2168
時間:
2016-11-22 11:53
2015年12月份的帖子
作者:
lsrly
時間:
2016-11-22 12:54
論壇里有呀!要先查,查不到在問
作者:
123444
時間:
2016-11-22 13:13
// /******************************************************************************* * 實驗名 : 動態(tài)顯示數(shù)碼管實驗 * 使用的IO : * 實驗效果 : 數(shù)碼管顯示76543210。 * 注意 :當(dāng)位選用P1口的時候注意可能會有一位不亮,那么調(diào)整J21 *******************************************************************************/ #include<reg51.h> //--定義使用的IO口--// #define GPIO_DIG P0 #define GPIO_PLACE P1 #define GPIO_TRAFFIC P2 sbit RED10 = P2^0; //上人行道紅燈 sbit GREEN10 = P2^1; //上人行道綠燈 sbit RED11 = P2^2; sbit YELLOW11= P2^3; sbit GREEN11 = P2^4; sbit RED00 = P3^0; //右人行道紅燈 sbit GREEN00 = P3^1; //右人行道綠燈 sbit RED01 = P2^5; sbit YELLOW01= P2^6; sbit GREEN01 = P2^7; //--定義全局變量--// unsigned char code DIG_PLACE[8] = { 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位選控制 查表的方法控制 unsigned char code DIG_CODE[17] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的顯示碼 unsigned char DisplayData[8]; //用來存放要顯示的8位數(shù)的值 unsigned char Time, Second; //用來存放定時時間 //--聲明全局函數(shù)--// void DigDisplay(); //動態(tài)顯示函數(shù) void Timer0Cofig(void); /******************************************************************************* * 函 數(shù) 名 : main * 函數(shù)功能 : 主函數(shù) * 輸 入 : 無 * 輸 出 : 無 *******************************************************************************/ void main(void) { Second = 1; Timer0Cofig(); while(1) { if(Second == 70) { Second = 1; } //--寶田路通行,30秒--// if(Second < 31) { DisplayData[0] = 0x00; DisplayData[1] = 0x00; DisplayData[2] = DIG_CODE[(30 - Second) % 100 / 10]; DisplayData[3] = DIG_CODE[(30 - Second) %10]; DisplayData[4] = 0x00; DisplayData[5] = 0x00; DisplayData[6] = DisplayData[2]; DisplayData[7] = DisplayData[3]; DigDisplay(); //--寶田路通行--// GPIO_TRAFFIC = 0xFF; //將所有的燈熄滅 RED00 = 1; GREEN00 = 1; GREEN11 = 0; //寶田路綠燈亮 GREEN10 = 0; //寶田路人行道綠燈亮 RED01 = 0; //前進(jìn)路紅燈亮 RED00 = 0; //前進(jìn)路人行道紅燈亮 } //--黃燈等待切換狀態(tài),5秒--// else if(Second < 36) { DisplayData[0] = 0x00; DisplayData[1] = 0x00; DisplayData[2] = DIG_CODE[(35 - Second) % 100 / 10]; DisplayData[3] = DIG_CODE[(35 - Second) %10]; DisplayData[4] = 0x00; DisplayData[5] = 0x00; DisplayData[6] = DisplayData[2]; DisplayData[7] = DisplayData[3]; DigDisplay(); //--黃燈階段--// GPIO_TRAFFIC = 0xFF; //將所有的燈熄滅 RED00 = 1; GREEN00 = 1; YELLOW11 = 0; //寶田路黃燈亮 RED10 = 0; //寶田路人行道紅燈亮 YELLOW01 = 0; //前進(jìn)路紅燈亮 RED00 = 0; //前進(jìn)路人行道紅燈亮 } //--前進(jìn)路通行--// else if(Second < 66) { DisplayData[0] = 0x00; DisplayData[1] = 0x00; DisplayData[2] = DIG_CODE[(65 - Second) % 100 / 10]; DisplayData[3] = DIG_CODE[(65 - Second) %10]; DisplayData[4] = 0x00; DisplayData[5] = 0x00; DisplayData[6] = DisplayData[2]; DisplayData[7] = DisplayData[3]; DigDisplay(); //--黃燈階段--// GPIO_TRAFFIC = 0xFF; //將所有的燈熄滅 RED00 = 1; GREEN00 = 1; RED11 = 0; //寶田路紅燈亮 RED10 = 0; //寶田路人行道紅燈亮 GREEN01 = 0; //前進(jìn)路綠燈亮 GREEN00 = 0; //前進(jìn)路人行道綠燈亮 } //--黃燈等待切換狀態(tài),5秒--// else { DisplayData[0] = 0x00; DisplayData[1] = 0x00; DisplayData[2] = DIG_CODE[(70 - Second) % 100 / 10]; DisplayData[3] = DIG_CODE[(70 - Second) %10]; DisplayData[4] = 0x00; DisplayData[5] = 0x00; DisplayData[6] = DisplayData[2]; DisplayData[7] = DisplayData[3]; DigDisplay(); //--黃燈階段--// GPIO_TRAFFIC = 0xFF; //將所有的燈熄滅 RED00 = 1; GREEN00 = 1; YELLOW11 = 0; //寶田路黃燈亮 RED10 = 0; //寶田路人行道紅燈亮 YELLOW01 = 0; //前進(jìn)路紅燈亮 RED00 = 0; //前進(jìn)路人行道紅燈亮 } } } /******************************************************************************* * 函 數(shù) 名 : DigDisplay * 函數(shù)功能 : 使用數(shù)碼管顯示 * 輸 入 : 無 * 輸 出 : 無 *******************************************************************************/ void DigDisplay() { unsigned char i; unsigned int j; for(i=0; i<8; i++) { GPIO_PLACE = DIG_PLACE[i]; //發(fā)送位選 GPIO_DIG = DisplayData[i]; //發(fā)送段碼 j = 10; //掃描間隔時間設(shè)定 while(j--); GPIO_DIG = 0x00; //消隱 } } /******************************************************************************* * 函 數(shù) 名 : Timer0Cofig * 函數(shù)功能 : 配置定時器 * 輸 入 : 無 * 輸 出 : 無 *******************************************************************************/ void Timer0Cofig(void) { TMOD = 0x01; //定時器0選擇工作方式1 TH0 = 0x3C; //設(shè)置初始值,定時50MS TL0 = 0xB0; EA = 1; //打開總中斷 ET0 = 1; //打開定時器0中斷 TR0 = 1; //啟動定時器0 } /******************************************************************************* * 函 數(shù) 名 : Timer0 * 函數(shù)功能 : 定時器0中斷函數(shù) * 輸 入 : 無 * 輸 出 : 無 *******************************************************************************/ void Timer0() interrupt 1 { TH0 = 0x3C; //設(shè)置初始值 TL0 = 0xB0; Time++; if(Time == 20) { Second ++; Time = 0; } }
作者:
15123777154
時間:
2017-12-5 23:00
在腹肌里面,5個黑幣
羅.zip
2017-12-5 22:59 上傳
點擊文件名下載附件
1.31 MB, 下載次數(shù): 3
十字路口編程以及仿真圖
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1