LCD Code error

Status
Not open for further replies.

Thread Starter

karthi keyan 9

Joined Apr 17, 2018
30
I am using pic16f877a development with in built LCD display. I just want to display the word.
Here i am attaching the code that was built successfully in MPLAB but still nothing is displaying.

C:
#include<pic.h>

#define EN RB4
#define RS RB5

__CONFIG (0xFF02);

void lcd_delay()
{
int i;
for(i=0;i<255;i++);
}
void lcd_data(unsigned char)
{
    EN=1;
    RS=0;
    lcd_delay();
    EN=0;  
}
void lcd_command(unsigned char)
{
    EN=1;
    RS=1;
    lcd_delay();
    EN=0;  
}
void display_string(const char *s)
    {
        while(*s)
        lcd_data(*s++);
        }
void lcd_Init()
{
    TRISB=0x00;
    PORTB=0x00;
    ADCON1=0x06;
    lcd_command(0X01); //Clear Dispaly
    lcd_delay();
    lcd_command(0x0C); //Display ON, Cursor OFF
    lcd_delay();
    lcd_command(0x80); // Force begin to first character
    lcd_delay();
    lcd_command(0X06); // Inc cursor, Shift cursor to right
    lcd_delay();
    lcd_command(0X28); // 4bit mode,2 lines, 5x7 matrix
    lcd_delay();
}
          
void main()
{
lcd_Init();
    while(1)
{
display_string("Hai");
//lcd_data("HEI");
lcd_delay();
}
}
Hope many experts are here some can help on this issue
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
12,347
In lcd_data and lcd_command, set the value of RS before pulsing EN.
[EDIT] If you are using 4 bit mode to drive the display then a special initialisation is needed. The one in your code will not work (at least not reliably).
 

Thread Starter

karthi keyan 9

Joined Apr 17, 2018
30
In lcd_data and lcd_command, set the value of RS before pulsing EN.
[EDIT] If you are using 4 bit mode to drive the display then a special initialisation is needed. The one in your code will not work (at least not reliably).
C:
#include<pic.h>

#define EN RB4
#define RS RB5

__CONFIG (0xFF02);

void lcd_delay()
{
int i;
for(i=0;i<255;i++);
}
void lcd_data(unsigned char)
{
EN=1;
RS=0;
lcd_delay();
EN=0;
}
void lcd_command(unsigned char)
{
EN=1;
RS=1;
lcd_delay();
EN=0;
}
void display_string(const char *s)
{
while(*s)
lcd_data(*s++);
}
void lcd_Init()
{
TRISB=0x00;
PORTB=0x00;
ADCON1=0x06;
lcd_command(0X01); //Clear Dispaly
lcd_delay();
lcd_command(0x0C); //Display ON, Cursor OFF
lcd_delay();
lcd_command(0x80); // Force begin to first character
lcd_delay();
lcd_command(0X06); // Inc cursor, Shift cursor to right
lcd_delay();
lcd_command(0X28); // 4bit mode,2 lines, 5x7 matrix
lcd_delay();
}

void main()
{
lcd_Init();
while(1)
{
display_string("Hai");
lcd_data("HEI");
lcd_delay();
}
Moderators note : please use code tags for pieces of code
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
12,347
There are a lot of things wrong with this code.
I will continue the discussion on your other thread 'LCD Interface code for pic16f877a'.
 
Status
Not open for further replies.
Top