Tutorial
Microcontroller 8051 |
||||||
![]() |
||||||
INITIALIZING
THE LCD The first instruction we send must tell the LCD whether we'll be communicating with it with an 8-bit or 4-bit data bus. We also select a 5x8 dot character font. These two options are selected by sending the command 38h to the LCD as a command. As you will recall from the last section, we mentioned that the RS line must be low if we are sending a command to the LCD. Thus, to send this 38h command to the LCD we must execute the following 8051 instructions: Init_lcd: mov r1,#00000001b ;Display clear acall write_inst ; mov r1,#00111000b ;Function set, ;Data 8 bit,2 line font 5x7 acall write_inst ; mov r1,#00001100b ;Display on, The write_data routine that we just wrote will send the character in the accumulator to the LCD which will, in turn, display it. Thus to display text on the LCD all we need to do is load the data in R1 to P0 that already connected to DB7 - DB0. Pretty easy, huh?
EXAMPLE : call init_LCD
The lcd module contains a certain amount of memory which is assigned to the display. All the text we write to the LCD module is stored in this memory, and the LCD module subsequently reads this memory to display the text on the LCD module itself. This memory can be represented with the following "memory map":
In the above memory map, the
area shaded in blue is the visible display. As you can see, it measures
16 characters per line by 2 lines. The numbers in each box is the memory
address that corresponds to that screen position. However, the first character of line 2, as shown in the memory map, is at address 40h. This means if we write a character to the last position of the first line and then write a second character, the second character will not appear on the second line. That is because the second character will effectively be written to address 10h--but the second line begins at address 40h. Thus we need to send a command to the LCD that tells it to position the cursor on the second line. The "Set Cursor Position" instruction is 80h. To this we must add the address of the location where we wish to position the cursor. In our example, we said we wanted to display "World" on the second line on the tenth character position. Referring again to the memory map, we see that the tenth character position of the second line is address 4Ah. Thus, before writing the word "WELCOME TO" to the LCD, we must send a "Set Cursor Position" instruction--the value of this command will be 80h (the instruction code to position the cursor) plus the address 00h. 80h + 00h = 80h. Thus sending the command 80h to the LCD will position the cursor on the firs line at the first DDRAM.
|
Lesson 1: Lesson 2: |
|||||