找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索

求程序思路 可暫停arduino計(jì)時(shí)器

查看數(shù): 1630 | 評論數(shù): 3 | 收藏 0
關(guān)燈 | 提示:支持鍵盤翻頁<-左 右->
    組圖打開中,請稍候......
發(fā)布時(shí)間: 2022-7-4 11:05

正文摘要:

由于本論壇禁止直接求程序,禁止伸手黨,所以向大家請教一下大致的實(shí)現(xiàn)方法與思路,理清頭緒后我自己來寫程序去實(shí)現(xiàn),謝謝大家

回復(fù)

ID:161164 發(fā)表于 2022-7-6 18:52
gbgb52 發(fā)表于 2022-7-6 11:21
為啥顯示錯(cuò)誤,求解,大佬

因?yàn)樗o的是8051的代碼,只是給一個(gè)思路
你需理解后,以Arduino的C++寫出來
ID:827243 發(fā)表于 2022-7-5 09:31
思路如下,請參考。
  1. void main(void) {
  2.     int timerCount[5]={0,0,0,0,0};      //5個(gè)計(jì)時(shí)器
  3.     char timerPtr;          //計(jì)時(shí)器指針
  4.     char timerShowPtr;      //計(jì)時(shí)器顯示指針
  5.     char timerStat;         //計(jì)時(shí)狀態(tài)  1 計(jì)時(shí) 0 停止計(jì)時(shí)
  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ì)時(shí)器 timerCount[timerShowPtr];
  15.         }
  16.     }
  17. }

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

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

評分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎(jiǎng)勵(lì)!

查看全部評分

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表