[Solved] Problem with 16x2 LCD HD44780

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I've recently started my uC hobby. The first lessons were easy: blinking led, input, output and interruptions.

I got stuck however on interfacing a LCD display. This is what I am doing:

- I am sending commands from ATMEGA16 to the LCD in 8-bit mode

- I use PORTA for commands and two lowest bits of PORTB as RS and E lines. I've checked the wiring many, many times

- I have Vcc and contrast correctly connected, so I get on the LCD the upper row of black rectangles.

- I'm checking the state of output pins (PORTA, PORTB) with multimeter and they are exactly as I want them to be

The problem is that after sending 0x38 (make two lines), I'm getting TWO lines of black rectangles which I can't clear out. No matter what do I send, the two lines remain dark.

Is there something wrong in what I am doing or the device is broken?

There is my code:

int T=1000; // It is long enough to check pin state by multimeter or LED

//Function for sending commands to LCD
void lcd_cmd(unsigned char command){
  //Put command on the Data Bus
  PORTA = command;

  //Enable LCD for command writing
  PORTB = 0b00000010;

  //Allow delay for LCD to read the databus
  _delay_ms(T);

  //Disable LCD again
  PORTB = 0b00000000;

  //Allow some more delay
  _delay_ms(T);
}

void init_lcd(){

  _delay_ms(1000);

  lcd_cmd(0x30);
  lcd_cmd(0x30);
  lcd_cmd(0x30);

  //Setup both lines of LCD
  lcd_cmd(0x38);
  //Set Cursor off - Enable LCD
  lcd_cmd(0x0E);
  //Clear Screen
  lcd_cmd(0x01);
  //Goto first position
  lcd_cmd(0x80);
}


int main(void) {

  DDRA = 0xff;
  DDRB = 0xff;

  PORTA = 0x00;
  PORTB = 0x00;

  init_lcd();
}

Last Edited: Thu. May 2, 2013 - 10:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure why you'd write it from scratch when there are loads of tried/tested/proven libraries for HD44780. But if you are determined to go it alnoe at least use the minimal C code near the bottom of this page to prove your hardware setup:

http://www.johanekdahl.se/rwiki/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The dreaded black boxes are the display's idea of an error code. Likely it doesn't like the timing of your RS and CE lines, or your startup sequence. The startup sequence is not easy to figure out. Look at one of the many published libraries.

The largest known prime number: 282589933-1

In my humble opinion, I'm always right. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is there something wrong in what I am doing or the device is broken?
Let's start out with the easiest possible solution. You haven't mentioned the R/W line. Have you connected pin 5 of the LCD module to GND?

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  //Set Cursor off - Enable LCD
  lcd_cmd(0x0E); 

By the way, although this is not your problem wouldn't you be better off following the sequence recommended in the initialization flowchart? Don't forget to turn the device back on (with the above command) after the initialization sequence is complete.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int T=1000;
...
_delay_ms(T);

The parameter to _delay_ms() must be a constant known at compile time. The compiler >>MAY<< see that T is never changed, but I would not count on it.

But with a value of 1000 it will be 15 seconds before your initialization routine finishes. I would change the definition of T to:

#define T 1

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The problem is that after sending 0x38 (make two lines), I'm getting TWO lines of black rectangles

One line of black boxes means BAD initialisation.

Two lines of black boxes on your 16x2 LCD means that you have initialised correctly.

No, I have not read your code. But I do suggest that you adjust your contrast voltage. 0V to 0.5V is normal for a 5V VCC.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Quote:
I'm getting TWO lines of black rectangles

One line of black boxes means BAD initialisation.

Two lines of black boxes on your 16x2 LCD means that you have initialised correctly.
[...] I do suggest that you adjust your contrast voltage.


+1

10 or 20K pot. One end to VCC. Other end to GND. Wiper to contrast pin on LCD. Good setting is somewhere close to the GND end.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thankx a lot! I've changed my pot. for contrast voltage and now it works just fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh! You slew your black boxes with a pot. Mine went away when I noticed I was setting RS, then CS, then clearing RS.

You now earn the letters BBO (Black Box Overcomer).

The largest known prime number: 282589933-1

In my humble opinion, I'm always right.