#include<REGX52.H>voidDelay(unsignedint xms){unsignedchar i, j;while(xms--){
i =2;
j =199;do{while(--j);}while(--i);}}voidmain(){while(1){if(P3_1==0){Delay(20);while(P3_1==0);Delay(20);
P2_0=~P2_0;}}}
独立按键 led二进制
#include<REGX52.H>voidDelay(unsignedint xms){unsignedchar i, j;while(xms--){
i =2;
j =199;do{while(--j);}while(--i);}}voidmain(){unsignedchar x=0;while(1){if(P3_1==0){Delay(20);while(P3_1==0);Delay(20);
x++;
P2=~x;}}}
独立按键控制led移位
#include<REGX52.H>voidDelay(unsignedint xms){unsignedchar i, j;while(xms--){
i =2;
j =199;do{while(--j);}while(--i);}}voidmain(){unsignedchar x=0;
P2_0=0;while(1){if(P3_0==0){Delay(20);while(P3_0==0);Delay(20);
x++;
x=x%8;
P2=~(0x01<<x);}if(P3_1==0){Delay(20);while(P3_1==0);Delay(20);if(x==0)
x=7;else
x--;
P2=~(0x01<<x);}}}