楼主的程序是:- #include<reg52.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit G1=P1^0;
- sbit Y1=P1^1;
- sbit R1=P1^2;
- sbit G2=P1^3;
- sbit Y2=P1^4;
- sbit R2=P1^5;
- sbit P3_3=P3^3;
- unsigned char Time,J=1;
- uchar Ab;
- unsigned char a,b,c,d;
- unsigned char code WEI[]={0X7F,0XBF,0XDF,0XEF}; //位码
- unsigned char code XIANSHI[]={0x40,0X79,0X24,0X30,0X19,0X12,0X02,0X78,0X00,0X18};//段码
- void delay(uchar k); //函数声明
- void Timer();
- void delay1s(void);
- void main()
- {
- Timer();
- while(1)
- {
- if(Ab==86) //计数Ab的最大值
- {
- Ab=1;
- }
- if(Ab<43)
- {
- b=(42-Ab)/10;
- a=(42-Ab)%10;
- P2=WEI[0];
- P0=XIANSHI[a];
- delay(10);
- P2=WEI[1];
- P0=XIANSHI[b];
- delay(10);
- c=(45-Ab)/10;
- d=(45-Ab)%10;
- P2=WEI[2];
- P0=XIANSHI[d];
- delay(10);
- P2=WEI[3];
- P0=XIANSHI[c];
- delay(10);
- J=Ab;
- P1=0XF3;//R1=0;G2=0;
- if(J==40)
- {P1=0XF3;delay(10);P1=0XFB;delay(10);
- P1=0XF3;delay(10);P1=0XFB;delay(10);
- }
- if(J==41)
- {P1=0XF3;delay(10);P1=0XFB;delay(10);
- P1=0XF3;delay(10);P1=0XFB;delay(10);
- }if(J==42)
- {P1=0XF3;delay(10);P1=0XFB;delay(10);
- P1=0XF3;delay(10);P1=0XFB;delay(10);
- }
- }
-
- else if(Ab<46)
- {
- b=(45-Ab)/10;
- a=(45-Ab)%10;
- P2=WEI[0];
- P0=XIANSHI[a];
- delay(10);
- P2=WEI[1];
- P0=XIANSHI[b];
- delay(10);
- c=(45-Ab)/10;
- d=(45-Ab)%10;
- P2=WEI[2];
- P0=XIANSHI[d];
- delay(10);
- P2=WEI[3];
- P0=XIANSHI[c];
- delay(10);
- P1=0XFF;
- R1=0;
- Y2=0;
- }
- else if (Ab<83)
- {
- b=(85-Ab)/10;
- a=(85-Ab)%10;
- P2=WEI[0];
- P0=XIANSHI[a];
- delay(10);
- P2=WEI[1];
- P0=XIANSHI[b];
- delay(10);
- c=(82-Ab)/10;
- d=(82-Ab)%10;
- P2=WEI[2];
- P0=XIANSHI[d];
- delay(10);
- P2=WEI[3];
- P0=XIANSHI[c];
- delay(10);
- J=Ab;
- P1=0Xde;
- if(J==80)
- {P1=0Xde;delay(10);P1=0Xdf;delay(10);
- P1=0Xde;;delay(10);P1=0Xdf;delay(10);
- } if(J==81)
- {P1=0Xde;delay(10);P1=0Xdf;delay(10);
- P1=0Xde;delay(10);P1=0Xdf;delay(10);
- } if(J==82)
- {P1=0Xde;delay(10);P1=0Xdf;delay(10);
- P1=0Xde;delay(10);P1=0Xdf;delay(10);
- }
- }
- else if(Ab<86)
- {
- b=(85-Ab)/10;
- a=(85-Ab)%10;
- P2=WEI[0];
- P0=XIANSHI[a];
- delay(10);
- P2=WEI[1];
- P0=XIANSHI[b];
- delay(10);
- c=(85-Ab)/10;
- d=(85-Ab)%10;
- P2=WEI[2];
- P0=XIANSHI[d];
- delay(10);
- P2=WEI[3];
- P0=XIANSHI[c];
- delay(10);
- P1=0XFF;
- Y1=0; //黄灯亮三秒
- R2=0;
- //Y2=0;
- }
- }
- }
- void delay(uchar k) //延迟程序
- {
- uint i,j;
- for(i=k;i>0;i--);
- for(j=110;j>0;j--);
- }
- void Timer()
- {
- TMOD = 0x01; //定时器0选择工作方式1
- TH0 = 0x3C; //设置初始值,定时50MS
- TL0 = 0xB0;
- EA = 1; //打开总中断
- ET0 = 1; //打开定时器0中断
- TR0 = 1; //启动定时器0
- }
- void Timer0() interrupt 1
- {
- TH0 = 0x3C; //设置初始值
- TL0 = 0xB0;
- Time++;
- if(Time == 20)
- {
- Time = 0;
- Ab++;
- }
- }
复制代码 |