求89C51单片机C语言用四个74hc595控制四个LED实现交通灯程序

来源:百度知道 编辑:UC知道 时间:2024/07/08 13:55:19
设计要求

1.设计十字路口的交通灯,每个路口用三个LED表示左转、直行、右转三个方向,每个方向用红、绿、黄三种颜色表示,自行设计控制逻辑

2.用键盘输入交通状态模拟道路情况

3.(扩展):为每个路口的红灯加两位数码管显示等待时间

我分不多哦 不好意思 各位大侠帮帮忙呀~~~

#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int

uint t1oc=20; //20*50000us=1s
uint count;

uchar tp[8];
uchar t1,t2,t3,t4;
uchar d1,d2,d3,d4;

//数码管显示代码
unsigned char code tab[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x40,0x80};
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//0 1 2 3 4 5 6 7 8 9 A B C D E F - .

unsigned char code tab_p[]={
0xbf,0x86,0xdb,0xcf,
0xe6,0xed,0xfd,0x87,
0xff,0xef,0xf7,0xfc,
0xb9,0xde,0xf9,0xf1};//带小数点的16个数码

unsigned char code tab_w[]={
0x7F,0xBF,0xDF,0xEF,0xF7,0xfb,0xfd,0xfe};//位选择代码 从右到左

void delay1ms(unsigned int count) //延时1ms
{
unsigned char j;
for(;count>0;count--)
for(j=0;j<120;j++);
}

void led_ex(unsigned char dat,unsigned char N)
{
P0=dat;