6.6 Example LCD Display Setup Program

An example C program is given here to show how the LCD can be set up. The connection of the LCD to the microcontroller is shown in Figure 6.9 (if you are using the EasyPIC 7 development board, all you have to do is just connect the LCD to the board). PORT B lower pins (RB0 to RB3) are connected to the upper 4 bits of the LCD (DB4 to DB7). In addition, RB4 and RB5 pins are connected to LCD RS and E pins, respectively.

Figure 6.9 Connecting the LCD to a PIC microcontroller


The program listing is shown in Figure 6.10. The following functions are used in the program:

Lcd_Initialise: This function initialises the LCD in 4-bit mode, as described earlier. The enable clock pulses are sent to the LCD by calling to function Toggle_E, which simply sets the E line to HIGH and then LOW. The 4-bit LCD commands are sent using function Lcd_Write_Cmd.
Lcd_Write_Cmd: This function receives a byte, separates it into two nibbles, sends the high nibble, followed by the low nibble. The E line is toggled after each output.
Lcd_Clear: This function clears the LCD and homes the cursor.
Lcd_Write_Char: This function sends a character to the LCD. The upper nibble is sent first, followed by the lower nibble. Line E is toggled between each output.
Toggle_E: This function toggles the E line by first sending a HIGH and then a LOW signal.

The LCD setup functions are ...

Get Using LEDs, LCDs and GLCDs in Microcontroller Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.