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] LCD Interface with pic18f4550

Status
Not open for further replies.

pcsandhya82

Member level 3
Joined
Jul 31, 2010
Messages
58
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,732
Hi,

I m trying to do a simple LCD interface. controller is PIC18f4550, running on 20MHz crystal, LCD is JHD 162A, c18 compiler. Port B is used as data port, and port A as control. 10k pot for contrast setting of LCD. When I run the program, the first array of LCD lights up, and nothing else happens, no matter what command I have given. But the command voltages are available at LCD terminals.
Proteous simulation works fine.The code is as follows:

// Program to interface 16x2 LCD and display a single character using PIC18F4550

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


#include<p18f4550.h>
#include"delay.h"

#define rs LATAbits.LATA0
#define rw LATAbits.LATA1
#define en LATAbits.LATA2

#define lcdport LATB

void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned int i=0;


void lcd_ini()
{
	lcdcmd(0x38);		//16x2, 5x7matrix LCD.			
	lcdcmd(0x01);		//CLEAR DISPLAY AND DDRAM CONTENT	
	lcdcmd(0x06);		//ENTRY MODE	
	lcdcmd(0x0F);	       //DISPLAY ON, CURSOR BLINKING	
}

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

void lcddata(unsigned char dataout)
{
	lcdport=dataout;	//Send data to lcdport=PORTB
	rs=1;
	rw=0;
	en=1;
	DelayMs(10);
	en=0;
}

void main(void)
{
	TRISA=0;		// Configure Port A as output port
	LATA=0;
	TRISB=0;		// Configure Port B as output port
	LATB=0;
	lcd_ini();		// LCD initialization
	lcddata('H');		// Print 'H'
	DelayMs(1000);
	while(1);
}

As troubleshooting, I attempted the following:

1)To see if the config bits are wrong, I wrote an LED flashing program for port A. Tested with LED s connected to port A, it worked fine.
2) Checked if the controller actually outputs the commands in the ports. Tried sending only 0x38 to PORTA. The ascii value of 0x38 (00111000) was appearing on PORTA when I executed the program. Verified this with multimeter, 5v for 1's and 0v for 0's.
3)To see if there is a problem with the LCD, I tried with another LCD. Same result.

Proteous design attached. Could someone please help?
 

Attachments

  • led_rd0.rar
    14 KB · Views: 19
Last edited by a moderator:

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,165
Helped
161
Reputation
396
Reaction score
191
Trophy points
1,353
Location
India
Activity points
10,582
What I personally Feel is that,
By Default PORTA of PIC18F4550 is configured as Analog PORT
If you want to use the same configuration use it as Digital PORT,
Or Change LCD_Control Pins to some another port like PORTC or some thing else.


Use
ADCON1 = 0x0F;
//Configure PORT A for Digital Input Output
CMCON = 0x07;


This is the only Problem in your case
Hope this will asist you
Arun
 
Last edited:

min2max

Advanced Member level 4
Joined
Jul 12, 2011
Messages
104
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,308
Location
China
Activity points
2,209
Upon power on, 'the first array of LCD lighting up' is the default behavior of the LCD.

That means it has not yet been properly initialized or cleared.
 

nandhu015

Advanced Member level 5
Joined
Feb 11, 2006
Messages
1,965
Helped
300
Reputation
600
Reaction score
224
Trophy points
1,353
Location
India
Activity points
9,861
LCD Initialization needs proper timing.

I cant see delay between the commands.

Refer LCD datasheet for proper timings.
 

mahm150

Full Member level 1
Joined
Dec 14, 2010
Messages
98
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cairo, Egypt, Egypt
Activity points
2,001
i have problem in lcd but with sending value of variable.
i using mikroc program
int prev_time4_lectures,time4_lectures;
time4_lectures+=5;
IntToStr(time4_lectures, txt);
Lcd_Custom_Chr(1, 14,txt);
but not work
 

pcsandhya82

Member level 3
Joined
Jul 31, 2010
Messages
58
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,732
Hi Arun,

That precisely was the problem. Got it working now. Thanks a lot.:-D

---------- Post added at 04:20 ---------- Previous post was at 04:19 ----------

Hi,

The time delays are incorporated in the functions.
 

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,165
Helped
161
Reputation
396
Reaction score
191
Trophy points
1,353
Location
India
Activity points
10,582
Its Okay Sandhya...
Can you tell me which compiler are you using...
I am using Hi-Tech C Compiler

I think you are using PICC-18 Compiler...
Can you tell me some difference between these two...
 

candreg

Newbie level 1
Joined
Nov 5, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
Hi!

I tried this code but it gives it doesn't compile since it doesn't have the Delay_ms or delay_us function definitions. Any help with that would be greatly appreciate it.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top