0:07
hello everyone welcome to controllers
0:11
Tech many of you requested this so here
0:15
we are interfacing LCD 16 by 2 with SDM
0:19
32 but without i2c this time in parallel
0:23
connection LCD can work in two different
0:26
modes 8-bit and 4-bit mode in 8-bit mode
0:32
we need to use all eight data pins and
0:35
in 4-bit mode we can use only four data
0:37
pins we will use 4-bit mode in this
0:41
tutorial let's start with the cube ID
0:46
create a new SDM 32 project
0:56
I am using f103 c8 controller give some
1:02
name to the project and click finish
1:27
we have the cube MX here for the setup
1:30
I am enabling the external crystal for
1:34
the clock enable the serial wire debug
1:38
we also need the delay in microseconds
1:41
so I am using timer one for the same if
1:45
you don't know about micro second delay
1:47
check out the video on the top right
1:49
corner let's set up the clock first I
1:53
want to run the controller at maximum
1:56
possible frequency 72 megahertz the APB
2:07
to clock is also at 72 megahertz and
2:09
timer 1 is connected to a PB to a
2:13
prescaler of 72 will divide the clock to
2:16
one megahertz input the maximum possible
2:20
value for the ARR that is 0 cross ffff
2:24
as it is 16-bit register as shown in
2:28
this picture pins PA 1 to PA 7 are
2:31
connected to the LCD we need to select
2:43
this is it for the setup now click Save
2:47
and the project will be generated
3:01
here is our main dot C file first of all
3:12
we need to include the library files you
3:21
can get these files after you download
3:23
the project from the link in the
3:25
description there is nothing special in
3:34
the header file these are the functions
3:37
that you can use for the LCD we need to
3:40
modify things in the LCD 1602 dot C file
3:45
my connections is as shown in the
3:47
picture from our s to enable pin and
3:51
from d4 to d7 you can use any pin and
3:55
any port for the connection just make
3:58
sure you define them properly here
4:22
define the timer handler that you are
4:34
this function here is an internal
4:37
function and it is not defined in the
4:40
header file send to LCD is for writing
4:44
the four bit data or command to the pins
4:47
of the LCD it takes two parameters first
4:51
is the useful data which is only four
4:54
bit long and second is the RS we update
4:58
the pins to the respective bits in the
5:00
data variable RS must be one for sending
5:10
data and zero for sending command once
5:18
the data is written to the pins
5:20
we will toggle the enable pin this will
5:23
ensure that the data has been updated
5:25
successfully I am keeping this 20
5:29
microseconds delay commented out right
5:32
we will see if it works without the
5:34
delay or not for higher clocks this
5:38
delay must be there if the display shows
5:42
some weird characters try increasing or
5:44
reducing this delay LCD send command is
5:48
used to send the command to the LCD as
5:52
we are only using for data pins our
5:55
8-bit command should also be divided
5:57
into two 4-bit commands that's why we
6:01
need to send the command into two halves
6:03
upper nibble and lower nibble note that
6:07
RS is 0 to indicate that it's a command
6:10
LCD send data is used to send the data
6:14
to the LCD it uses the same process of
6:18
sending the upper nibble first and then
6:20
lower one the Rs pin must be high to
6:23
indicate that the data is being sent LCD
6:28
clear clears the LCD put cursor command
6:32
is used to put the cursor at the entered
6:34
location row can be 0 or 1 and column
6:48
this function initializes the LCD in the
6:51
4-bit mode these commands are written as
6:55
per instructions in the datasheet then
6:58
you have some display control functions
7:01
here you can modify them if you want
7:04
some other configuration for example if
7:07
you want the blinking cursor use C and V
7:11
as one in this command let's write the
7:14
main code now first we need to include
7:18
the header file make sure you start the
7:27
timer before initializing the LCD now I
7:36
am going to put the cursor at zero zero
7:38
and send some strings to the LCD
7:50
and then put the cursor at first row and
7:54
zero column and then send another string
7:58
I want to wait for three seconds and
8:08
then clear the display inside the while
8:11
loop this function will print the ASCII
8:14
characters from 1 to 128 build the code
8:29
there are no errors let's flash it
8:32
select stm32 application click OK and
8:40
wait for the debugger to launch
8:52
as you can see the characters are being
8:56
printed but quite not what we want this
8:59
is happening due to the delay missing in
9:02
the enable pin strobe
9:18
let's enable the delay and flash the
9:21
code again if you face the problem again
9:26
try increasing or decreasing this delay
9:50
as you can see the data is being printed
9:55
properly let me just reset the
9:58
controller again ASCII characters will
10:08
continue to print from 0 to 128 every
10:38
this is it guys I hope you understood
10:42
the video this video was made on demand
10:45
as I got many requests for this keep
10:49
watching have a nice day