The purpose of this experiment is to interface an LCD 2x16 characters (compatible with standard HD44780) to PIC16F628A in 4-bit mode. This means the data transfer will use just 4 pins of the microcontroller. No additional hardware configuration is required. In the current experiment we are displaying a text, on the 2 x16 LCD. The circuit diagram is presented below.
Circuit Diagram:
For those who want to build it on their own breadboard or other platform, here is the electronic scheme built in Eagle Cad, free version:
Software:
Here is the C program written for MikroC PRO for PIC 2010 (version v4.15).
/*
'*******************************************************************************
' Lesson nr.15:
' Alphanumeric LCD in 4-bit mode.
' Done by:
' Aureliu Raducu Macovei, 2010.
' Description:
' In this experiment we will work with alphanumeric LCD. Communication
' with LCD will be performed through 4-bits and connections is made as
' follows: D4 with RB0, D5 with RB1, D6 with RB2, D7 with RB3;
' RS with RB4 and EN with RB5.
' Test configuration:
' MCU: PIC16F628A
' Test.Board: WB-106 Breadboard 2420 dots
' SW: MikroC PRO for PIC 2010 (version v4.15)
' Configuration Word
' Oscillator: INTOSC:I/O on RA.6, I/O on RA.7
' Watchdog Timer: OFF
' Power up Timer: Disabled
' Master Clear Enable: Enabled
' Browun Out Detect: Enabled
' Low Voltage Program: Disabled
' Data EE Read Protect: Disabled
' Code Protect: OFF
'*******************************************************************************
*/
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
// Define Messages
char text1[] = "Testing LCD";
char text2[] = "using PIC16F628A";
char text3[] = "Test successful";
char text4[] = "in 4-bit mode";
void main() {
Lcd_Init(); // Initialize LCD
do {
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,text1); // Write message1 in 1st row
Lcd_Out(2,1,text2); // Write message1 in 2nd row
Delay_ms(3000); // delay 3s
Lcd_Cmd(_LCD_CLEAR); // Clear display
Delay_ms(1000); // delay 1s
Lcd_Out(1,2,text3); // Write message3 in 1st row
Lcd_Out(2,3,text4);
Delay_ms(3000); // delay 3s
} while(1);
}