LCD display problem

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
Hi,
I(a newbie) am trying to display a character on LCD.Instead black boxes are displayed on the first row; the second row remaining empty. I am sure trouble does not lie in the connections.
Kindly check out my code:
Rich (BB code):
#include<avr/io.h>
#include<util/delay.h>
#define PIN_RS PINB0
#define PIN_RW PINB1
#define PIN_ENABLE PINB2
#define LCD_CONTROL_DIR DDRB
#define LCD_CONTROL_PIN  PORTB //ports for DB0 to DB7
void enable();// to make negative edge
void check_busy();//to check busy flag
void address_ddram(char);// to giv memory address of ddram
void Display(char);// to display character on lcd
main()
{
  DDRD =0xFF;//setting PORTD as output
  LCD_CONTROL_DIR |=(1<<PIN_RS)|(1<<PIN_RW)|(1<<PIN_ENABLE);//setting port R/S RW output
  check_busy();
  address_ddram(0x0);
  check_busy();
  Display(0x31);
  while(1);
}
void enable()
{
  LCD_CONTROL_PIN |=(1<<PIN_ENABLE);/* negative eedge transition for data transfer
  but data is read after negative edge and remains avaliable till enable is high*/
 asm volatile("nop");
 asm volatile("nop");
  LCD_CONTROL_PIN &=~(1<<PIN_ENABLE);
}

void check_busy()
{
 LCD_CONTROL_PIN |=1<<PIN_RW;//read
 LCD_CONTROL_PIN &=~(1<<PIN_RS);//instruction
 enable();
 LCD_CONTROL_PIN |=(1<<PIN_ENABLE);//raise Enable to read data
 while(PORTD >=0x80);//wait till db7 is 1
}

void address_ddram(char address)
{
  LCD_CONTROL_PIN &=~(1<<PIN_RW);//WRITE
  //instruction is enabled in check_busy() function
  PORTD |=(1<<PIN7);
  enable();
  check_busy();
  LCD_CONTROL_PIN &=~(1<<PIN_RW);//WRITE
  //instruction is enabled in check_busy() function
  PORTD =address;
  enable();
}

void Display( char character)
{
  LCD_CONTROL_PIN &=~(1<<PIN_RW);//WRITE
  LCD_CONTROL_PIN |=1<<PIN_RS;//DATA
  PORTD = character;
  enable();
}
 

ErnieM

Joined Apr 24, 2011
8,377
Hi,
I(a newbie) am trying to display a character on LCD.Instead black boxes are displayed on the first row; the second row remaining empty. I am sure trouble does not lie in the connections.
You can only be sure of the connections by checking each and every one of them, preferable by single stepping thru some test code to test exactly that.

Alphanumeric displays init themselves in 8 bit mode. While you seem to be using that you do not allow the LCD to complete it's power on routine by waiting until after that completes.

The web has 10,000 sites devoted to LCD code on every chip out there. Have you tried to Google "AVR LCD" yet?
 

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
Thanks for reply.
Do you mean that I should use initialise by instruction? While going through the datasheet (for 8bit initialisation) the first three instructions are same with different time delays after each instruction.
why can't one give these instruction just once and do a cumulative time delay?(I googled and found a nice page on initialisation but it doesnot answer my above question)
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
I believe that's the 4 bit initialization ylou are looking at. For 8 bits all you need do it WAIT till it is done doing it's internal init. Leave it along, don't send commands or data, it will probably ignore them anyway.

Do look at the data set up time and the min clock width too: you may need to add a bit of delay between the data and the control signals, and make sure the control signals are on long enough.
 

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
I checked the busy flag between control and data signals (and also tried giving delays) .Also , gave a full delay of up to 1 second during power on (far more than necessary) ,but it still won't work .
If its not asking much can I be provided with a LCD program which includes initialization in 8 bit mode and displaying a character...
I will greatly appreciate any help.
 

Thread Starter

baba_bhuri

Joined Jul 2, 2013
17
Thanks for help. My code works now.
The error was in initialize function ,I was not giving the required time delays in the last 4 instructions.
 

tshuck

Joined Oct 18, 2012
3,534
Thanks for help. My code works now.
The error was in initialize function ,I was not giving the required time delays in the last 4 instructions.
That's usually how it works for most people starting with these LCD modules...on the bright side, you will probably never spend this much time with a bad initialization again!

Glad to hear you've got it working!
 
Top