void init_port(void);
void outport(char);
void outportc(char);
void delay1(int);
void lcd_control_write(void);
void init_lcd(void);
void write_data(char);
void setup() {
init_port();
init_lcd();
write_string("Welcome");
}
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;
*portd_dir = 0xF0;
*portc_dir = 0x0F;
}
void outport( char out_data)
{
volatile char *portb_data = (volatile char *)0x25;
volatile char *portd_data = (volatile char *)0x2B;
*portb_data = out_data >> 4;
*portd_data = out_data << 4;
}
void outportc( char out_data)
{
volatile char *portc_data = (volatile char *)0x28;
*portc_data = out_data;
}
void init_lcd( void )
{
outport(0x38); // 8bit 2 line
lcd_control_write();
outport(0x0F); // Display on Cursor Blinking
lcd_control_write();
outport(0x01); // Clear Display
lcd_control_write();
outport(0x06); // Auto Increment
lcd_control_write();
}
void write_data(char wr_data)
{
outport(wr_data);
outportc(0x04);
delay(1);
outportc(0x05);
delay(1);
outportc(0x04);
delay1(1);
}
void lcd_control_write( void )
{
outportc(0x01);
delay(1);
outportc(0x00);
delay1(1);
}
void delay1(int count)
{
volatile long i;
while(count)
{
for(i=0; i<1000; i++);
count--;
}
}
void loop() {
}