全套代码如下:
仿真图请参考微信公众号“伊斯电子编程”拿取
B站可以查看实现效果
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
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 Time_Count = 0,Flash_Count = 0,Operation_Type = 1;
void T0_INT() interrupt 1
{
TH0 = -50000/256;
TL0 = -50000%256;
switch(Operation_Type)
{
case 1:
RED_A=0;YELLOW_A=0;GREEN_A=1;
RED_B=1;YELLOW_B=0;GREEN_B=0;
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=0;
if(++Flash_Count != 10) return;