假设P1接8个灯,高电平灯亮,主程序如下:#include "reg51.h"sbit k1=P2^0;sbit k2=P2^1;unsigned char flag=0;void main( ){unsigned char i;while(1){if(k1==0){delayms(10);if(k1==0){flag=1;}}if(flag==1){P1=0X03;for(i=0;i<7;i++){ delayms(500); P1<<=1; }}if(k2==0){delayms(10);if(k2==0){flag=2;}}if( flag==2) { P1=0X00;}}}不过程序有个问题,按K1后双灯流水,K2不起作用,必须等流水完 成后才可以检测到 K2