0:09
hello and welcome to controller Tech
0:12
today we will see how to interface the
0:14
seven segment display with SDM 32
0:18
microcontroller these displays come in
0:20
different varieties some need to be
0:22
connected directly with the MCU While
0:25
others have some special LED Drive
0:27
control chip soldered into the board the
0:30
segment display I am going to cover has
0:33
tm1637 chip connected to the
0:39
tm1637 is a kind of LED Drive control
0:42
special circuit with a keyboard scan
0:45
interface since we don't have a keypad
0:48
we will just focus on the LED Drive part
0:51
IC the display has four different digits
0:55
and each digit has seven
0:57
segments a segment basically means the
1:00
LED and there are seven LEDs assigned to
1:03
each digit other than that it also has
1:06
the colon in the middle which can be
1:08
used during the clock
1:10
display each digit has a different
1:13
address mentioned on the top but we will
1:15
talk about it later in the
1:17
video I am going to control this display
1:20
using the SDM 32 f103 controller and
1:24
here you can see the connection I made
1:27
the blue wire is the clock pin and and
1:30
yellow is the I/O pin we only need these
1:33
two pins to control this display clock
1:37
data I have connected the clock pin to
1:40
pb10 of the MCU and the io pin to pb11
1:45
MCU other than these the VCC pin is
1:48
connected to the 3.3 volts and ground is
1:53
ground this is the data of the
1:57
tm1637 we will only see the important
2:02
sheet by the way this display is also
2:05
available on controller's text store so
2:07
the Indian users can purchase it from
2:10
there you can also download the
2:12
schematic and data sheet from the
2:16
itself I will leave the link in the
2:19
description let's start the Q ID and
2:24
project I am using stdm 32 f103 C8 T6
2:30
give some name to the project and click
2:33
finish let's start with the clock setup
2:37
first I am selecting an external Crystal
2:40
to provide the clock the board has 8 MHz
2:44
Crystal on it and let's run the system
2:48
MHz go to CIS debug and enable serial
2:54
debug let's set the pins now I have
2:58
connected the clock pin to p pb10 and IO
3:02
pb11 so set these pins as output and
3:07
accordingly now go to gpio setting
3:10
select both the pins and set the maximum
3:13
output speed to high that is all we need
3:17
to set up click save to generate the
3:20
project we will create a separate
3:22
Library file for this display so create
3:25
a new source file in the source
3:26
directory and a new header file in the
3:30
ctory let's take a look at the data
3:32
sheet now this data sheet mainly covers
3:36
the keypad interface but we will just
3:38
focus on a few things needed to
3:41
display here you can see the address for
3:44
the individual grid a grid actually
3:48
represents a digit and this driver is
3:50
capable of interfacing six digits
3:53
together we have only four digits on the
3:55
display so the grided address will vary
4:00
hex this is what I have mentioned in the
4:03
first image we saw the colon in the
4:06
middle of the display comes under the
4:07
address C1 hex it is controlled by the
4:11
bit B7 of the segment but we will talk
4:13
about it later the rest of the digits
4:16
have their individual
4:19
addresses as mentioned here in order to
4:21
send a start condition the clock should
4:24
be at high level and the data pin should
4:26
change from high to low level you can
4:29
see the same in this timing
4:31
diagram the clock is at high level and
4:34
when the data changes from high to low
4:37
this is considered a start condition
4:40
similarly to send a stop condition the
4:42
clock should be at high level and the
4:44
data pin should change from low to high
4:48
you can see the stop condition in the
4:53
diagram the data transfer is always
4:55
answered with the acknowledgement
4:58
signal here the device pulls the data
5:00
pin low at the falling edge of the
5:02
eighth clock cycle and then releases the
5:04
line at the end of the ninth clock cycle
5:08
there are different modes available in
5:12
tm1637 the first one is command data
5:14
transfer which is used for reading the
5:19
keypad we will skip this one as we are
5:22
using it to interface the display the
5:25
second one is used when you want the
5:27
address to autoincrement and the third
5:29
third one is used for the fixed address
5:32
mode I will use this autoincrement mode
5:35
as this is more useful right
5:38
now here we send the command one first
5:41
which should be the set data
5:43
command then send the command two the
5:47
command then send the data bytes since
5:50
we have only four digits we can send a
5:53
maximum of four datab bytes at
5:55
once finally send the command three
5:59
which is the control display
6:01
command we will see these commands in
6:03
detail when we write the
6:05
code I have another data sheet of the
6:08
same device but this one contains the
6:13
format this code is actually written for
6:15
the AVR MCU but we will use it as the
6:18
reference for our SDM
6:21
32 all right let's open the
6:24
tm1637 source file include the main
6:28
header file along with the T M1 1637
6:31
header file let's write a function to
6:34
send the start condition to the
6:36
device we will modify this start
6:42
MCU let me first Define the functions to
6:45
set and reset the clock and edit a pin
6:49
it will be easier for us to call these
6:51
functions directly later in the code
7:07
all right here the clock is setor one so
7:10
call the function clock High then the
7:13
data pin is setor one so call data High
7:17
then there is 2 microsc delay and later
7:20
the data is set to zero so call data low
7:25
now let's write the function for the
7:27
delay the delay does not necessarily
7:30
need to be in the micros seconds the
7:33
device does not have any such
7:34
requirements as per the data sheet so we
7:37
will just write a simple function to
7:39
provide a very small delay my system
7:42
clock is at 72 MHz so I am setting the
7:45
maximum value for the variable J as 7 if
7:49
you are running the system at 50 MHz set
7:52
it to 5 or for 100 MHz set it to 10 the
7:57
start function is as per the information
7:59
in the data sheet first the clock and
8:02
data should be high then while the clock
8:05
is still high the data should transit to
8:08
low this generates a start condition for
8:11
the device let's write the function for
8:14
the Stop condition we will modify the
8:17
code for the Stop condition provided in
8:21
sheet reset the clock then reset the
8:24
data then set the clock and in the end
8:26
set the data this is again as per the
8:30
instructions provided here first both
8:33
clock and data are low then the clock
8:36
transits to high while the data is still
8:39
low and finally the data transits to
8:42
high while the clock is high we have
8:45
both start and stop functions now we
8:48
will write the function to read the
8:49
acknowledgement from the
8:54
device first reset the clock pin and
8:58
then wait for some time
9:00
here the function checks for the state
9:02
of the data pin and it waits for the
9:04
data pin to go low but we have set the
9:07
data pin as output so we can't perform
9:10
this check so we will skip this step if
9:13
the device is responding the data pin
9:16
will anyway be low here you can see the
9:19
acknowledgement on the timing diagram
9:22
first the clock is pulled low and then
9:25
there is a considerably larger delay at
9:28
this point the data P should be low then
9:31
the clock is set to high and after a
9:33
small delay it is reset back to low next
9:37
we will write the function to write a
9:39
single bite to the display this bite can
9:45
data let's modify this code according to
9:50
functions here we extract a single bit
9:53
from the bike data if the bit is a one
9:55
we set the data pin and if the bit is a
9:58
zero we set the data pin note that the
10:02
data is transmitted while the clock is
10:04
low this is as for the instructions in
10:06
the data sheet after transmitting one
10:09
bit the bite is shifted to the right by
10:11
one place and the same operation is
10:14
performed again now we will write
10:16
another function to send the actual data
10:19
to the device the parameter of this
10:22
function will be the digit address where
10:24
the data needs to be displayed and the
10:26
pointer to the data we have the code for
10:29
for it in the data sheet but instead we
10:31
will write it by understanding the
10:34
sequence as you can see here to write
10:36
the data to the display we need to send
10:39
the set data command followed by the set
10:41
address command followed by the data and
10:44
at last the display control
10:47
command here is the table describing the
10:51
command it is basically used to
10:53
configure between writing data to the
10:55
register or reading the key scan data
10:58
along with the address mode you want to
11:00
use we want to write the data to the
11:03
display along with the automatic address
11:06
mode so our Command will contain a one
11:09
only at the B6 position to write the
11:12
command one we will first send the start
11:15
condition followed by the command 40 hex
11:19
then wait for the acknowledgement and
11:21
send the stop condition next we need to
11:25
send the set address command followed by
11:29
note that there is no stop condition
11:31
between the address command and the data
11:36
continuously once all the data bytes
11:38
have been transferred we can issue the
11:41
stop condition the address is already
11:44
defined in the parameter of this
11:46
function so we will pass the same
11:48
address let's define one more parameter
11:51
here size of the data now first send the
11:55
start condition then send the command
11:59
two the address and wait for the
12:02
acknowledgement now send the data bytes
12:05
and wait for acknowledgement after
12:07
sending each data bite once all the data
12:10
has been transferred send the stop
12:13
condition finally we need to send the
12:16
command three the control display
12:19
command this command controls the
12:22
display brightness along with the
12:25
control we definitely want to turn the
12:27
display on so the bits B7 and B3 must be
12:31
one bits B 0 to B2 controls the
12:36
display the more the propulse width the
12:38
brighter the LEDs are I will set it to a
12:42
random value let's say to 1/4th of the
12:46
brightness so the command 3 value I have
12:51
hex let's send the command three in the
12:54
same pattern send the start condition
12:57
followed by the command 3
12:59
by then wait for the acknowledgement and
13:02
finally send the stop condition let's
13:06
define this function in the header file
13:08
so that we can call it from the main
13:10
file we will write the main file now
13:16
tm1637 header file let's give some delay
13:20
before we can proceed with the
13:22
function this delay is not necessary I
13:25
am just adding it now call the function
13:30
tm1637 WR data the address will be the
13:34
address for the first digit c0 hex the
13:39
data is basically decided based on which
13:41
segments of the digit you want to turn
13:43
on here you can see each digit has seven
13:49
G here each segment represents one bit
13:54
now let's say I want to display the
13:56
letter A to do this I need to turn on
13:59
the segments a b c e f and g similarly
14:06
if I want to display the number two I
14:08
need to turn on the segments a b g e and
14:13
D here you can see the binary data
14:16
respective to each digit or letter I
14:19
want to display the letter c so let's
14:22
copy this data from here now let's
14:25
Define a variable data and assign the
14:30
variable since the function takes the
14:32
pointer to the data we will pass the
14:34
address of the variable here the size is
14:38
bite all right let's build and Flash the
14:41
project to the board you can see the
14:44
letter c being displayed on the first
14:47
digit now I am changing the address to
14:49
C1 hex and flashing the code again we
14:53
now have the letter c on the second
14:55
digit also the data is being retained in
14:58
the the first digit as I mentioned
15:01
earlier this colon is also part of the
15:04
address C1 to turn on this colon we need
15:07
to write a one to the most significant
15:09
bit of the data so let's set this bit to
15:13
one and Flash the code again the colon
15:16
is also turned on now let's keep going
15:20
and now I am setting the address for the
15:22
third digit the letter c is now being
15:25
displayed on the third digit too and and
15:29
finally we will display this letter to
15:31
the fourth digit also so we can control
15:34
the data on the individual digits by
15:37
setting the respective address now we
15:40
will see how we can send the data for
15:42
all the digits at once here I am
15:45
defining an array of four bytes I want
15:49
to display the number 1 2 3 4 on the
15:52
display so let's copy the binary data
16:00
now send the four bytes array to the
16:02
display starting from the address c0
16:13
hex you can see the number 1 2 3 4 on
16:16
the display so we successfully
16:19
interfaced the seven segment display
16:22
tm1637 driver IC in the next video we
16:26
will write functions to print the number
16:28
numers directly on the display we will
16:31
also program to use this display as the
16:34
clock this is it for today you can
16:38
download the code from the link in the
16:40
description leave comments in case of
16:43
any doubt keep watching and have a nice