This topic shows a simple example for interfacing LCD display with HD44780 controller with PIC18F4550 microcontroller using CCS PIC C compiler.
In 4-bit mode there are 7 data lines between the PIC microcontroller and the LCD which are: RS, R/W, E, D4, D5, D6 and D7.
Interface PIC18F4550 with LCD circuit:
PIC18F4550 LCD example circuit schematic is shown below.
PIC18F4550 internal oscillator is used at 8MHz and MCLR pin function is disabled.
The button connected to RC0 used to increment a number displayed in the 2nd row as shown in the video below.
The PIC18F4550 microcontroller must be supplied with 5V (Pins VDD and VSS).
Hardware Required:
- PIC18F4550 microcontroller —> datasheet
- 1602 LCD screen
- Push button
- 10k ohm resistor
- 10k ohm variable resistor
- Bread board and some jumper wires
- PIC microcontroller programmer (PICkit 2, PICkit 3…)
Interfacing PIC18F4550 with LCD CCS C code:
The C code below was tested with CCS C compiler version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | // Interfacing PIC18F4550 with LCD display CCS C code // https://simple-circuit.com/ //LCD module connections #define LCD_RS_PIN PIN_D0 #define LCD_RW_PIN PIN_D1 #define LCD_ENABLE_PIN PIN_D2 #define LCD_DATA4 PIN_D3 #define LCD_DATA5 PIN_D4 #define LCD_DATA6 PIN_D5 #define LCD_DATA7 PIN_D6 //End LCD module connections #include <18F4550.h> #fuses NOMCLR INTRC_IO #use delay(clock=8000000) #include <lcd.c> char i; void main(){ setup_oscillator(OSC_8MHZ); // Setup internal oscillator @ 8MHz lcd_init(); // Initialize LCD module lcd_gotoxy(2, 1); // Go to column 2 row 1 lcd_putc("PIC18F4550"); lcd_gotoxy(1, 2); // Go to column 1 row 2 lcd_putc("LCD example"); for(i = 0; i < 2; i++){ // Shift display right 2 times delay_ms(200); lcd_send_byte(0,0x1E); } delay_ms(5000); for(i = 0; i < 14; i++){ // Shift display right 14 times delay_ms(200); lcd_send_byte(0,0x1E); } lcd_putc('f'); // LCD clear lcd_gotoxy(18, 1); // Go to column 18 row 1 lcd_putc("Hello world!"); lcd_gotoxy(17, 2); // Go to column 17 row 2 lcd_putc("Have a nice day"); for(i = 0; i < 15; i++){ // Shift display left 15 times delay_ms(200); lcd_send_byte(0,0x18); } delay_ms(5000); lcd_putc('f'); // LCD clear lcd_gotoxy(3, 1); // Go to column 3 row 1 lcd_putc("Hello world!"); i = 0; while(TRUE){ if(input(PIN_C0) == 0){ i++; if(i > 100) i = 0; lcd_gotoxy(7, 2); // Go to column 7 row 2 printf(lcd_putc,"%3u",i); // Write i with 3 numbers max delay_ms(200); } } } |
Interfacing PIC18F4550 with LCD video:
The following video shows the example in a hardware circuit.
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.