void init_port(void);
void outport(char);
void RS_Enable_pin(char);
void delay1(int);
void lcd_control_write(void);
void init_lcd(void);
void write_data(char);
void write_string(char *ptr);
void scroll_display_infinite(void);
void setup() {
init_port();
init_lcd();
write_string("Ankit Harsh");
delay1(2000); // Wait 2 seconds to read the message
scroll_display_infinite(); // Start infinite scrolling
}
void write_string(char *ptr) {
while (*ptr != 0) {
write_data(*ptr);
ptr++;
}
}
void init_port() {
volatile char *portb_dir = (volatile char *)0x24;
volatile char *portd_dir = (volatile char *)0x2A;
volatile char *portc_dir = (volatile char *)0x27;
*portb_dir = 0x0F; // Set PORTB for output
*portd_dir = 0xF0; // Set higher nibble of PORTD for output
*portc_dir = 0x03; // Set lower bits of PORTC for output
}
void outport(char out_data) {
volatile char *portb_data = (volatile char *)0x25;
volatile char *portd_data = (volatile char *)0x2B;
*portb_data = out_data >> 4; // Send high nibble
*portd_data = out_data << 4; // Send low nibble
}
void RS_Enable_pin(char out_data) {
volatile char *portc_data = (volatile char *)0x28;
*portc_data = out_data; // Control RS pin
}
void init_lcd(void) {
outport(0x38); // 8-bit, 2 lines
lcd_control_write();
delay1(2); // Delay for stability
outport(0x0F); // Display on, Cursor Blinking
lcd_control_write();
delay1(2); // Delay for stability
outport(0x01); // Clear Display
lcd_control_write();
delay1(2); // Delay for clearing the display
outport(0x06); // Auto Increment
lcd_control_write();
delay1(2); // Delay for stability
}
void write_data(char wr_data) {
outport(wr_data);
RS_Enable_pin(0x02); // RS high for data
delay(1);
RS_Enable_pin(0x03); // Enable high
delay(1);
RS_Enable_pin(0x02); // Enable low
delay1(2); // Delay for data to be processed
}
void lcd_control_write(void) {
RS_Enable_pin(0x01); // RS low for command
delay(1);
RS_Enable_pin(0x00); // Enable low
delay1(2); // Delay for command to be processed
}
void delay1(int count) {
volatile long i;
while(count) {
for(i=0; i<1000; i++);
count--;
}
}
// Function to scroll the message infinitely
void scroll_display_infinite() {
while (1) { // Infinite loop
for (int i = 0; i < 16; i++) { // Scroll for the length of the display
outport(0x1C); // Scroll display right
lcd_control_write();
delay1(150); // Delay for scrolling effect
}
outport(0x01); // Clear the display after scrolling
lcd_control_write(); // Execute the clear command
delay1(2); // Wait for the display to clear
outport(0x80); // Move cursor back to the start
write_string("Ankit Harsh"); // Reprint the message
delay1(2000); // Wait for 2 seconds before scrolling again
}
}
void loop() {
// No code here
}