#define LCD_CURSOR_BLINK 0x0F // curson keeps blinking #define LCD_CURSOR_ON 0x0E // turns on cursor display #define LCD_CURSOR_OFF 0x0C // stops display curson on screen #define LCD_PAN_RIGHT 0x1C // used to scroll text right side to scroll text #define LCD_PAN_LEFT 0x18 // used to scroll text left side to scroll text
#define LCD_CURSOR_FWD 0x14 //moves curson one position forward #define LCD_CURSOR_BACK 0x10 // moves curson one position back #define LCD_HOME 0x02 // set the cursor to first line and first row #define LCD_CLEAR 0x01 // It clears everythings Command set for Hitachi 44780U LCD display controller We use #define directives to define commands that are used for various control functions of the 16×2 display.
I will show you how to assign pins for LCD in the next section. To do this, we need to change the pin assignment inside the code.
Although, you can use see code with other Pic microcontrollers also.Īs we mentioned earlier, we can use the 8-bit mode and 4-bit mode interfacing. In this section, we will see how to write example code for 16×2 LCD interfacing with PIC18F4550 microcontroller. LCD Interfacing Programming MPLAB XC8 Compiler
In the contrary, MikroC Pro provides libraries for all modules such as LCD, Keypad, ADC Module, UART module. Because the XC8 compiler does not provide built-in libraries. In the case of MPLAB XC8, we will develop our own LCD library. For MikroC Pro for PIC, we will use the PIC16F877A microcontroller. In this tutorial, we will use two pic microcontroller compilers for programming:įor MPLAB XC8 Compiler, we will use the PIC18F4550 microcontroller. PIC Microcontroller LCD Interfacing Programming This contrast register makes adjust to the voltage applied on the VEE pin. Therefore, if you are not able to see anything on LCD after programming, the maximum changes are that you need to adjust contrast with the variable resistor. However, it doesn’t make any major difference.Ī variable resistor is used to adjust the contrast of 5×8 dot pixels according to background light. The only difference between 4-bit and 8-bit is that data transfer speed is faster for 8-bit mode. Therefore, it is recommended to use 4-bit mode interfacing. On the other hand, if we use 4-bit mode, we need only 6 GPIO pins.
So It is recommended to use LCD in four bits mode to save pins of the microcontroller for other applications.Īs you can see in this diagram, if we use 8-bit mode interfacing, we will need to use 11 pins of pic microcontroller. In this tutorial, we have used the 4-bit mode which uses only 4 data lines, thus saving pins of the microcontroller. It can work in two modes, 4-bit and 8-bit. Its pin configuration is given as follows: Pin Number Name Use 1 Vss Ground 2 Vdd Power 3 Vee To adjust the contrast 4 RS 1=Data inputĠ=Instruction input 5 R/W 1=Read from LCDĠ=Write to LCD 6 Enable (EN) From 1 to 0 = Data is written to the LCD 7 DB0 Data Bus Lines 8 DB1 9 DB2 10 DB3 11 DB4 12 DB5 13 DB6 14 DB7 15 LED+ Backlight 16 LED- How to interface/Connect LCD with PIC Microcontroller LED+ and LED- pins are used to control the backlight LED. There are 8 data pins from D0-D7 and three control pins such as RS, RW, and E. Now let’s first understand the pinout diagram and commands of 16×2 Liquid Crystal display.
Because we send control and data signals to LCD through these I/O pins. GPIO pins are general-purpose input-output pins. Applications How to Interface 16X2 LCD with PIC Microcontroller?įirst of all, to interface LCD with a pic microcontroller, we used GPIO pins.LCD Connections with pic microcontroller.LCD Interfacing with PIC16F877A MikroC Pro.LCD Display Commands in Mikro c for pic.LCD Interfacing Code MPLAB XC8 Compiler.LCD Interfacing Programming MPLAB XC8 Compiler.PIC Microcontroller LCD Interfacing Programming.How to interface/Connect LCD with PIC Microcontroller.How to Interface 16X2 LCD with PIC Microcontroller?.