Dot matrix LCD : the CGRAM
|
DDRAM and CGRAM.
We still remember that communication with the 'integrated handles the LCD is manipulating control lines and data lines. In fact, the controller has a specific line for the 'access to read or write (RW) and for the selection of commands and data (RS), plus 8 data
lines.
In regard to the latter, it should be borne in mind that, even in the case in which the connection with the microprocessor it using for only 4, to save / or, a data or command extends anyway of 8
bits.
Command |
Control |
|
Data |
Function |
Execution time |
Set DDRAM
address |
RS |
RW |
|
D7 |
D6 |
D5 |
D4 |
D3 |
D2 |
D1 |
D0 |
Set DDRAM address of which can then be read or written |
37-100 us |
0 |
0 |
|
1 |
DDRAM address |
From the point of view of the code, then
bcf RSpin
; set RS = 0 for command
bcf RWpin
; set RW = 0 for write operation
movlw .5
; DDRAM relative address 5
iorlw b'100000000' ;
add DDRAM base address
call writechar ; invio il
comando al modulo
The CGRAM is to occupy 64 locations starting from 'address 40h, then extends from 40h to 7Fh: 5 bits are sufficient for the' address. As a result, the command looks like
this:
Command |
Control |
|
Data |
Function |
Execution time |
Set CGRAM
address |
RS |
RW |
|
D7 |
D6 |
D5 |
D4 |
D3 |
D2 |
D1 |
D0 |
Set CGRAM address of which can then be read or written |
40 us |
0 |
0 |
|
0 |
1 |
CGRAM address |
From the point of view of the code, then
bcf RSpin
; set RS = 0 for command
bcf RWpin
; set RW = 0 for write operation
movlw .5
; CGRAM relative address 5
iorlw b'010000000' ;
add CGRAM base address
call writechar ; invio il
comando al modulo
move current address counter to 05h in CGRAM.
A note.
Note that it is customary practice to use, for simplicity, the relative address of the
RAM; this makes it easier placement of the characters in the DDRAM locations corresponding to the display on the display. For example, for a display device with 1 line of 16
characters:
|
the first character is all 'extreme left (home), position 00 (character 1).
The character is at position Y 0Fh. |
In fact, in the memory DDRAM, the first character is the location 80h and 'last 8Fh the
lease.
Column
LCD |
Position of the symbols on the display |
Position of code in DDRAM |
hex |
bin |
dec |
hex |
bin |
1 |
0 |
00h |
00000000 |
80h |
10000000 |
2 |
1 |
01h |
00000001 |
81h |
10000001 |
.. |
.. |
.. |
.. |
.. |
.. |
15 |
14 |
0Eh |
00001110 |
8Eh |
10001110 |
16 |
15 |
0Fh |
00001111 |
8Fh |
10001111 |
It may be noted that the position of the code in the DDRAM is simply the position of the symbol on the display with the bit 7 = 1.
So, from the point of view of the code:
movlw 0x05
; DDRAM relative address 5
iorlw b'100000000' ;
add DDRAM base address
call writechar ; invio il
comando al modulo
and
movlw 0x85
; DDRAM address 5
call writechar ; invio il
comando al modulo
produce the same result.
Similarly to the CGRAM, where the two most significant bits are fixed to 01, for which
movlw 0x05
; CGRAM relative address 5
iorlw b'100000000' ;
add CGRAM base address
call writechar ; invio il
comando al modulo
and
movlw 0x45
; CGRAM address 5
call writechar ; invio il
comando al modulo
are equivalent.
As a further clarification, we indicate in the table below, in the case of the message displayed in the 'image, the content of DDRAM:
Column on LCD |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
Visible character |
1 |
x |
1 |
6 |
|
L |
C |
D |
|
D |
I |
S |
P |
L |
A |
Y |
DDRAM content |
31h |
78h |
31h |
36h |
20h |
4Ch |
43h |
44h |
20h |
44h |
49h |
53h |
50h |
4Ch |
41h |
59h |
DDRAM
address |
80h |
81h |
82h |
83h |
84h |
85h |
86h |
87h |
88h |
89h |
8Ah |
8Bh |
8Ch |
8Dh |
8Eh |
8Fh |
The conversion code in DDRAM and the corresponding ASCII symbol is carried out as described above, or by using the code as a table address in the CG and extracting and treating the corresponding 40-bit (this is completely transparent to the 'user).
|