0:09
hello and welcome to controllers tech
0:12
this is another video covering the 16
0:14
1602 lcd display and today we will see
0:18
how to use the custom characters with
0:21
i have covered 2 videos on lcd 1602
0:25
where we did interface this display with
0:27
stm32 using i2c and another one with
0:31
simply the parallel connection
0:34
this method of creating custom
0:35
characters can work with both of those
0:37
videos so if you have already interfaced
0:40
the lcd using either of those methods
0:43
then you are good to go with today's
0:46
this is how the lcd display actually is
0:50
if you notice here you can see that each
0:52
block contains 40 pixels divided in 8
0:58
we are simply going to draw some
1:00
characters using these pixels
1:03
let's start the cube id
1:06
in the meantime let's take a look at the
1:19
as mentioned here the ic has character
1:22
generator rom cg rom and character
1:28
the cg rom has 208 pre-defined
1:32
characters stored in it
1:34
these contain the ascii characters also
1:37
and when we display some number or any
1:39
other character it basically takes the
1:41
data from the c g rom
1:44
the c g ram is where the user can write
1:46
the character patterns
1:49
we are allowed to write 8 character
1:51
patterns of 5 by 8 size
1:54
this means we can store 8 characters in
1:56
the ram and then use them on the display
2:00
if you take a look at table 4 you can
2:03
see there are some characters which we
2:05
use regularly along with some additional
2:09
as these additional characters are
2:11
already stored in the cg rom we can call
2:14
them as per our requirement
2:16
we will start with first using these
2:19
additional characters and later we will
2:21
create some of the custom characters of
2:25
let's create a new project in q by d
2:28
i am using the s d m 32 f 1 0 3 c 8
2:34
give some name to the project and click
2:38
we will set up the clock first
2:41
i am choosing an external high speed
2:44
crystal for the clock
2:46
the blue pill have eight megahertz
2:48
crystal and i am running the system at
2:53
let's go to the sys debug and enable
2:58
as i mentioned you can use parallel
3:00
connection or the i2c to connect the lcd
3:03
i have the i2c type so i am enabling the
3:08
all right that's all the configuration
3:10
required click save to generate the
3:14
first of all we need to include the lcd
3:18
this is the same old library i used in
3:21
my previous video about the lcd display
3:25
if you are using the parallel connection
3:27
include the library for that
3:30
no modification is done in the library
3:33
so you don't need to worry about that
3:36
now first i am going to test if the
3:38
display is working or not
3:41
so include the header file for the lcd
3:45
now in the main function we will
3:47
initialize the display first
3:50
then put the cursor in the beginning
3:53
and print something on it
3:55
build the project and debug it
4:08
as you can see the lcd is working fine
4:12
so we are good to go with our custom
4:15
let's start by displaying the predefined
4:19
as i mentioned these characters are
4:21
present in the cg rom and we can display
4:24
them anywhere we want on the lcd
4:26
for example say i want to display this
4:30
if you notice here we have the upper
4:32
four bits and lower four bits
4:35
corresponding to these characters
4:38
the alpha has the upper four bits as one
4:40
one one 0 and lower bits are zero zero
4:45
this makes the hexadecimal address for
4:47
this alpha character as zero cross e
4:54
let me put the cursor in the first row
4:57
and then send the address of the alpha
4:59
character as the data to the lcd
5:07
let's build the code and debug it
5:16
you can see the alpha character is being
5:18
displayed on the lower row and fifth
5:21
let's add one more character to this
5:24
this time i am going to display it in
5:34
this is the character i am going to
5:37
the upper 4 bits are 1 1 0 1 which is d
5:42
the lower bits are 0 0 1 0 which is 2.
5:47
so the address of the characters is zero
5:55
as you can see the character is being
5:57
displayed on the seventh column in the
6:00
so the predefined characters are fine
6:03
now we will see how to generate
6:04
characters and how to use them
6:08
you can find a lot of websites offering
6:11
the character generators
6:14
i am going with this one
6:16
i will leave the link to this in the
6:20
here we have a 5 by 8 matrix
6:23
they provide a pre-generated code for
6:25
arduino but that's ok as we will use a
6:29
part of this code let's say i want to
6:39
here we have the eight bytes for this
6:43
basically these five columns are the
6:45
five least significant bits and if you
6:47
see in the third row the first and third
6:52
hence we have zero cross zero a in the
6:57
similarly in the fifth position the
6:59
zeroth and fourth bits are high and
7:01
hence we have zero cross one one in
7:05
this is very simple to understand
7:08
you simply put a one wherever you want
7:10
to turn on the pixel and then convert
7:13
the binary code to hex
7:15
let's copy this and we will put it in
7:19
remember we are defining a new array
7:23
change the byte to char and give some
7:27
i am changing it to look a bit more
7:36
as per the data sheet we can save up to
7:39
8 characters in the cgram
7:41
we have only defined one character as of
7:45
let's define more of them
7:50
for example i can create a plus minus
7:53
symbol and then copy this code from here
7:58
i have already generated some characters
8:01
and here are the codes for them
8:03
all right we have the eight characters
8:05
now and we need to save them in the cg
8:12
let's city the data sheet again
8:21
as mentioned here the cgram address
8:23
starts from zero cross four zero hexa
8:27
the first two zeros are for the read
8:29
write and command data operations so you
8:32
need to neglect them for the addressing
8:38
in order to store the character in the
8:40
cgram we need to first send the location
8:43
of the ram and i am starting with 0
8:45
cross 4 0 the start position for the
8:50
now we will write our first character at
8:57
this is basically the smiley face we
9:08
now for every character the address will
9:10
shift by eight positions as each
9:12
character occupies eight bytes
9:19
this way our eighth character will be
9:21
placed at an offset of 56 bytes which
9:24
makes the cgram size as 64 bytes in
9:28
the characters have been stored in the
9:30
cg ram now we will display them
9:34
let's put the cursor in the beginning of
9:38
and we will send the data which will
9:40
basically be the address of the first
9:42
character in the cgram that is zero
9:46
just to show you guys that this works
9:48
together with regular data i am
9:50
displaying r in the middle of the two
9:55
the second character has the address one
9:57
which will basically be at the position
9:59
zero cross four eight in the c g ram
10:03
let's also display this plus minus
10:05
symbol which is at the last position and
10:08
its address will be 7.
10:21
all right build the code and run it
10:33
you can see the characters are being
10:34
displayed just as we want them to be
10:41
we can simply send all the characters
10:43
together and display them just one after
11:02
here you can see on the display all the
11:04
characters are being displayed at once
11:11
there are other ways of storing the data
11:19
for example we can group all the
11:21
characters in a single array
11:46
and then store all the 64 bytes starting
11:49
at address 0 cross 4 0 the start of the
11:54
this will simply store all these bytes
11:57
into the c g ram and we still have the
11:59
same fixed positions of those characters
12:10
i am keeping this same so the lcd should
12:13
display all the characters together
12:16
let's build and run this code now
12:19
you can see the characters are
12:21
displaying as they should so i hope you
12:24
understood how to deal with custom
12:26
characters on the lcd-1602
12:30
as i mentioned the process will work
12:32
well with the parallel or i-2-c
12:36
remember that you can only use 8
12:38
characters to store in the c g ram
12:42
this is it for the video
12:44
you can download the code from the link
12:49
leave comments in case of any doubt keep
12:52
watching and have a nice day ahead