Here we are discussing various aspects of 16*2 Character LCD Interfacing with PIC Microcontroller in 8-bit Mode. A character LCD is the most basic form of an electronic display device which is widely used. The module will consist of 2 rows each with 16 columns which can display 16 characters. Already discuss LCD in4-bit mode in the chapter 4-bit LCD interfacing with pic microcontroller
Character LCD
Several other LCD modules are also available like 20×4 dimension LCD which can display 20 characters per line and 4 such lines would be available. The choice for the module depends on the requirement.
The main advantage of using a character LCD instead of a seven segment display and other multi-segment LEDs is that there is no limitation in displaying special & custom characters animations and so on. All character LCDs will have 16 pins among which 8 are data pins through which data or commands are passed into the LCD registers. A character LCD can be configured in 8 bit or 4-bit mode in which 8 data pins and 4 data pins are used respectively. This feature allows efficient use of the digital I/0 pins of the microcontroller.
Features
The features of a character LCD module make it more suitable as an electronic display than 7 segment displays and other multi-segment display modules. Most importantly the module can be interfaced much easily unlike other modules with no complexity in both hardware and software. The 4-bit mode interfacing of the LCD module enables an efficient method of saving the number of general purposes I/O pins which is a major criterion for an embedded system designer. There is no limitation in characters which can be displayed using the module. The contrast of the module can be adjusted using the VEE pin of the module and LED backlight which makes the display more bright can be enabled with LED+ and LED- pin.
Register
A Character LCD consists of two registers
- Command register
- Data register
The RS (Register Select) pin of the LCD module is used to select the specific register. When RS is low, the command register is selected and when RS is high, data register is selected. State of R/W pin determines the operation to be performed whether to read or write data.
All instructions to be executed by the LCD are latched into the command register of the LCD. LCD commands include a clear display, the cursor on/off, display shift and so on.
Character to be displayed on the LCD is stored in the data register. The data is stored temporarily in the data register.
Commands
Commands are instructions given to the LCD module to perform a predefined task. The task to be performed is defined by the manufacturer. Some of the LCD commands are listed below.
- Clear display – 0x01
- Display on, cursor off – 0x0C
- Increment cursor – 0x04
The rest of the commands can be obtained from the device datasheet.
Sending the commands
The register select pin of the LCD module should be connected to a general purpose I/O pin and the corresponding pin should be made low. R/W pin should be grounded to select the write operation. The command register will not be accessed.
Enabling the LCD would latch in the value of the data port into the command register of the module. Enabling the module involves applying a high to low pulse to the Enable pin of LCD.
Example firmware:
void LCD_command(unsigned char command) { RS=0;R/W=0; Data_PORT=command; Enable_pin=1; delay_ms(5); Enable_pin=0; }
RS, R/W, Data_PORT, and Enable_pin should be macro defined in the firmware.
Example:
Sending data
Data write operation involves the similar steps as that of a command write operation except data register should be selected by setting the RS pin and grounding the R/W pin. Enabling the module would then latch in the value in the data port to the data register of the module and corresponding character will be displayed on the LCD module.
Example firmware:
RS, R/W, Data_PORT, Enable_pin should be macro defined in the firmware.
Initializing The LCD
First of all, it needs to be initialized before writing data into the character LCD. The initialization is done to configure the module for the specific use. It involves writing some initialization commands into the command register. Some of the initialization commands include a command to turn the display on and cursor off, the command to set cursor at the preferred position and the command to set the option for cursor increment or decrement and so on.
Ex:
void lcd_init(void) { CTRL_PORT_DIR = 0x00; /* Direction of control port as Output */ DATA_PORT_DIR = 0x00; /* Direction of data port as Output */ LCD_command(0x38); /* LCD command - 5x7 matrix */ LCD_command(0x80); /* LCD command - Force cursor to the bigining of first line */ LCD_command(0x0C); /* LCD command - Display ON, cursor OFF */ LCD_command(0x01); /* LCD command - Clear display */ }
The user can also display custom characters on LCD. More Details of displaying of custom character on LCD is specified in the Chapter Display Custom Character on 16*2 LCD using PIC microcontroller