附录二 原程序 #include
#define uchar unsigned char #define uint unsigned int
uchar code table[]={
uchar code table1[]={
uchar num=0,num1,shi,ge;
void delay(uint z) {
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};
0xfe,0xfd,0xfb,0xf7, 0xef,0xdf,0xbf,0x7f};
uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--);
第16页 共20页
}
void main() {
while(1) {
TMOD=0x01;
TH0=(65536-50000)/256; TL0=(65536-50000)%6; EA=1; ET0=1; TR0=1;
num=45;//主干道绿灯亮支道红灯亮45秒 while(num!=0) {
P2=0X7b;
P1=0xfb; P0=table[ge];
delay(5);
P1=0xf7; P0=table[shi]; delay(5);
第17页 共20页
} TR0=1;
num=5;//主干道支道黄灯亮5秒
while(num!=0)
{
P2=0Xbd;
P1=0xfb; P0=table[ge];
delay(5);
TR0=1;
num=25;//主干道红灯亮支道绿灯亮25秒 while(num!=0) { P1=0xf7; //
P0=table[shi];
P0=0x3f; delay(5); }
P2=0Xde;
第18页 共20页
P1=0xfb; P0=table[ge];
delay(5); }
void T0_time() interrupt 1 {
TH0=(65536-50000)/256; TL0=(65536-50000)%6; num1++; if(num1==20) { num1=0; num=num-1; if(num==0) P1=0xf7; P0=table[shi]; delay(5); } }
{ TR0=0;
第19页 共20页
}
shi=num/10; ge=num;
} }
第20页 共20页