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 interface for PIC18F4550 problem

Status
Not open for further replies.

pranavm1502

Newbie level 6
Joined
Jun 18, 2012
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Activity points
1,364
Hi,
I am having problem getting LCD work with this code:
Code:
// Program to display text on 16x2 LCD using PIC18F4550 Microcontroller

#include <p18f4550.h>



//LCD Control pins
#define rs LATEbits.LATE0
#define rw LATEbits.LATE1
#define en LATEbits.LATE2

//LCD Data pins
#define lcdport LATD

void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char data[20]="CheckThisOut";
unsigned int i=0;


void lcd_ini()
{
	lcdcmd(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	lcdcmd(0x0C);		// Display On and Cursor Off
	lcdcmd(0x01);		// Clear display screen
	lcdcmd(0x06);		// Increment cursor
	lcdcmd(0x80);		// Set cursor position to 1st line, 1st column
}

void Delay_ms(int n)
{
	int i,j;
	for(i=0;i<n;i++)
		for(j=0;j<760;j++);
}

void lcdcmd(unsigned char cmdout)
{
	lcdport=cmdout;		//Send command to lcdport=PORTD
	rs=0;						
	rw=0;
	en=1;
	Delay_ms(10);
	en=0;
}

void lcddata(unsigned char dataout)
{
	lcdport=dataout;	//Send data to lcdport=PORTB
	rs=1;
	rw=0;
	en=1;
	Delay_ms(10);
	en=0;
}
void main(void)
{
	ADCON1=0x0F;
	TRISE=0;		// Configure Port E as output port
	LATE=0;
	TRISD=0;		// Configure Port D as output port
	LATD=0;
	lcd_ini();		// LCD initialization
	while(data[i]!='\0')
	{
		lcddata(data[i]);	// Call lcddata function to send characters
					// one by one from "data" array
		i++;
		Delay_ms(300);
	}

}
 

I don't know C but from what I understand of it you have not initialized the LCD correctly. To initialize the LCD properly you should send 30H to the LCD wait more than 4.1mS then send 30H again twice more with a minimum gap between instructions of 100uS.

Although you have a delay of 10mS in the send data to LCD portb routine it does not need to be so long where you have put it and you should put another delay (of 10mS will do) after returning en=0.

It is also a good idea to have a delay of 100mS before you try to program the LCD after power up.
 

I have no experience in writing program in C18 compiler. But i know how to program. Where did you initialize the oscillator frequency??? Please include the cystal frequency, it must work.
 

added
Code:
#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS
but still its not working. is there any other register which I should set (eg. CMCON1) for using PORTE/D?

- - - Updated - - -

I don't know C but from what I understand of it you have not initialized the LCD correctly. To initialize the LCD properly you should send 30H to the LCD wait more than 4.1mS then send 30H again twice more with a minimum gap between instructions of 100uS.

Although you have a delay of 10mS in the send data to LCD portb routine it does not need to be so long where you have put it and you should put another delay (of 10mS will do) after returning en=0.

It is also a good idea to have a delay of 100mS before you try to program the LCD after power up.

changed lcd_ini() as follows:
Code:
void lcd_ini()
{
	lcdcmd(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	Delay_ms(5);
	lcdcmd(0x38);
	Delay_ms(1);
	lcdcmd(0x38);
	lcdcmd(0x0C);		// Display On and Cursor Off
	lcdcmd(0x01);		// Clear display screen
	lcdcmd(0x06);		// Increment cursor
	lcdcmd(0x80);		// Set cursor position to 1st line, 1st column
}

still not working :(
 

Try this..
HTML:
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = OFF
#pragma config OSC=HS
#define _XTAL_FREQ 20000000   // Change the frequency, according to your hardware
 

added
Code:

#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2
#pragma config FOSC = HSPLL_HS

but still its not working. is there any other register which I should set (eg. CMCON1) for using PORTE/D?

Don't forget as mentioned in the previous post to turn the watchdog timer to off.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top