给你改了,对比一下就知道哪里错了。
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- sbit RED_A=P0^0;
- sbit YELLOW_A=P0^1;
- sbit GREEN_A=P0^2;
- sbit RED_B=P0^3;
- sbit YELLOW_B=P0^4;
- sbit GREEN_B=P0^5;
- uchar Flash_Count=0;
- uchar num=0;
- uchar Operation_Type=1;
- void DelayMS(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void Traffic_light()
- {
- switch(Operation_Type)
- {
- case 1:
- RED_A=1;YELLOW_A=1;GREEN_A=0;
- RED_B=0;YELLOW_B=1;GREEN_B=1;
- Operation_Type=2;
- for(num=9;num>2;--num)
- {
- P1=tab[num];
- DelayMS(1000);
- }
- break;
- case 2:
- for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
- {
- P1=tab[num];
- DelayMS(200);
- YELLOW_A=~YELLOW_A;
- if(Flash_Count%5==0)num--;
- }
- Operation_Type=3;
- break;
- case 3:
- RED_A=0;YELLOW_A=1;GREEN_A=1;
- RED_B=1;YELLOW_B=1;GREEN_B=0;
- for(num=7;num>0;num--)
- {
- P1=tab[num];
- DelayMS(1000);
- }
- Operation_Type=4;
- break;
- case 4:
- num=2;
- for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
- {
- P1=tab[num];
- DelayMS(200);
- YELLOW_B=~YELLOW_B;
- if(Flash_Count%5==0)num--;
- }
- Operation_Type=1;
- break;
- }
- }
- void main()
- {
- while(1)
- {
- Traffic_light(); //Traffic_lignt ();
- }
- }
复制代码 |