#include<reg52.h> #include<intrins.h> sbit KEY1=P2^0; sbit KEY2=P2^1; sbit KEY3=P2^2; sbit KEY4=P2^3; sbit BELL=P2^4; sbit RED1=P1^0; sbit YEL1=P1^1; sbit GRE1=P1^2; sbit RED2=P1^3; sbit YEL2=P1^4; sbit GRE2=P1^5; sbit RED3=P1^6; sbit YEL3=P1^7; sbit GRE3=P3^0; sbit RED4=P3^1; sbit YEL4=P3^2; sbit GRE4=P3^3; #define uint unsigned int void Delay(uint); void Key(); void Bell(uint); void main() { while(1) Key(); } void Key() { if(KEY1==0 || KEY2==0 || KEY3==0 || KEY4==0) { Delay(2); //20??????????í????·?????? if(KEY1 == 0) { RED1=0; RED2=0; RED3=0; RED4=0; Bell(10); } else if(KEY2 == 0) { YEL1=0; YEL2=0; YEL3=0; YEL4=0; Bell(10); } else if(KEY3 == 0) { GRE1=0; GRE2=0; GRE3=0; GRE4=0; Bell(10); } else { RED1=0; RED2=0; RED3=0; RED4=0; YEL1=0; YEL2=0; YEL3=0; YEL4=0; GRE1=0; GRE2=0; GRE3=0; GRE4=0; Bell(10); } Delay(50); //??????±0.5????????????????????????°????ü??????ì???? RED1=1; RED2=1; RED3=1; RED4=1; YEL1=1; YEL2=1; YEL3=1; YEL4=1; GRE1=1; GRE2=1; GRE3=1; GRE4=1; } } void Bell(uint a) { uint b; for(b=100;b>0;b--) { BELL=0; Delay(a); BELL=1; Delay(a); } } void Delay(uint z) { uint x,y; for(x=100;x>0;x--) for(y=z;y>0;y--); }