problem with lcd jhd162a interfacing to pic

Status
Not open for further replies.

sachin26

Newbie level 4
Joined
Feb 8, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
respected sir,
i m using 4-BIT mode PROGRAMMING for interfacing with LCD jhd 162A by PIC16F689.
here is my connections. coding is done in HITEC C..

/* RC7=LCD ENABLE
RC5=LCD RS
RC3=LCD DB7
RC2=LCD DB6
RC1=LCD DB5
RC0=LCD DB4
*/

my code:

#include<pic.h>
#include<htc.h>

#define LCD_EN 0x80
#define LCD_RS 0x20
#define _XTAL_FREQ 4000000

void lcd_reset()
{
SSPEN=0;
ANSEL=0X00;
ANSELH=0X00;
TRISC=0X00;
INTCON=0X00;
__delay_ms(40);
PORTC = 0x03+LCD_EN; /*FUNCTION SET,
8-BIT INTERFACE DATA LENGTH,
ENABLE LCD*/
PORTC = 0x03; /*FUNCTION SET,
8-BIT INTERFACE DATA LENGTH*/
__delay_ms(10); /* DELAY OF 10ms*/
PORTC = 0x03+LCD_EN;

PORTC = 0x03;
__delay_ms(1); /* DELAY OF 1ms*/
PORTC = 0x03+LCD_EN;
PORTC = 0x03;
__delay_ms(1); /* DELAY OF 1ms*/
PORTC = 0x02+LCD_EN; /*FUNCTION SET,
4-BIT INTERFACE DATA LENGTH*/
PORTC = 0x02;
__delay_ms(1); /* DELAY OF 1ms*/

}

void lcd_cmd (char cmd)
{
PORTC = ((cmd >> 4) & 0x0F)|LCD_EN; /*shift nibbles & mask lower nibble,
enable high */
__delay_us(50);
PORTC = ((cmd >> 4) & 0x0F);

__delay_us(200);
PORTC = (cmd & 0x0F)|LCD_EN;
__delay_us(50);
PORTC = (cmd & 0x0F);

__delay_us(200);
__delay_us(200);
}

void lcd_init ()
{
lcd_reset(); /* Call LCD reset */
lcd_cmd(0x28); /* 4-bit mode - 2 line - 5x7 font. */
lcd_cmd(0x08); // lcd display off
lcd_cmd(0x01); /*LCD CLEAR*/
lcd_cmd(0x0f); /* Display on,cursor on ,blink on.*/
lcd_cmd(0x06); /* Automatic Increment - No Display shift.*/
lcd_cmd(0x80); /* Address DDRAM with 0 offset 80h. */
}




void lcd_data (unsigned char * dat)
{
int i=0;
while((*(dat+i)!='\0'))
{
PORTC = (((*(dat+i) >> 4) & 0x0F)|LCD_EN|LCD_RS);
__delay_us(50);
PORTC = (((*(dat+i) >> 4) & 0x0F)|LCD_RS);

PORTC = ((*(dat+i) & 0x0F)|LCD_EN|LCD_RS);
__delay_us(50);
PORTC = ((*(dat+i) & 0x0F)|LCD_RS);
i++;
__delay_us(50);
__delay_us(50);
}
}

void main()
{
char *x = "SACHIN";
lcd_init();
while(1)
{
lcd_data((x));
}
}


my code is working perfectly... but there is nothing is displayed on LCD.. even contrast is also not varying..
please help me if something is getting wrong..
 

hai.. If you believe your code is working perfectly, then we can look into your circuit. Can you upload circuit?

before that, please search and read the threads. May be you could have done some minor mistake like others

https://www.edaboard.com/threads/233058/

Thanks
karthikkr
 


yp... my lcd is displaying now...

actually the problem was 1 of my pin of lcd is disconnected and another in cod

/*PORTC = (cmd & 0x0F)|LCD_EN;
__delay_us(50);
PORTC = (cmd & 0x0F);
*/
is not working... it should be like..

PORTC = ((cmd >> 4) & 0x0F);
RC7=1;
__delay_us(100);
RC7=0;

...

but still 1 problem is that my lcd jst showing output in 1 line.. although i have selected 2 lines in function set...
please.. if i m making some mistakes then help me...

thnks..
regards..
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…