1、#include#include #define uchar unsigned char#define uint unsigned intbit Flag_SN_Yellow; /SN 黄灯标志位bit Flag_EW_Yellow;/EW 黄灯标志位uchar Time_EW;/东西方向倒计时单元uchar Time_SN;/南北方向倒计时单元uchar EW=15,SN=10,EWL=19,SNL=19; /程序初始化赋值,正常模式uchar EW1=60,SN1=40,EWL1=19,SNL1=19;/用于存放修改值的变量 uchar Flag_Moden=1; /模式变量 1 正常模式
2、 2 禁止南北通东西 3 禁止东西通南北 4 禁止东西南北 5 夜间模式uchar Flag_key=0;uchar code table10=0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F;/19 段选码sbit HC164_Data =P00;sbit HC164_Clk =P01;sbit EW_green =P02;sbit EW_yellow =P03;sbit EW_red =P04;sbit SN_red =P05;sbit SN_green =P07;sbit SN_yellow =P06;sbit SN_RXD_red =P
3、27;sbit SN_RXD_green =P26;sbit EW_RXD_red =P25;sbit EW_RXD_green =P24;sbit FMQ = P10;sbit key1 = P33;sbit key2 = P34;sbit key3 = P35;sbit WEI1 =P23; / 东西数码管第一位sbit WEI2 =P22; / 东西数码管第二位sbit WEI3 =P21; / 南北数码管第一位sbit WEI4 =P20; / 南北数码管第二位/uchar ew=40;sn=35;/函数 delay(uchar z)/功能能 延时void Delay(uchar z)
4、uchar a,b;for(a=z;a0;a-)for(b=200;b0;b-); void HC_164_Set_byte(uchar duan)uchar i;for(i=0;i5)if(key1=0 | key2=0|key3=0)/Flag_Moden=1;TR0=0;/启动定时break;Display(); SN_yellow=0; /SN 黄灯亮开始闪烁 5 秒SN_green =1; /灭 /*S1 状态*Time_SN=5;while(Time_EW5)if(key1=0 | key2=0|key3=0)/Flag_Moden=1;TR0=0;/启动定时break;Displ
5、ay(); /*S3 状态*EW_green=1;EW_yellow=0;Time_EW=5;while(Time_SN=5)if(key1=0 | key2=0|key3=0)TR0=0;/启动定时break;Flag_EW_Yellow=1; /SN 开黄灯信号位 Display();Flag_EW_Yellow=0;EW_yellow=1; /模式 2 禁止南北 通东西 蜂鸣器响void Jsn()EW_green =0;EW_yellow =1;EW_red =1;SN_red =0;SN_green =1;SN_yellow =1;SN_RXD_red =0;SN_RXD_green
6、 =1;EW_RXD_red =1;EW_RXD_green =0;FMQ = FMQ;Delay(10);WEI1=1;WEI2=1;WEI3=1;WEI4=1;/模式 3 禁止东西 通南北 蜂鸣器响void Jew()EW_green =1;EW_yellow =1;EW_red =0;SN_red =1;SN_green =0;SN_yellow =1;SN_RXD_red =1;SN_RXD_green =0;EW_RXD_red =0;EW_RXD_green =1;FMQ = FMQ;Delay(10);WEI1=1;WEI2=1;WEI3=1;WEI4=1;/模式 4 禁止东西南
7、北 蜂鸣器响void JEwSn()EW_green =1;EW_yellow =1;EW_red =0;SN_red =0;SN_green =1;SN_yellow =1;SN_RXD_red =0;SN_RXD_green =1;EW_RXD_red =0;EW_RXD_green =1;FMQ = FMQ;Delay(10);WEI1=1;WEI2=1;WEI3=1;WEI4=1;/模式 5 夜间模式 ,东西南北黄灯闪烁void Yejian()EW_green =1;/EW_yellow =1;EW_red =1;SN_red =1;SN_green =1;/SN_yellow =1
8、;SN_RXD_red =1;SN_RXD_green =1;EW_RXD_red =1;EW_RXD_green =1;Flag_EW_Yellow=1; /SN 开黄灯信号位Flag_SN_Yellow=1; /SN 开黄灯信号位void main ()P1=0xff;P2=0xff ;P3=0xff;P0=0xff;EW_green =1;EW_yellow =1;EW_red =1;SN_red =1;SN_green =1;SN_yellow =1;SN_RXD_red =1;SN_RXD_green =1;EW_RXD_red =1;EW_RXD_green =1;WEI1=1;W
9、EI2=1;WEI3=1;WEI4=1;IT0=1; /INT0 负跳变触发 TMOD=0x01;/定时器工作于方式 1TH0=(65536-50000)/256;/定时器赋初值TL0=(65536-50000)%6;EA=1; /CPU 开中断总允许ET0=1;/开定时中断/ EX0=1;/开外部 INTO 中断TR0=1;/启动定时while(1)switch(Flag_Moden) case 1:Zc_moshi(); break;case 2:Jsn(); break;case 3: Jew();break;case 4: JEwSn();break;case 5: Yejian();break;default :break;Key();