EmbDev.net

Forum: µC & Digital Electronics 16x2 lcd help


von Ajay R. (ajay_r)


Rate this post
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..
1
#define F_CPU 1000000UL
2
3
#include <avr/io.h>
4
#include <util/delay.h>
5
6
#define LCD_DATA PORTB                //LCD data port
7
#define ctrl PORTD
8
#define en PD2                         // enable signal
9
#define rw PD1                       // read/write signal
10
#define rs PD0                     // register select signal
11
12
13
14
int main()
15
{
16
DDRB=0xff;                                  // setting the port B
17
DDRD=0x07;                                // setting for port D
18
init_LCD();                                 // initialization of LCD
19
_delay_ms(50);                        // delay of 50 mili seconds
20
LCD_write_string("“hello world”");                      // function to print string on LCD
21
return 0;
22
}
23
24
void init_LCD(void)
25
{
26
LCD_cmd(0x38);                            // initialization of 16X2 LCD in 8bit mode
27
_delay_ms(1);
28
LCD_cmd(0x01);                                 // clear LCD
29
_delay_ms(1);
30
LCD_cmd(0x0E);                        // cursor ON
31
_delay_ms(1);
32
LCD_cmd(0x80);                     // —8 go to first line and –0 is for 0th position
33
_delay_ms(1);
34
return;
35
}
36
37
void LCD_cmd(unsigned char cmd)
38
{
39
LCD_DATA=cmd;
40
ctrl =(0<<rs)|(0<<rw)|(1<<en);
41
_delay_ms(1);
42
ctrl =(0<<rs)|(0<<rw)|(0<<en);
43
_delay_ms(50);
44
return;
45
}
46
47
void LCD_write(unsigned char data)
48
{
49
LCD_DATA= data;
50
ctrl = (1<<rs)|(0<<rw)|(1<<en);
51
_delay_ms(1);
52
ctrl = (1<<rs)|(0<<rw)|(0<<en);
53
_delay_ms(50);
54
return ;
55
}
56
57
void LCD_write_string(unsigned char *str)             //store address value of the string in pointer *str
58
{
59
int i=0;
60
while(str[i]!='\0')                               // loop will go on till the NULL character in the string
61
{
62
LCD_write(str[i]);                            // sending data on LCD byte by byte
63
i++;
64
}
65
return;
66
}

:
von Henrik P. (henrik84)


Rate this post
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
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
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
useful
not useful
It's even possible the contrast is turned up too high.

von Jake_55 (Guest)


Rate this post
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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.