#include <reg51.h>
#define INT8U unsigned char
#define INT16U unsigned int
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;
INT8U Time_Count=0,Flash_Count=0,Operation_Type=1;
void T0_INT() interrupt 1
{
TH0=(65536-50000)>>8;
TL0=(65536-50000)&0xff;
switch(Operation_Type)
{
case 1:red_a=1;yellow_a=1;green_a=0;
red_b=0;yellow_b=1;green_b=1;
if(++Time_Count!=100) return;
Time_Count=0;
Operation_Type=2;
break;
case 2:if(++Time_Count!=8) return;
Time_Count=0;
yellow_a=!yellow_a;green_a=1;
if(++Flash_Count!=10) return;
Flash_Count=0;
Operation_Type=3;
break;
case 3:red_a=0;yellow_a=1;green_a=1;
red_b=1;yellow_b=1;green_b=0;
if(++Time_Count!=100) return;
Time_Count=0;
Operation_Type=4;
break;
case 4:if(++Time_Count!=8) return;
Time_Count=0;
yellow_b=!yellow_b;green_b=1;
if(++Flash_Count!=10) return;
Flash_Count=0;
Operation_Type=1;
}
}
void main()
{
TMOD=0x01;
IE=0x82;
red_a=1;red_b=1;
yellow_a=1;yellow_b=1;
green_a=1;green_b=1;
while(1);
}
|