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:
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();
}