Menu

all about electronic and microcontrollers

Sunday, October 17, 2010

Lesson nr.15-Alphanumeric LCD in 4-bit mode

Hardware setup:
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);
}

9 comments:

  1. I connected everything like on shematics. I made hex file after succesfull build in mikroC and burned it on pic16f628a... but all I get is black boxes in first row of my lcd. :(

    ReplyDelete
  2. Hello,
    you're sure 100% that the ​​electronic scheme made by you is good?,
    I have tested the software and it works very well,you set the configuration words? when you start the mikroC PRO for pic software.
    Keep me informed.

    ReplyDelete
  3. I checked my connections twice, I suspect my LCD might be damaged.
    Can you check my hex file? http://speedy.sh/nYmUr/lcd-electronicsexperiments.HEX

    ReplyDelete
  4. Did you find some time to check my hex file on your project?

    ReplyDelete
  5. Ok I found out the possible reason why its not working for me.. my display is not 16x2.. its 20x2. What modification in code is needed to adopt it to 20x2 display?

    ReplyDelete
  6. Even so, it should work if your display uses the standard HD44780.
    Can you share some pictures of your work?

    ReplyDelete
  7. how If i want to put a push button??when we push the button, it will display..how??can u help me??=D

    ReplyDelete
  8. What if i wanned to connect lcd with porta

    ReplyDelete

If you do not understand something, or if you make some aplication helped by this blog, let me know.