//範例7-6c:可控制四位數計數器 //檔名:ch7_6.c #include "seg7.h" sbit SW1=P2^0 ; // 計數器啟動開關 sbit SW2=P2^1 ; // 計數器歸零開關 sbit SW3=P2^2 ; // 計數器速度控制開關 main() { int i,count=0,reptime=2; while(1) { for(i=0;i<=reptime;i++) digitx4(count); // 顯示計數器的四位數 if(~SW1) count++; //計數器數字加1 else if(~SW2) count=0; if(~SW3) reptime=200; //計數器速度變慢 else reptime=10; //計數器速度變快 } }