標(biāo)題: 求程序思路 可暫停arduino計(jì)時器 [打印本頁]

作者: gbgb52    時間: 2022-7-4 11:05
標(biāo)題: 求程序思路 可暫停arduino計(jì)時器
由于本論壇禁止直接求程序,禁止伸手黨,所以向大家請教一下大致的實(shí)現(xiàn)方法與思路,理清頭緒后我自己來寫程序去實(shí)現(xiàn),謝謝大家

IMG_20220704_110437.jpg (2.1 MB, 下載次數(shù): 79)

IMG_20220704_110437.jpg

作者: daemondong    時間: 2022-7-5 09:31
思路如下,請參考。
  1. void main(void) {
  2.     int timerCount[5]={0,0,0,0,0};      //5個計(jì)時器
  3.     char timerPtr;          //計(jì)時器指針
  4.     char timerShowPtr;      //計(jì)時器顯示指針
  5.     char timerStat;         //計(jì)時狀態(tài)  1 計(jì)時 0 停止計(jì)時
  6.     timerPtr=0;   //初始狀態(tài)為全零
  7.     timerShowPtr=0;
  8.     timerStat=0;
  9.     while (1) {
  10.         if (timerStat==1) {
  11.             timerCount[timerPtr]++;
  12.         }
  13.         else {
  14.             顯示當(dāng)前計(jì)時器 timerCount[timerShowPtr];
  15.         }
  16.     }
  17. }

  18. void exint0() interrupt 0 {     //按鍵1中斷
  19.     timerStat=1-timerStat;      //計(jì)時和停止計(jì)時切換
  20. }

  21. void exint1() interrupt 2 {     //按鍵2中斷
  22.     if (timerStat==0) {   //停止計(jì)時中
  23.         timerShowPtr++;
  24.         if (timerShowPtr>=5) timerShowPtr=0;
  25.     }
  26.     else {      //計(jì)時中
  27.         timerPtr++;
  28.         if (timerPtr>=5) timerPtr=0;
  29.         timeCount[timerPtr]=0;
  30.     }
  31. }
復(fù)制代碼

作者: gbgb52    時間: 2022-7-6 11:21
daemondong 發(fā)表于 2022-7-5 09:31
思路如下,請參考。

為啥顯示錯誤,求解,大佬

IMG20220706112124.jpg (1.76 MB, 下載次數(shù): 84)

IMG20220706112124.jpg

作者: lkc8210    時間: 2022-7-6 18:52
gbgb52 發(fā)表于 2022-7-6 11:21
為啥顯示錯誤,求解,大佬

因?yàn)樗o的是8051的代碼,只是給一個思路
你需理解后,以Arduino的C++寫出來




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1