|
第一次自己做无流量监控的交通灯系统设计,基于51单片机做的,自己发帖,求鼓励。
这个是老师让做的交通灯仿真系统,无流量监控
一共横向竖向两路,红绿黄灯,红灯30S 绿灯加黄灯30秒,绿灯25秒。
人行道红绿灯个8个,共16个。
采用定时器中断。
每个路口两位数码管。
程序比较傻瓜,
如果有好的想法,求指点。
单片机仿真原理图如下(proteus仿真工程文件可到本帖附件中下载):
单片机源程序如下:
- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit shen_lu1=P1^2;
- sbit shen_lu2=P1^3;
- sbit sheng_lu1=P1^4;
- sbit sheng_lu2=P1^5;
- //红绿灯口定义
- sbit sheng_red=P2^2;
- sbit shen_green=P2^3;
- sbit sheng_green=P2^0;
- sbit shen_red=P2^5;
- sbit shang_red=P1^0;
- sbit xia_red=P2^6;
- sbit zuo_red=P2^7;
- sbit you_red=P1^1;
- sbit shen_yellow=P2^4;
- sbit sheng_yellow=P2^1;
- //定义全局变量
- uchar code digcode[10] = {
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar DisplayData[8];
- uint Second,Time;
- //申明全局函数
- void DigDisplay(); //动态显示函数
- void Timer0Cofig();
- void Delay(uint z);
- void main()
- {
- P2=0X00;
- P1=0X00;
- P0=0X00;
- P3=0X00;
- Timer0Cofig();
- while(1)
- {
- if(Second>60)
- {
- Second=0;
- }
- if(Second < 25)
- {
- shen_green=0;
- sheng_red=0;
- shang_red=0;
- xia_red=0;
- shen_yellow=0;
- //升路通行
- sheng_green=1; //升路绿灯亮
- shen_red=1; //申路红灯亮 上下绿灯亮
- zuo_red=1; //左红灯亮
- you_red=1; //右红灯亮
- }
- else if (Second < 30) //黄灯等待切换时间5s
- {
- sheng_green=0;
- shen_red=1;
- sheng_yellow=1;
- zuo_red=1;
- you_red=1;
- }
- else if (Second < 55)
- {
- //申路通行
- sheng_green=0;
- shen_red=0;
- sheng_yellow=0;
- zuo_red=0;
- you_red=0;
-
- shen_green=1;
- sheng_red=1;
- shang_red=1;
- xia_red=1;
- }
- else
- {
- sheng_green=0;
- shen_red=0;
- shen_yellow=0;
- zuo_red=0;
- you_red=0;
- shen_green=0;
- sheng_red=1;
- shang_red=1;
- xia_red=1;
- shen_yellow=1;
- }
- DigDisplay();
-
- }
- }
- void Timer0Cofig()
- {
- TMOD = 0x01; //定时器0选择工作方式1
- TH0 = (65536-50000)/256; //设置初始值,定时50MS
- TL0 = (65536-50000)%256;
- EA = 1; //打开总中断
- ET0 = 1; //打开定时器0中断
- TR0 = 1; //启动定时器0
- }
- void Timer0() interrupt 1
- {
- TH0 = (65536-50000)/256; //设置初始值
- TL0 = (65536-50000)%256;
- Time++;
- if(Time == 10)
- {
- Second ++;
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
红绿灯.rar
(26.56 KB, 下载次数: 17)
|
评分
-
查看全部评分
|