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.

[SOLVED] problem with lcd interfacing with pic18f4550

Status
Not open for further replies.

project1

Junior Member level 1
Joined
Feb 15, 2012
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,379
hello,

I am trying to interface a JHD162A LCD to pic18f4550. Its only showing a row of black boxes. Can someone pls help me out with this. I have given the code below. I'm using microchip C18 compiler with MPLAB.

Code:
#include<p18f4550.h>
#include<delays.h>

#pragma config FOSC = HS

#pragma config WDT = OFF

#pragma config PWRT = OFF

#pragma config CP0 = OFF

#pragma config PBADEN = OFF

//LCD Control pins
#define rs LATAbits.LATA0
#define rw LATAbits.LATA1
#define en LATAbits.LATA2

//LCD Data pins
#define lcdport LATB


void dis_cmd(unsigned char);
void dis_data(unsigned char);
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void lcd_ini(void);

void main(void)
{
	unsigned char data0[]="Hello";
	unsigned int i=0;
	TRISB=0;			// Configure Port B as output port
	LATB=0;
	TRISA = 0;
	LATA = 0;
	lcd_ini();			// LCD initialization
	while(data0[i]!='\0')
	{
		dis_data(data0[i]);
		Delay10KTCYx(400);		//Delay_ms(800);
		i++;
	}
}
void lcd_ini()	                    
{
	dis_cmd(0x02);		// To initialize LCD in 4-bit mode.
	dis_cmd(0x28);		// To initialize LCD in 2 lines, 5x7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
	dis_cmd(0x80);
}

void dis_cmd(unsigned char cmd_value)
{
	unsigned char cmd_value1;
	cmd_value1 = (cmd_value & 0xF0);	// Mask lower nibble because RB4-RB7 pins are being used
	lcdcmd(cmd_value1);			// Send to LCD
	cmd_value1 = ((cmd_value<<4) & 0xF0);	// Shift 4-bit and mask
	lcdcmd(cmd_value1);			// Send to LCD
}


void dis_data(unsigned char data_value)
{
	unsigned char data_value1;
	data_value1=(data_value&0xF0);
	lcddata(data_value1);
	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}

void lcdcmd(unsigned char cmdout)
{
	lcdport=cmdout;		//Send command to lcdport=PORTB
	rs=0;						
	rw=0;
	en=1;
	Delay10KTCYx(25);	//Delay_ms(50);
	en=0;
}

void lcddata(unsigned char dataout)
{
	lcdport=dataout;	//Send data to lcdport=PORTB
	rs=1;
	rw=0;
	en=1;
	Delay10KTCYx(25);	//Delay_ms(50);
	en=0;
}
 

You need delays when enable is low
Code:
        rs=0;						
	rw=0;
	en=1;
	Delay10KTCYx(1);	//small delay
	en=0;
	Delay10KTCYx(25);	//Delay_ms(50);
 

I just added the delays in lcdcmd() and lcddata() functions. It still didnt work.
 

I added a delay of 100ms and tried.

Code:
void main(void)
{
	unsigned char data0[]="Hello";
	unsigned int i=0;
	TRISB=0;			// Configure Port B as output port
	LATB=0;
	TRISA = 0;
	LATA = 0;
	Delay10KTCYx(50);	//Delay_ms(100);
	lcd_ini();			// LCD initialization
	while(data0[i]!='\0')
	{
		dis_data(data0[i]);
		Delay10KTCYx(400);		//Delay_ms(800);
		i++;
	}
}

I went through the other thread. I checked the connections once again with the multimeter. The lcd is receiving 5V and I'm not driving anything else. The supply is given only to the microcontroller and to the lcd.
 

You not have the correct initialization routine, look on **broken link removed**at page 10
 

I changed the lcd initialization function as follows but still same problem.

Code:
void lcd_ini()	                    
{
	Delay10KTCYx(10);	//Delay_ms(20)
	dis_cmd(0x30);
	Delay10KTCYx(5);	//Delay_ms(10)
	dis_cmd(0x30);
	Delay1KTCYx(1);		//Delay_us(200)
	dis_cmd(0x30);
	dis_cmd(0x28);		// To initialize LCD in 2 lines, 5x7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
}
 

Before setting interface to 4 bits you should use lcd_cmd function that write just one nibble:


Code:
void lcd_ini()	                    
{
	Delay10KTCYx(10);	//Delay_ms(20)
	lcd_cmd(0x03);
	Delay10KTCYx(5);	//Delay_ms(10)
	lcd_cmd(0x03);
	Delay1KTCYx(1);		//Delay_us(200)
	lcd_cmd(0x03);

	lcd_cmd(0x02);           //Function set

	dis_cmd(0x28);		// To initialize LCD in 2 lines, 5x7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
}
 
Hi,

I tried using the code you suggested. But still its the same problem.
 

Try the following code (lcdport uses only high nibble, so you should have the command prepared for this)

Code:
void lcd_ini()	                    
{
	Delay10KTCYx(10);	//Delay_ms(20)
	lcd_cmd(0x30);
	Delay10KTCYx(5);	//Delay_ms(10)
	lcd_cmd(0x30);
	Delay1KTCYx(1);		//Delay_us(200)
	lcd_cmd(0x30);

	lcd_cmd(0x20);           //Function set

	dis_cmd(0x28);		// To initialize LCD in 2 lines, 5x7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
}
 
hello,

I am trying to interface a JHD162A LCD to pic18f4550. Its only showing a row of black boxes. Can someone pls help me out with this. I have given the code below. I'm using microchip C18 compiler with MPLAB.

Code:
void dis_cmd(unsigned char cmd_value)
{
	unsigned char cmd_value1;
	cmd_value1 = (cmd_value & 0xF0);	// Mask lower nibble because RB4-RB7 pins are being used
	lcdcmd(cmd_value1);			// Send to LCD
	cmd_value1 = ((cmd_value<<4) & 0xF0);	// Shift 4-bit and mask
	lcdcmd(cmd_value1);			// Send to LCD
}


void dis_data(unsigned char data_value)
{
	unsigned char data_value1;
	data_value1=(data_value&0xF0);
	lcddata(data_value1);
	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}

I think you should check these two functions. How the 4 wires are connected to the port? (high nibble or low nibble connection?)
 

it finally worked.

cristianp - thanks a lot for all your help. the lcd keeps displaying hello more than a single time. will try to figure that out. atleast its displaying something.

papunblg - the wires are connected to the high nibble.
 

.... the lcd keeps displaying hello more than a single time. will try to figure that out. atleast its displaying something.

You not have main loop, so your program will execute periodically. Add a dummy while loop at the end of your code:


Code:
	while(data0[i]!='\0')
	{
		dis_data(data0[i]);
		Delay10KTCYx(400);		//Delay_ms(800);
		i++;
	}

        while (1);
 
@Project1

I am also working on the same project........

can u post me the code because I am unable to print the characters.........................


Thanking u..............
 

the code is there in the previous posts
 

Thanku for the reply................

Even i am using the same code.............previously

But the problem is when i am sending dis_cmd(0x28); for selecting two lines of the LCD, but it is showing only single line, and I saw that we have to send the dis_cmd(0x20) command as dis_cmd(0x02) instead. As a part of testing I tested entire connections and continuity of the circuit. Everything is fine..But the data I am sending is not displayed on the screen...........

I dont know what is the problem of the circuit at all..................
 

u have to give dis_cmd(0x20) only. it worked for me.
 

K. Thanku . I am getting the data on the display along with some garbage values which are displaying on the screen. may be I have to clear the data I sent after writing.....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top