#include "REGX52.H"
#include "smg.h"
#include "delay.h"
#include "Timer0.h"
int Time_SMG=0,Timer0Count=0,blink=0,Timer0Count2=0;
int flag=1;
// 定义IO口连接
sbit RedEastWest = P1^0; // 东西向红灯
sbit YellowEastWest = P1^1; // 东西向黄灯
sbit GreenEastWest = P1^2; // 东西向绿灯
sbit RedNorthSouth = P1^3; // 南北向红灯
sbit YellowNorthSouth = P1^4; // 南北向黄灯
sbit GreenNorthSouth = P1^5; // 南北向绿灯
// 主函数
void main() {
Timer0Init();
P3_7=0;
while (1) {
//过程:东西红灯33秒,南北绿灯27秒,绿灯以占空比50闪烁3秒,黄灯三秒;
if (flag==0){
RedEastWest=0;
GreenEastWest=1;
YellowEastWest=1;
if(Time_SMG<27){
GreenNorthSouth=0;
RedNorthSouth=1;
YellowNorthSouth=1;
}
else if(Time_SMG>=27&&Time_SMG<=30){
blink=1;//绿灯闪烁
}
else if (Time_SMG>30)
{
blink=0;
GreenNorthSouth=1;
YellowNorthSouth=0;
RedNorthSouth=1;
}
}
else if (flag==1){
RedNorthSouth=0;
GreenNorthSouth=1;
YellowNorthSouth=1;
if(Time_SMG<27){
GreenEastWest=0;
YellowEastWest=1;
RedEastWest=1;
}
else if(Time_SMG>=27&&Time_SMG<=30){
blink=1;//绿灯闪烁
}
else if (Time_SMG>30)
{
blink=0;
GreenEastWest=1;
YellowEastWest=0;
RedEastWest=1;
}
}
smg(1,Time_SMG%10);
smg(2,Time_SMG/10);
}
}
//主函数中断示例
void Timer0Routine() interrupt 1 //中断
{
TL0 = 0x66; //设置定时初值
TH0 = 0xFC; //设置定时初值【注意:这里的定时初值要与函数Timer0Init内的初值一样】10ms
Timer0Count++; //每1ms打断一次,计数器加1
Timer0Count2++;
if(Timer0Count>=1000) //当计数器到1000,即经过1秒
{
Time_SMG++;
Timer0Count=0;
}
if(Time_SMG>33){
Time_SMG=0;
flag=!flag;
}
if(Timer0Count2>=500) //当计数器到100,即经过0.1秒
{
Timer0Count2=0;
if(blink==1)
{
if(flag==0)
{
GreenNorthSouth=!GreenNorthSouth;
}
else if (flag==1)
{
GreenEastWest=!GreenEastWest;
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
51单片机路口红黄绿交通灯设计(附源码)
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共8个文件
c:4个
h:3个
hex:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
3 下载量 144 浏览量
2024-05-23
00:23:13
上传
评论
收藏 4KB ZIP 举报
温馨提示
51单片机路口红黄绿交通灯设计(附源码)
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 8 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/31d266113eee45c7b2139ec5d49a76fa_qq_33534211.jpg!1)
CollinLee
- 粉丝: 3842
- 资源: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)