Lcd1602 user manual, explain the use of LCD1602
- Apr 16, 2018 -

LCD1602 is a character liquid crystal display that many microcontroller enthusiasts come into contact with earlier. Its main control chip is HD44780 or other compatible chips. Most of the beginners who came into contact with it are microcontrollers. Because of its lack of understanding, it cannot be driven as it pleases. After a period of study, I had a bit of a glimpse of its drive and today it is recorded here for later reference.


In general, the LCD1602 has 16 pins and is said to have 14 pins. Compared with the 16-pin, the LCD 1602 lacks the backlight power supply A (15 feet) and the ground line K (16 feet). The model of the LCD1602 in my hand is the HJ1602A, which is a product of the Legend of Technology Corporation. It has 16 pins.


555.jpg


Lcd1602 user manual, explain the use of LCD1602


The basic operation of LCD1602


1. Read status: input RS=0, RW=1, E=high pulse. Output: D0-D7 is the status word.


2. Read data: input RS=1, RW=1, E=high pulse. Output: D0-D7 is data.


3. Write command: input RS=0, RW=0, E=low pulse. Output: None. (Write E = high pulse)


4. Write data: input RS=1, RW=0, E=low pulse. Output: None.


Analysis sequence diagram


(1) Write operation (SCM to HD44780)


Lcd1602 user manual, explain the use of LCD1602


The first thing to do is to configure register selection and read and write operation selections. RS is register selection, RS = 1 operates on data, and RS = 0 operates on instructions.


Then configure read and write operations, RW = 0 write operations.


Turn on the enable terminal and input enable signal E = 1.


Data bus, assignment to DB0~DB7, data transfer


Note: If you enable it first, and then perform other configurations, it is possible that the transmitted data is not what you want.


(2) Read Operation (HD44780 to Microcontroller)


Lcd1602 user manual, explain the use of LCD1602


The instruction set of the display module is configured according to its own display needs


Lcd1602 user manual, explain the use of LCD1602


Lcd1602 user manual, explain the use of LCD1602


Lcd1602 user manual, explain the use of LCD1602


Lcd1602 user manual, explain the use of LCD1602


Display position setting DDRAM


Lcd1602 user manual, explain the use of LCD1602


The data displayed in one column of the first row can be written as follows: 0x80 | 0x**, the data displayed in one column of the second row can be written as follows: 0x80 | 0x40 | 0x** = 0xC0 | 0x**, 0x80 because DB7 is fixed to 1 when setting the DDRAM address.


LCD1602 writes its own characters and displays Chinese characters


1. Since the LCD is an external device and the processing speed is slower than that of the CPU, it takes a certain time to write commands to the LCD to complete the function. In this process, the LCD is busy and cannot write new contents to the LCD. Whether the LCD is busy can be understood by reading the busy flag command.


Use state = LCDPORT to read the status of the IO port and state & 0x80 to determine if the LCD is busy. If the IO port bit7 is 1, the LCD is busy, otherwise it is idle.


2. To allow the LCD1602 to display custom characters, use the CGRAM instruction. The CGROM word table actually has only 8 bytes available. Writecom (0x40) indicates that the data will be written in CGRAM. The command to set the font CGRAM address is 0100 0000.


The 1602 can store 8 custom characters (ie, 8 bytes of use). The first addresses of the 8 custom character storage spaces are: 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78.


When reading, the address of the custom character is 0X40-0X78 and the address is 00H-07H. One address (such as 00H) stores 1B character (1B = 8bit, one character consists of 8 0x**)


For 0x40, its storage space looks like this:


Lcd1602 user manual, explain the use of LCD1602


If 5*7 characters are used, then the data on the leftmost 3rd and last row is actually useless, usually set to 0.


Lcd1602 user manual, explain the use of LCD1602


So we get the data that each address needs to be written:


Address : Data


0x40 : 0x16


0x41 : 0x09


0x42 : 0x08 and so on. Write these 8 data to the corresponding address. (The red grid is 1 and the white grid is 0)