Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD JHD162A interface wid pic 16F877

Status
Not open for further replies.

sastraster

Newbie level 3
Joined
Mar 28, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,317
I am using 16*2 LCD. I am using Hitech C compiler . I am trying to display some word. Sometimes it will display correctly sometimes it will not ..Sometimes some characters will be missing or it will display something else. I have tried to increase the delay.after each initialisation i am giving 5 sec as the delay just to cross check it. but even after tat i am facing the same problem. So kindly help me. I have attached the code also .


#include<htc.h>
#include<pic.h>
#define EN RC5 // 24
#define RS RC6 // 25
#define RW RC7 // 26
#define DB0 RB0
#define DB1 RB1
#define DB2 RB2
#define DB3 RB3
#define DB4 RB4
#define DB5 RB5
#define DB6 RB6
#define DB7 RB7
#define Data PORTB
char x;
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
char count=0;


void init_LCD()
{
TRISB=0x00;
TRISC=0x00;
RS=0;
RW=0;
Data=0x38;
EN=1;
asm("nop");
EN=0;
for(i=1;i<1000;i++)
{ __delay_ms(5);
}
RS=0;
RW=0;
Data=0x0f;
EN=1;
asm("nop");
EN=0;
for(i=1;i<1000;i++)
{ __delay_ms(5);
}

RS=0;
RW=0;
Data=0x06;
EN=1;
asm("nop");
EN=0;
for(i=1;i<1000;i++)
{ __delay_ms(5);
}


RS=0;
RW=0;
Data=0x01;
EN=1;
asm("nop");
EN=0;
for(i=1;i<1000;i++)
{ __delay_ms(5);
}

}


void display(char x)
{ RW=0;
RS=1;
Data=x;
EN=1;
asm("nop");
EN=0;
for(i=1;i<1000;i++)
{ __delay_ms(5);
}
}

void LCD_sendstring(unsigned char *var)
{
while(*var) //till string ends
display(*var++); //send characters one by one
}

void main()
{
unsigned char msg1[] ="Traffic Density";
for(int i=1;i<50;i++)
{
__delay_ms(1);
}

init_LCD();
RC0=~RC0;
LCD_sendstring(msg1);
while(1)
{
}

}
 

Hi,
what frequency you are running your PIC? From datasheet minimum pulse width for EN is 230ns or 450ns and data setup 80ns or 195 ns, so your EN = 1; asm("nop"); EN = 0; is not enough!
Minimum E cycle frequency is 1ms, so __delay_ms(1) between commands is enough. I also recommend place one NOP between RS and/or RW changes and E rising edge.
Your control signals on scope should be as pictures on page 4 of datasheet.
Regards
Pavel.
 

This is the proper initialization of LCD As per datasheet... But many people are not following this initialization... So can you try with this initialization.. I also sometime faced this kind of problem due to unproper initialization... But i am sure this is the problem... but you could try this one...
STEP1: Write Function set [0x38] into Command Register.. [8 bit interfacing, Multiple Line, 5x7 font size]
STEP2: Give 4ms delay
STEP3: Same Step 1
STEP4: Give 1ms delay
STEP5: Same Step 1
STEP6: Write the cursor/display shift [0x1C] into Command Register with delay... [Shift Entire display into right]
STEP7: Write Display ON/OFF control [0x0C] into Command Register with Delay... [No cursor and No blink]
STEP8: Write Entry mode set [0x06] into Command Register with Delay... [Increment without shift]
STEP9: Write Home cursor [0x02] into command register with Delay...[Home cursor]
STEP10: Write Clear display [0x01] into command register with delay... [Clear Display]
 

use capacitor(of any value) with your power supply. i think your power supply is not well regulated.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top