EmbDev.net

Forum: µC & Digital Electronics 16x2 lcd help


Author: Ajay R. (ajay_r)
Posted on:

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;
}

Author: Henrik P. (henrik84)
Posted on:

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

Author: Guest (Guest)
Posted on:

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?

Author: Steve (Guest)
Posted on:

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

Author: cprog (Guest)
Posted on:

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

Author: Jake_55 (Guest)
Posted on:

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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.