#include<reg51.h> #include<intrins.h> /* K1按:D2亮,D9亮,D8亮,D7亮,D6亮,D5亮,D4亮,D3亮,D2亮,D9亮,循环亮 K2按:所有都不亮 K3按:暂停,只有一亮 K4按:D9亮,D2亮,D2亮,D4亮,D5亮,D6亮,D7亮,D8亮,D9亮,D2亮,循环亮 */ #define uchar unsigned char sbit k1=P3^2; sbit k2=P3^3; sbit k3=P3^4; sbit k4=P3^5; void delay(uchar a) { uchar i; while(a--)for(i=0;i<120;i++); } main() { uchar flag=0; uchar led=0x7f; while(1) { if(k1==0) { delay(10); if(k1==0) { while(k1==0); flag=1; led=0xfe; } } if(k2==0) { delay(10); if(k2==0) { while(k2==0); flag=2; } } if(k3==0) { delay(10); if(k3==0) { while(k3==0); flag=3; } } if(k4==0) { delay(10); if(k4==0) { while(k4==0); flag=4; led=0x7f; } } switch(flag) { case 1:P1=led;led=_cror_(led,1);delay(100);break; case 2:P1=0xff;led=0xff;break; case 3:P1=led;break; case 4:P1=led;led=_crol_(led,1);delay(100);break; default:break; } } }