#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
共17个文件
pdsbak:3个
workspace:2个
lst:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 62 浏览量
2024-05-03
17:56:49
上传
评论
收藏 102KB ZIP 举报
温馨提示
基于proteus8的51单片机的交通灯仿真源码.zip 基于proteus8的51单片机的交通灯仿真源码.zip 基于proteus8的51单片机的交通灯仿真源码.zip 基于proteus8的51单片机的交通灯仿真源码.zip 基于proteus8的51单片机的交通灯仿真源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于proteus8的51单片机的交通灯仿真源码.zip (17个子文件)
code
simulation
trafic_led.pdsprj 20KB
Last Loaded trafic_led.pdsbak 20KB
trafic_led.pdsprj.贺欧巴.11566.workspace 2KB
trafic_led
trafic_led.c 2KB
Objects
trafic_led.build_log.htm 1022B
trafic_led.hex 2KB
trafic_led.lnp 92B
trafic_led 7KB
traffic_led.obj 8KB
trafic_led.uvopt 5KB
Listings
traffic_led.lst 7KB
trafic_led.lst 5KB
trafic_led.m51 10KB
trafic_led.uvgui.11566 89KB
trafic_led_pic
Last Loaded trafic_led.pdsbak 18KB
trafic_led.pdsprj.贺欧巴.11566.workspace 2KB
Backup Of trafic_led.pdsbak 20KB
共 17 条
- 1
资源评论
FL1768317420
- 粉丝: 3855
- 资源: 4571
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功