|
基于arduino的計(jì)時器(包涵倒計(jì)時、暫停、重置),在proteus8中仿真通過。用了兩組1673的時鐘芯片。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.gif (51.39 KB, 下載次數(shù): 66)
下載附件
2021-10-25 14:53 上傳
76b4d42af5197eb039377377011a0e82.png (69.39 KB, 下載次數(shù): 64)
下載附件
2021-10-25 12:02 上傳
Arduino代碼如下:
- #include <SevenSegmentTM1637.h>
- #include <SevenSegmentExtended.h>
- volatile int minute;
- volatile int second;
- volatile int order;
- volatile int full;
- volatile int empty;
- volatile int setvalue;
- volatile int topvalue;
- boolean timerState=LOW;
- SevenSegmentExtended display(8,9);
- void setup(){
- pinMode(2, INPUT);
- minute = 0;
- second = 0;
- order = 0;
- full = 0;
- empty = 0;
- setvalue = 5;
- topvalue = 0;
- display.begin();
- order = 0;
- // 倒計(jì)時時sencond與minute從full開始計(jì)時,順計(jì)時從empty開始計(jì)時
- if (order == 0) {
- empty = 0;
- full = 59;
- minute = setvalue;
- second = 0;
- topvalue = 0;
- } else {
- empty = 59;
- full = 0;
- minute = 0;
- // 設(shè)置為x分鐘,加上秒鐘走59,實(shí)際多走了一分鐘,所以減一
- topvalue = setvalue - 1;
- }
- attachInterrupt(digitalPinToInterrupt(2),interruptFun,LOW);
- }
- void loop(){
- // 決定順計(jì)時倒計(jì)時0為倒計(jì)時,1為順計(jì)時
- // 設(shè)置計(jì)時的最大數(shù)值
- // 倒計(jì)時時topvalue=0時minute重置為setvalue
- // 順計(jì)時topvalue=setvalue值時被重置
- // minute=0
- if(timerState)
- {
- display.printTime(minute,second,true);
- delayMicroseconds(1);
- if (second == empty && minute == topvalue) {
- if (order == 0) {
- // 當(dāng)minute達(dá)到設(shè)定的值則
- minute = setvalue;
- second = empty;
- } else {
- // 當(dāng)minute達(dá)到設(shè)定的值則
- minute = full;
- second = full;
- }
- } else if (second == empty) {
- if (order == 0) {
- second = 59;
- minute = minute - 1;
- } else {
- second = 0;
- minute = minute + 1;
- }
- } else {
- if (order == 0) {
- second = second - 1;
- } else {
- second = second + 1;
- }
- }
- }
- }
- void interruptFun()
- {
- timerState=!timerState;
- digitalWrite(5,timerState);
- // Inside the attached function, delay() won't work and the value returned by millis() will not increment.
- // delay(5000);
-
- }
復(fù)制代碼
51hei.png (2.75 KB, 下載次數(shù): 57)
下載附件
2021-10-25 14:57 上傳
Proteus8.8版本的仿真圖下載:
countDowntimer.zip
(31.11 KB, 下載次數(shù): 53)
2021-10-25 11:03 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|