#include void delay(unsigned int t); unsigned char buffer; sbit PB = P3^2; //設定PB代表P3.2 void main(void) { buffer = 0; //設定buffer初值為0 while(1) { while(PB == 0) //檢查PB是否為0 { delay(3); //延遲, 判斷是否為彈跳訊號 if (PB == 0) //如果PB仍然為0, 則 { buffer++; //buffer內的值加1 P2 = ~buffer; //將buffer內的值反向送到P2顯示 } while(PB == 0); //如果PB仍然為0, 則停在此行,直到放開 } } } void delay(unsigned int t) { unsigned int i; while(t--) { i=10000; while(i--); } }