单片机:K1开始流水 K2 全熄灭 K3从下到上依次点亮 来回
#include <reg52.h> #include<intrins.h> sbit key1=P3^2; sbit key2=P3^3; sbit key3=P3^4; sbit key4=P3^5; typedef unsigned int uint; typedef unsigned char uchar; void delay(uchar a) { uchar i; while(a--)for(i=0;i<120;i++); } main() { uchar led=0x7f; uchar flag=0; while (1) { if(key1==0) { delay(10); if(key1==0) { while(key1==0); flag=1; //led=0xfe; } } if(key2==0) { delay(10); if(key2==0) { while(key2==0); flag=2; } } if(key3==0) { delay(10); if(key3==0) { while(key3==0); flag=3; } } switch(flag) { case 1:P1=led;led=_cror_(led,1);delay(80);break; case 2:P1=0xff;break; case 3:P1=P1>>1;delay(80); if (P1==0X00) P1=0XFF; break; default:continue; } } }