Sending Characters in LCD
subratasarkar20
c_cpp
24 days ago
1.8 kB
1
Indexable
Never
/* * LCDSendACharacter.cpp * * Created: 19-09-2024 11:53:19 * Author : subrs */ #include <avr/io.h> #include <util/delay.h> #define LCD_Data_Pins PORTB #define LCD_Data_Pins_DDR DDRB #define LCD_Control_Pins PORTD #define LCD_Control_Pins_DDR DDRD #define Enable PIND5 #define ReadWrite PIND7 #define RS PIND2 void Check_If_LCD_Is_Busy(void); void setEnable(void); void sendCommand(unsigned char command); void sendCharacter(unsigned char character); int main(void) { LCD_Control_Pins_DDR = 0xFF; LCD_Control_Pins |= 1 << Enable | 1 << ReadWrite | 1 << RS; _delay_ms(15); sendCommand(0x01); // command for clearing the screen in LCD is 0x01 _delay_ms(2); sendCommand(0x38); // command for 8 bit mode _delay_us(50); sendCommand(0b00001111); _delay_us(50); sendCharacter(0x48); // H sendCharacter(0x65); // e sendCharacter(0x6C); // l sendCharacter(0x6C); // l sendCharacter(0x6F); // o while (1) { } } void Check_If_LCD_Is_Busy(void) { LCD_Data_Pins_DDR = 0X00; LCD_Control_Pins |= 1 << ReadWrite; LCD_Control_Pins &= ~(1 << RS); while(LCD_Data_Pins >= 0x80) { setEnable(); } LCD_Data_Pins_DDR = 0XFF; } void setEnable(void) { LCD_Control_Pins |= 1 << Enable; asm volatile ("nop"); asm volatile ("nop"); LCD_Control_Pins &= ~(1 << Enable); } void sendCommand(unsigned char command) { Check_If_LCD_Is_Busy(); LCD_Data_Pins = command; LCD_Control_Pins &= ~(1 << ReadWrite) | (1 << RS); setEnable(); LCD_Data_Pins = 0; } void sendCharacter(unsigned char character) { Check_If_LCD_Is_Busy(); LCD_Data_Pins = character; LCD_Control_Pins &= ~(1 << ReadWrite); LCD_Control_Pins |= 1 << RS; setEnable(); LCD_Data_Pins = 0; }
Leave a Comment