#include<reg52.h> #define uc unsigned char sbit red1=P0^0; // 南北指向 sbit yellow1=P0^1; sbit green1=P0^2; sbit red2=P0^3; // 东西指向 sbit yellow2=P0^4; sbit green2=P0^5; unsigned int i=0; void aa() interrupt 1 { TH0=15536/256; TH0=15536%256; i++; if(i>1400) i=0; TF0=0; } void main() { uc t; TMOD=0x01; TH0=15536/256; TH0=15536%256; ET0=1; EA=1; TR0=1; while(1) { P2=t/10*16+t%10; if(i<600) { green2=red1=0; yellow1=yellow2=green1=red2=1; t=30-i/20; } else if(i<700) { yellow1=yellow2=0; green1=green2=red1=red2=1; t=35-i/20; } else if(i<1300) { red2=green1=0; yellow1=yellow2=red1=green2=1; t=65-i/20; } else if(i<1400) { yellow1=yellow2=0; green1=green2=red1=red2=1; t=70-i/20; } } }
接线:认识英语的应该都能接对