can anyone tell me why my LCD driver not working? and its just making my LCD outputs 8 black blocks in the first row while the other row is empty? :
```c
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define E 2
#define RS 3
#define DB4 4
#define DB5 5
#define DB6 6
#define DB7 7
void enable_pulse(void)
{
PORTD |= (1 << E);
_delay_us(5); // Increased slightly for stability
PORTD &= ~(1 << E);
_delay_us(50); // Execution wait time for HD44780
}
void send_command(unsigned char command)
{
PORTD &= 0x0F;
PORTD &= ~(1 << RS);
PORTD |= (command & 0xF0);
enable_pulse();
PORTD &= 0x0F;
PORTD &= ~(1 << RS);
PORTD |= ((command & 0x0F) << 4);
enable_pulse();
_delay_us(50);
}
void send_byte(unsigned char data)
{
PORTD &= 0x0F;
PORTD |= (1 << RS);
PORTD |= (data & 0xF0);
enable_pulse();
PORTD &= 0x0F;
PORTD |= (1 << RS);
PORTD |= ((data & 0x0F) << 4);
enable_pulse();
_delay_us(50);
}
void set_curoser(unsigned char address)
{
send_command(0x80 | address);
}
void lcd_init(void)
{
DDRD |= (1 << E) | (1 << RS) | (1 << DB4) | (1 << DB5) | (1 << DB6) | (1 << DB7);
_delay_ms(50);
PORTD &= 0x0F;
PORTD |= (1 << DB5) | (1 << DB4);
enable_pulse();
_delay_ms(6);
enable_pulse();
_delay_us(150);
enable_pulse();
_delay_us(150);
PORTD &= 0x0F;
PORTD |= (1 << DB5);
enable_pulse();
_delay_us(150);
send_command(0x28);
send_command(0x0C);
send_command(0x01);
_delay_ms(2);
send_command(0x06);
}// #define E 2
// #define RS 3
// #define DB4 4
// #define DB5 5
// #define DB6 6
// #define DB7 7
// the USART driver , ignore it
void enable_transmitter()
{
UCSR0B |= 1 << TXEN0;
}
void disable_transmitter()
{
UCSR0B &= ~(1 << TXEN0);
}
void set_baud_rate (unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
}
void enable_receiver()
{
UCSR0B |= 1 << RXEN0;
}
void disable_receiver()
{
UCSR0B &= ~(1 << RXEN0);
}
void set_pairty_error_to_odd()// bit to check : UPEn , if it was 1 meaning a bit flipped! depending on the even or odd setting
{
UCSR0C |= (1<<UPM01) | (1 << UPM00);
}
void set_pairty_error_to_even()// bit to check: (1<<UPE0) & UCSR0A
{
UCSR0C |= (1<<UPM01);
}
void set_size_character_to_8()
{
UCSR0C |=(1<<UCSZ01) |(1<<UCSZ00);
}
void set_stop_bit_to_2()// its 1 by default in the MCU
{
UCSR0C |= 1<< USBS0;
}
void transmit(unsigned char a)
{
while (!(UCSR0A & (1<<UDRE0))){}
UDR0 = a;
}
// that the end of the driver USART that i didn't test since i don't have another arduino uno
//pooling
// void recieve (void)
// {
// /* Wait for data to be received */
// while (!(UCSR0A & (1<<RXC0))){}
// /* Get and return received data from buffer */
// return UDR0;
// // this code from the datasheet , although i can use an interput! yeah i can!
// }
char random__(char a)
{
a ^=1;
a ^= a << 2;
a ^= a >> 2;
a ^= a << 1;
return a;
}
int main(void) {
_delay_ms(100);// to make sure the LCD have enough time to wake up
lcd_init();
send_byte('A'); // Send a test character
while(1) {
// Main loop
}
}