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.

4bit lcd not working with pic18f452

Status
Not open for further replies.

cheenu02

Junior Member level 3
Joined
Jun 16, 2011
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,500
hi,
I am practicing sending the data to LCD using four pins.I am not able to get the output.Please help me.
This is my code

#include<18f452.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay(clock=4000000)
#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2

//data pins D0,D1,D2,D3

void lcd_command(int8 command)
{
int8 temp;
temp=(command>>4) & 0x0f; //mask lower nibble
output_d(temp); //send higher nibble
delay_ms(5);
output_low(rs);

output_high(en);
delay_cycles(2);
output_low(en);

output_d(0x00);

temp=command & 0x0f; //mask higher nibble
output_d(temp); //send lower nibble
delay_ms(5);
output_low(rs);

output_high(en);
delay_cycles(2);
output_low(en);

output_d(0x00);

delay_ms(10);
delay_ms(250);

}
void lcd_data(int8 data)
{
int8 temp;
temp=(data>>4) & 0x0f; //mask lower nibble
output_d(temp); //send higher nibble
delay_ms(5);
output_high(rs);

output_high(en);
delay_cycles(1);
output_low(en);

output_d(0x00);

temp=data & 0x0f; //mask higher nibble
output_d(temp); //send lower nibble
delay_ms(5);
output_high(rs);

output_high(en);
delay_cycles(1);
output_low(en);

output_d(0x00);

delay_ms(10);
delay_ms(250);

}

void main()
{

set_tris_d(0xf0);
set_tris_c(0);
while(1)
{
lcd_command(0x28);
lcd_command(0x0e);
lcd_command(0x06);
lcd_command(0x80);

lcd_data('a');
lcd_data('b');
lcd_data('c');
lcd_data('d');
}
}

Thank you.
 

You need some sequence to initialize the lcd and provide the delay required :)

"In 4-bit mode the data is sent in nibbles, first we send the higher nibble and then the lower nibble. To enable the 4-bit mode of LCD, we need to follow special sequence of initialization that tells the LCD controller that user has selected 4-bit mode of operation. We call this special sequence as resetting the LCD. Following is the reset sequence of LCD.

Wait for abour 20mS
Send the first init value (0x30)
Wait for about 10mS
Send second init value (0x30)
Wait for about 1mS
Send third init value (0x30)
Wait for 1mS
Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)
Wait for 1mS


The busy flag will only be valid after the above reset sequence. Usually we do not use busy flag in 4-bit mode as we have to write code for reading two nibbles from the LCD. Instead we simply put a certain ammount of delay usually 300 to 600uS. This delay might vary depending on the LCD you are using, as you might have a different crystal frequency on which LCD controller is running. So it actually depends on the LCD module you are using. So if you feel any problem running the LCD, simply try to increase the delay. This usually works. For me about 400uS works perfect.
"
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top