五岔路口的交通燈設計
1、道路包含2條主干道和1條支干道
2、設計合理的交通燈規(guī)則,控制道路通行
3、數(shù)碼管顯示倒計時時間
4、通行時間固定,可在程序內修改
#include<reg51.h>
#include "74hc595.h"
#define uchar unsigned char
#define uint unsigned int
sbit smg1=P2^0;//數(shù)碼管引腳
sbit smg2=P2^1;
sbit smg3=P2^2;
sbit smg4=P2^3;
sbit smg5=P2^4;
sbit smg6=P2^5;
sbit smg7=P2^6;
sbit smg8=P2^7;
sbit smg9=P3^0;
sbit smg10=P3^1;
sbit smg11=P3^2;
sbit smg12=P3^3;
uchar num1=0xff,num2=0xff,num3=0xff;//LED控制
//數(shù)碼管編碼
uchar code tabel[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar sec=0; //定時
uchar miao1=0,miao2=0,miao3=0,miao4=0,miao5=0,miao6=0;//時間
uchar mode=0; //路燈工作順序
uchar zhi1=25,zuo1=10,zhi2=20,zuo2=10,zhi3=15;//時間設置
void set_led()//設置路燈
{
Hc595SendByte(num1);
Hc595SendByte(num2);
Hc595SendByte(num3);
RCLK = 0;
_nop_();
_nop_();
RCLK = 1;
}
//1路口
void run1_1()
{
num3 |=0x01;
}
void run1_0()
{
num3 &=0xfe;
}
void left1_1()
{
num3 |=0x02;
}
void left1_0()
{
num3 &=0xfd;
}
void yellow1_1()
{
num3 |=0x04;
}
void yellow1_0()
{
num3 &=0xfb;
}
void red1_1()
{
num3 |=0x08;
}
void red1_0()
{
num3 &=0xf7;
}
//2路口
void run2_1()
{
num3 |=0x10;
}
void run2_0()
{
num3 &=0xef;
}
void left2_1()
{
num3 |=0x20;
}
void left2_0()
{
num3 &=0xdf;
}
void yellow2_1()
{
num3 |=0x40;
}
void yellow2_0()
{
num3 &=0xbf;
}
void red2_1()
{
num3 |=0x80;
}
void red2_0()
{
num3 &=0x7f;
}
//3路口
void left3_1()
{
num2 |=0x01;
}
void left3_0()
{
num2 &=0xfe;
}
void run3_1()
{
num2 |=0x02;
}
void run3_0()
{
num2 &=0xfd;
}
void right3_1()
{
num2 |=0x04;
}
void right3_0()
{
num2 &=0xfb;
}
void yellow3_1()
{
num2 |=0x08;
}
void yellow3_0()
{
num2 &=0xf7;
}
void red3_1()
{
num2 |=0x10;
}
void red3_0()
閱讀全文