Arduino与Proteus仿真实例-TM1637驱动4位7段数码管仿真

TM1637驱动4位7段数码管仿真

TM1637 是一种带键盘扫描接口的LED(发光二极管显示器) 驱动控制专用电路, 内部集成有MCU 数字接口、数据锁存器、LED 高压驱动、键盘扫描等电路。本产品性能优良,质量可靠。主要应用于电磁炉、微波炉及小家电产品的显示屏驱动。

在前面的实例中对TM1637驱动控制器做了详细的介绍,请参考:

1、仿真电路原理图

在这里插入图片描述

2、仿真代码实现

本次实例使用到如下开源库:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/\*
\* A library for the 4 digit display
\*
\* Copyright (c) 2012 seeed technology inc.
\* Website : www.seeed.cc
\* Author : Frankie.Chu
\* Create Time: 9 April,2012
\* Change Log :
\*
\* The MIT License (MIT)
\*
\* Permission is hereby granted, free of charge, to any person obtaining a copy
\* of this software and associated documentation files (the "Software"), to deal
\* in the Software without restriction, including without limitation the rights
\* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\* copies of the Software, and to permit persons to whom the Software is
\* furnished to do so, subject to the following conditions:
\*
\* The above copyright notice and this permission notice shall be included in
\* all copies or substantial portions of the Software.
\*
\* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\* THE SOFTWARE.
\*/
#include <TimerOne.h>
#include "TM1637.h"
#define ON 1
#define OFF 0

int8\_t TimeDisp[] = {0x00,0x00,0x00,0x00};
unsigned char ClockPoint = 1;
unsigned char Update;
unsigned char halfsecond = 0;
unsigned char second;
unsigned char minute = 0;
unsigned char hour = 12;


#define CLK 4//pins definitions for TM1637 and can be changed to other ports
#define DIO 3
TM1637 tm1637(CLK,DIO);

void setup()
{
tm1637.set();
tm1637.init();
Timer1.initialize(500000);//timing for 500ms
Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR
}
void loop()
{
if(Update == ON)
{
TimeUpdate();
tm1637.display(TimeDisp);
}

}
void TimingISR()
{
halfsecond ++;
Update = ON;
if(halfsecond == 2){
second ++;
if(second == 60)
{
minute ++;
if(minute == 60)
{
hour ++;
if(hour == 24)hour = 0;
minute = 0;
}
second = 0;
}
halfsecond = 0;
}
// Serial.println(second);
ClockPoint = (~ClockPoint) & 0x01;
}
void TimeUpdate(void)
{
if(ClockPoint)tm1637.point(POINT_ON);
else tm1637.point(POINT_OFF);
TimeDisp[0] = hour / 10;
TimeDisp[1] = hour % 10;
TimeDisp[2] = minute / 10;
TimeDisp[3] = minute % 10;
Update = OFF;
}

3、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/120917065