|
思路如下,請(qǐng)參考。
- void main(void) {
- int timerCount[5]={0,0,0,0,0}; //5個(gè)計(jì)時(shí)器
- char timerPtr; //計(jì)時(shí)器指針
- char timerShowPtr; //計(jì)時(shí)器顯示指針
- char timerStat; //計(jì)時(shí)狀態(tài) 1 計(jì)時(shí) 0 停止計(jì)時(shí)
- timerPtr=0; //初始狀態(tài)為全零
- timerShowPtr=0;
- timerStat=0;
- while (1) {
- if (timerStat==1) {
- timerCount[timerPtr]++;
- }
- else {
- 顯示當(dāng)前計(jì)時(shí)器 timerCount[timerShowPtr];
- }
- }
- }
- void exint0() interrupt 0 { //按鍵1中斷
- timerStat=1-timerStat; //計(jì)時(shí)和停止計(jì)時(shí)切換
- }
- void exint1() interrupt 2 { //按鍵2中斷
- if (timerStat==0) { //停止計(jì)時(shí)中
- timerShowPtr++;
- if (timerShowPtr>=5) timerShowPtr=0;
- }
- else { //計(jì)時(shí)中
- timerPtr++;
- if (timerPtr>=5) timerPtr=0;
- timeCount[timerPtr]=0;
- }
- }
復(fù)制代碼 |
評(píng)分
-
查看全部評(píng)分
|