Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD initialization problem with PIC

Status
Not open for further replies.

jab99407

Member
Hi all,
I’ve connected a LCD display 16x2 with PIC16F877A . I 've written code for 8 bit mode When i run the code, the LCD powers up, I see the top row of the LCD with all black square. I did continuity test with multimeter all connection looks okay. It proves there is problem with LCD initialization

C:
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ

#include <xc.h>

//LCD GND - to PIC GND
//LCD VCC - to PIC 5V
//LCD  CONT - to  POT

#define RS           RB1
#define RW           RB2
#define EN           RB3

#define LCD_Port     PORTD

/* Make all PORTD pins low and Configured PORT pins as Output*/
void  Port_Initialize (void)
{
   PORTA = 0;
   PORTB = 0;
   PORTC = 0;
   PORTD = 0;
   PORTE = 0;

   TRISA = 0b00000000;
   TRISB = 0b00000000;
   TRISC = 0b00000000;
   TRISD = 0b00000000;
   TRISE = 0b00000000;
}

/* Function to send command instruction to LCD */
void LCD_Command(unsigned char Command)
{
    LCD_Port = Command;
    RS=0;
    RW=0;
    EN=1;
    __delay_ms(2);
    EN=0;
}

/*LCD Initialize*/
void LCD_Initialize (void)
{
    __delay_ms(40); // wait 40 milliseconds
    LCD_Command(0x30);  // 8-bit interface data, 1-line display, 5 × 8 dot character font
    __delay_ms(5);
    LCD_Command(0x30);
    __delay_us(100);
    LCD_Command(0x30);
    __delay_us(40);
    LCD_Command(0x01); //Clears display
    __delay_us(40);
    LCD_Command(0x0F);  //display on, cursor on, cursor blink on
    __delay_us(40);
}


/*Function to send message to LCD */
void LCD_Data(unsigned char Message)
{
    LCD_Port = Message;
    RS=1;
    RW=0;
    EN=1;
   __delay_ms(2);
    EN=0;
}


void Messagebuffer( unsigned char *pointer)
{

    while (*pointer != '\0')
    {
      LCD_Data(*pointer);
  
        pointer++;
    }
}

void main(void)
{

  unsigned char string []= {"Project"};

  Port_Initialize ();
  LCD_Initialize ();

  Messagebuffer(string);

  while(1);

}

Display datasheet attached. Please help
 

Attachments

  • HD44780.pdf
    322.1 KB · Views: 185
You are missing a step in your LCD_Initialize ()

Function set 0x30, after three inits..

send 0x30 three times
then 0x30 ( or 0x20 for 4 bit )

Then set parmeters..
C:
void LCD_Initialize (void)
{
    __delay_ms(40); // wait 40 milliseconds
    LCD_Command(0x30);
    __delay_ms(5);
    LCD_Command(0x30);
    __delay_us(100);
    LCD_Command(0x30);
    __delay_us(40);
   LCD_Command(0x30);  // 8-bit interface data, 1-line display, 5 × 8 dot character font
    __delay_us(40);
    LCD_Command(0x01); //Clears display
    __delay_us(40);
    LCD_Command(0x0F);  //display on, cursor on, cursor blink on
    __delay_us(40);
}

I would add cursor to increment as well... Personal requirement though..
 
You are missing a step in your LCD_Initialize ()

Function set 0x30, after three inits..

send 0x30 three times
then 0x30 ( or 0x20 for 4 bit )

I would add cursor to increment as well... Personal requirement though..

I tried this way but still black square shows on display. don't see "Project" on display
 
Status
Not open for further replies.

Latest threads

Back
Top