|
char LastKey; LastKey = 1; while(1) { if(k == 0 && LastKey == 1) //按下,且上一次檢測(cè)按鍵時(shí)是彈起狀態(tài) { //這樣才能保證每次按下時(shí)只執(zhí)行一次, //而不是一直在執(zhí)行 Delay1ms(20); if(k == 0) //確定是第一次按下,執(zhí)行動(dòng)作 { if((n % 2) == 0) { LedFlash(); } else { P0 = 0xFF; } n++; } } LastKey = k; //保存按鍵狀態(tài) } |
|