Hallo! i'm trying to send a text string to LCD for the first time. Could you check my code for any errors? Thanks 
Rich (BB code):
/LCD DATA BUS CONNECTED TO PORTD , 8 bit mode
// RS connected to PB0, R/W to PB1, E to PB2
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
void LCD_WAIT(void)
{
DDRD=0; //Set all pins as inputs for reading busy flag
PORTB=0x00; // It's a read command
// checking if the LCD is still busy
while(!(PIND7&0b100000)){
_delay_loop_2(10);
}
}
void LCD_SEND_COMMAND(void)
{
DDRD=0xFF; //Set all pins as outputs for sending instruction
PORTB|=(1<<PORTB1);; // It's a write command
PORTB|=(1<<PORTB2); //E=1
_delay_loop_2(1000);
PORTB&=0b1111011; // E=0
_delay_loop_2(1000);
LCD_WAIT();
DDRD=0XFF; //SET PORTD PINS AS OUTPUT
DDRB=0XFF; //SET PORTB PINS AS OUTPUT- FOR E,RW,RS
}
void LCD_INIT(void)
{
// FUNCTION SET
PORTD=0x38; //8 BIT INTERFACE,2 LINES,5*7 FONT
LCD_SEND_COMMAND();
// DISPLAY ON/OFF CONTROL
PORTD=0x0E; //DISPLAY ON, CURSOR ON, BLINK OFF
LCD_SEND_COMMAND();
// DISPLAY ON/OFF CONTROL
PORTD=0x06; // AUTOMATIC CURSOS POSITION INCREMENT
LCD_SEND_COMMAND();
// CLEAR DISPLAY
PORTD=0x01; //CLAER DISPLAY & RETURN CURSOR HOME
LCD_SEND_COMMAND();
}
void LCD_WRITE(char TEXT[])
{
unsigned char i;
PORTB|=(1<<PORTB0);
for(i=0;(i<32)&&(TEXT!='\0');i++)
{
PORTD=TEXT;
LCD_SEND_COMMAND();
}
}
int main(void){
LCD_INIT();
LCD_WRITE("Andrew");
}
Last edited: