Arduino UNO + DS1302 + TM1638时间显示+Proteus仿真
Arduino UNO + DS1302 + TM1638时间显示+Proteus仿真
- Proteus仿真

注意事项
- 在仿真前,需要将文件夹下的动态链接库
TM1638.dll拷贝到Proteus安装目录下的D:\Program Files (x86)\Labcenter Electronics\Proteus 8 Professional\DATA\MODELS里面,注意自己Proteus安装位置,我这里粘贴的路径只是示范。
- 将
LIBRARY文件目录下的USERDVC.IDX和USERDVC.LIB拷贝到D:\Program Files (x86)\Labcenter Electronics\Proteus 8 Professional\DATA\LIBRARY里面。
所需库
实例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <TM1638lite.h> #include <DS1302.h>
DS1302 rtc(2, 3, 5); //对应DS1302的RST,DAT,CLK // I/O pins on the Arduino connected to strobe, clock, data // (power should go to 3.3v and GND) TM1638lite tm(4, 7, 8);//STB, clock, data void initRTCTime(void)//初始化RTC时钟 { rtc.writeProtect(false); //关闭写保护 rtc.halt(false); //清除时钟停止标志 Time t(2021, 7, 15, 10, 34, 50, 5); //创建时间对象 最后参数位,为星期数据,周日为1,周一为2,周二为3,周四为5以此类推. rtc.time(t);//向DS1302设置时间数据 } void printTime()//打印时间数据 { Time tim = rtc.time(); //从DS1302获取时间数据 char buf[9]; snprintf(buf, sizeof(buf), "%02d-%02d-%02d",tim.hr, tim.min, tim.sec); for(char i=0;i<8;i++){ tm.displayASCII(i, buf[i]); } //获取星期时,需要做减一计算,由前面的星期映射关系决定的 Serial.println(buf); }
void setup() { tm.reset(); //新模块上电需要设置一次当前时间, //下载完成后需屏蔽此函数再次下载,否则每次上电都会初始化时间数据 // initRTCTime(); }
void loop() { printTime(); delay(1000); }
|
1 2 3 4 5 6
| 使用 1.1 版本的库 TM1638lite 在文件夹: C:\Users\Administrator\Documents\Arduino\libraries\TM1638lite 使用库 ds1302 在文件夹: C:\Program Files (x86)\Arduino\libraries\ds1302 (legacy) "C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "d:\\arduino\\MyHexDir/tmbac.ino.elf" 项目使用了 4378 字节,占用了 (13%) 程序存储空间。最大为 32256 字节。 全局变量使用了336字节,(16%)的动态内存,余留1712字节局部变量。最大为2048字节。
|
仿真资源和程序代码
1 2 3
| 链接:https://pan.baidu.com/s/1azuHWJoHBkcqlIOkB7mlVw 提取码:esh4
|
| 人的一生可能燃烧也可能腐朽, 我不能腐朽, 我愿意燃烧起来! —— 奥斯特洛夫斯基 |
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!