EmbDev.net

Forum: µC & Digital Electronics 16x2 lcd help


von Ajay R. (ajay_r)


Rate this post
0 useful
not useful
Hey,I was working on atmega 8 and tried to use a 16x2lcd with it but lcd 
is only showing blocks and nothing else. I want to know whether 
something is wrong with my code or with my connections.Here is my code..
#define F_CPU 1000000UL

#include <avr/io.h>
#include <util/delay.h>

#define LCD_DATA PORTB                //LCD data port
#define ctrl PORTD
#define en PD2                         // enable signal
#define rw PD1                       // read/write signal
#define rs PD0                     // register select signal



int main()
{
DDRB=0xff;                                  // setting the port B
DDRD=0x07;                                // setting for port D
init_LCD();                                 // initialization of LCD
_delay_ms(50);                        // delay of 50 mili seconds
LCD_write_string("“hello world”");                      // function to print string on LCD
return 0;
}

void init_LCD(void)
{
LCD_cmd(0x38);                            // initialization of 16X2 LCD in 8bit mode
_delay_ms(1);
LCD_cmd(0x01);                                 // clear LCD
_delay_ms(1);
LCD_cmd(0x0E);                        // cursor ON
_delay_ms(1);
LCD_cmd(0x80);                     // —8 go to first line and –0 is for 0th position
_delay_ms(1);
return;
}

void LCD_cmd(unsigned char cmd)
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}

void LCD_write(unsigned char data)
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}

void LCD_write_string(unsigned char *str)             //store address value of the string in pointer *str
{
int i=0;
while(str[i]!='\0')                               // loop will go on till the NULL character in the string
{
LCD_write(str[i]);                            // sending data on LCD byte by byte
i++;
}
return;
}

:
von Henrik P. (henrik84)


Rate this post
0 useful
not useful
Hi,

a Datasheet of the display module would really help.
I can only guess, maybe the contrast isn't set correctly.

Regards

von Guest (Guest)


Rate this post
0 useful
not useful
RTFM regarding correct initialization. If in doubt use the Fleury 
LCD-lib. Reinventing the wheel sometimes is a PITA.

Which type of LCD are you using? They pretend to be compatible but not 
all are. What kind of connection between CPU and LCD? One row of black 
boxes or two? Have you tried adjusting the contrast voltage?

von Steve (Guest)


Rate this post
0 useful
not useful
What kind of controller does this display use? HD44780(-compatible)?

Ajay R. wrote:
[...]
> init_LCD();                           // initialization of LCD
> _delay_ms(50);                        // delay of 50 mili seconds
[...]

I think the delay has to be before the initialization of the display, 
just after the power was applied.

Steve

von cprog (Guest)


Rate this post
0 useful
not useful
It's even possible the contrast is turned up too high.

von Jake_55 (Guest)


Rate this post
0 useful
not useful
I actually got the circut to work using the code! :D
I havent changed the code in any way and build the circut as you 
configured in the code.

But thanks for the code I got mine working now :D

-Jake

Only registered users may reply in this topic. Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Facebook account
No account? Register here.