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.

Problem in lcd interfacing with pic16f877a

Status
Not open for further replies.

rangerskm

Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,663
Code:
// Program to interface 16x2 LCD and display single character using PIC18F4550 Microcontroller

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on
*/

//LCD Control pins
#include<pic.h>
#include<stdio.h>

#define rs RB0
#define rw RB1
#define en RB2

//LCD Data pins
#define lcdport PORTD

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

void Delay_ms(unsigned int msec)  // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}


void main(void)
{	
   // ADCON1=0X07;
	TRISB=0;		// Configure Port A as output port
	//PORTB=0;
	TRISD=0;		// Configure Port B as output port
	//PORTD=0;
	lcd_ini();		// LCD initialization
	lcddata('E');		// Print 'E'
	Delay_ms(10);
	lcdcmd(0x85);		// Position 1st Line, 6th Column
	lcddata('G');		// Print 'G'

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


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

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


I COMPILED THIS CODE IN MPLAB BY USING HI TECH C COMPILER.

THE CHARACTERS NOT DISPLAYING IN LCD .JUST BLANK .

CAN ANY ONE HELP ME IN THIS.
 

in command side just give these three commands 0x38,0x06,0x80 its enough to initialize lcd.. no more commands need to use in lcd initialisation
 

hi dude,

lcd back light is working fine

nothing display in lcd. i dont know the exact delay time

and tried with lot of initialization methods.

is there any problem with hardware.i connected by using wires to the lcd

- - - Updated - - -

hi vinoth ,

happy to get you,

i tried with many initialisation methods.dont know the problem.
 

94861d1376462416-prot.jpg

Hi I solved and I am posting the code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<htc.h>
 
#define rs RB0
#define rw RB1
#define en RB2
 
#define lcdport PORTD
 
#define _XTAL_FREQ 12000000 //Your frequency
 
void lcd_init();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned int i=0;
 
void Delay_ms(unsigned int msec)  // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
 
 
void main(void)
{   
    TRISB=0;        // Configure Port A as output port
    TRISD=0;        // Configure Port B as output port
    lcd_init();     // LCD initialization
    lcddata('E');       // Print 'E'
    __delay_ms(10);
    lcdcmd(0x85);       // Position 1st Line, 6th Column
    lcddata('G');       // Print 'G'
    while(1);
 
}
void lcd_init()
{   
    
    __delay_ms(100);
    lcdcmd(0x30);       // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    Delay_ms(15);
    lcdcmd(0x30);       // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    __delay_ms(1);
    lcdcmd(0x30);       // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    __delay_ms(10);
    lcdcmd(0x38);       // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    __delay_ms(10);
    lcdcmd(0x38);       // Configure the LCD in 8-bit mode, 2 line and 5x7 font
    __delay_ms(1);
    lcdcmd(0x0F);       // Display On and Cursor Off
    __delay_ms(1);
    lcdcmd(0x01);       // Clear display screen
    __delay_ms(1);
    lcdcmd(0x06);       // Increment cursor
    __delay_ms(1);
    lcdcmd(0x80);       // Set cursor position to 1st line, 1st column
    __delay_ms(1);
}
 
 
void lcdcmd(unsigned char cmdout)
{
    lcdport=cmdout;     //Send command to lcdport=PORTB
    rs=0;                       
    rw=0;
    en=1;
    __delay_ms(1);
    en=0;
}
 
void lcddata(unsigned char dataout)
{
    lcdport=dataout;    //Send data to lcdport=PORTB
    rs=1;
    rw=0;
    en=1;
    __delay_ms(1);
    en=0;
}



#define _XTAL_FREQ 12000000 //I did this for 12Mhz change it with your frequency for using __delay_ms(); it is in htc.h

- - - Updated - - -

Here is the project file....
 

Attachments

  • prot.jpg
    prot.jpg
    56.2 KB · Views: 126
  • lcd.7z
    33.3 KB · Views: 54
Last edited:

Try this code...
And instead of your for loop un known delay use a in built delay function and use 5 ms delay inside lcddata and lcdcmd functions...

Code:
// Program to interface 16x2 LCD and display single character using PIC18F4550 Microcontroller

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on
*/

//LCD Control pins
#include<pic.h>
#include<stdio.h>

#define rs RB0
#define rw RB1
#define en RB2

//LCD Data pins
#define lcdport PORTD

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

void Delay_ms(unsigned int msec)  // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}


void main(void)
{	

	TRISB=0;		// Configure Port A as output port
	TRISD=0;		// Configure Port B as output port
	lcd_ini();		// LCD initialization
	lcddata('E');		// Print 'E'
	Delay_ms(10);
	lcdcmd(0x85);		// Position 1st Line, 6th Column
	lcddata('G');		// Print 'G'

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


void lcdcmd(unsigned char cmdout)
{
	lcdport=cmdout;		//Send command to lcdport=PORTB
	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;
}
 
HI venkatesh

i removed the delay loop and use built in delay as you mentioned
i got the error when used the above code

this is the error code i got

HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1
Copyright (C) 1984-2009 HI-TECH SOFTWARE
(1273) Omniscient Code Generation not available in Lite mode (warning)
Warning [1355] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\LCD\lcd5.c; 40. inline delay argument too large
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 305. undefined symbol "?__delay"
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 313. undefined symbol "__delay"
 

HI venkatesh

i removed the delay loop and use built in delay as you mentioned
i got the error when used the above code

this is the error code i got

HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1
Copyright (C) 1984-2009 HI-TECH SOFTWARE
(1273) Omniscient Code Generation not available in Lite mode (warning)
Warning [1355] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\LCD\lcd5.c; 40. inline delay argument too large
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 305. undefined symbol "?__delay"
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 313. undefined symbol "__delay"

Just check for a built in library function that your compiler has for delay...
 

HI venkatesh

i removed the delay loop and use built in delay as you mentioned
i got the error when used the above code

this is the error code i got

HI-TECH C PRO for the PIC10/12/16 MCU family (Lite) V9.65PL1
Copyright (C) 1984-2009 HI-TECH SOFTWARE
(1273) Omniscient Code Generation not available in Lite mode (warning)
Warning [1355] E:\ece tutorials\ELECTRONICS SOFT LAB\lab set up programs\MY WORKS C\LCD\lcd5.c; 40. inline delay argument too large
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 305. undefined symbol "?__delay"
Error [800] C:\Users\sathish\AppData\Local\Temp\s4tg.; 313. undefined symbol "__delay"


in Lite mode You can use delay function upto 30ms so split the 100ms to 4 delay functions....
 
hi venkatesh

i am able to use in built delay function what may the reason .i am using HI TECH C compiler 9.65.it keeps on showing error
 

Hello,

Try to add a big delay before the Lcd_ini();
100mS or more..
LCD need some time after power ON...to be ready for ...
 

can any one provide exact delay loop for 1ms for an 20Mhz oscillator
 

venketesh

then i simulated the code that you given its working fine in isis .but when i connected in hardware its just showing black boxes.no text in it
 

Change the brightness .by changing the the resistance in the pre-set.
 
that i did bro, i changed my brightness many times.sometimes it showing full of boxes .but sometimes its showing nothing .i think it may be a hardware problem .i didnt solder the lcd with board.i just connected it with loose wires.so there may be a loose contacts between them .what you guys thinking ??
 

hi guys , finally i found the problem in the lcd.its because of the loose contact of the wires to the lcd from controller .i made the lcd soldered then its fine .now its displaying the text .:)

can you help me to display the letters in running manner....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top