#includesbit key = P1^0;//按键void delay(unsigned int time){ unsigned int i,j; for(i=0; i for(j=0; j<1000; j++) {;}}void mian(){ unsigned int temp =0x00; while(1) { if(key == 0) { delay(20);//适当延时,消除按键抖动,自己看实际情况修改时间 if(key == 0) temp = ~temp; } P2 = temp; } }
读取P1口值,判断按键状态,从P2口输出0x00,或0xff。
我做单片机设计的
可以