#include<reg51.h>
sbit led_red = P1 ^ 0;
sbit led_yellow = P1 ^ 1;
sbit led_green = P1 ^ 2;
sbit led_red1 = P1 ^ 3;
sbit led_yellow1 = P1 ^ 4;
sbit led_green1 = P1 ^ 5;
unsigned int i = 0;
unsigned int j = 0;
unsigned char code LedChar[] ={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90 }; //0 1 2 3 4 5 6 7 8 9
static unsigned int sec = 5;
static unsigned char togle_flag = 0;
static unsigned char rg_flag = 0;
static unsigned char skip_yellow = 0;
static unsigned char fs = 0;
void timer0(){
TMOD = 0x01;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void tcount() interrupt 1 {
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
i++;
}
void display(){
//P0 = 0x01;
P0 = 0x05;
P2 = LedChar[sec % 10]; //
P3 = LedChar[(sec + 5) % 10];
// enhance the refresh rate
P0 = 0x00;
P2 = 0xFF;
P3 = 0xFF;
//P0 = 0x02;
P0 = 0x10;
P2 = LedChar[sec / 10]; //
P3 = LedChar[(sec + 5) / 10];
// enhance the refresh rate
P0 = 0x00;
P2 = 0xFF;
P3 = 0xFF;
}
void first() {
while(!togle_flag){
display();
if(i == 20) { //
if (!rg_flag) {
led_green = 0;
led_green1 = !led_green;
} else {
led_red = 0;
led_red1 = !led_red;
}
i = 0;
if (sec > 0) sec--;
else {
if (rg_flag) {
togle_flag = 0;
sec = 5;
skip_yellow = 1;
} else if (!rg_flag){
togle_flag = 1;
sec = 3;
skip_yellow = 0;
}
rg_flag = !rg_flag;
led_green = 1;
led_red = 1;
}
}
}
while (togle_flag) {
if (skip_yellow) {
togle_flag = !togle_flag;
sec = 5;
} else {
display();
if(i == 20) { //
led_yellow = 0;
led_yellow1 = 0;
i = 0;
//
if (sec > 0) sec--;
else {
sec = 5;
togle_flag = !togle_flag;
led_yellow = 1;
led_yellow1 = 1;
}
}
}
}
}
void main(){
timer0();
while (1) {
first();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于proteus8的51单片机的交通灯仿真.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共17个文件
pdsbak:3个
workspace:2个
lst:2个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 2 浏览量
2024-06-25
17:40:48
上传
评论
收藏 101KB ZIP 举报
温馨提示
基于proteus8的51单片机的交通灯仿真
资源推荐
资源详情
资源评论
![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)
![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)
![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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![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)
![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)
![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)
![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)
共 17 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/780829b3ac054f9db01766e9f0c0c4aa_m0_74712453.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
热爱嵌入式的小佳同学
- 粉丝: 9068
- 资源: 2131
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的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)