void init_port(void);
void outdata(char);
void outcontrol(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 *portf_dir  = (volatile char *)0x30;
  volatile char *portk_dir  = (volatile char *)0x107;
  *portf_dir = 0xFF;
  *portk_dir = 0x03;
}

void outdata(char out_data)
{
  volatile char *portf_data = (volatile char *)0x31; 
  *portf_data = out_data;
}

void outcontrol( char out_data)
{
  volatile char *portk_data = (volatile char *)0x108; 
  *portk_data = out_data;
}

void init_lcd( void )
{
  outdata(0x38);   // 8bit 2 line
  lcd_control_write();
  outdata(0x0F);   // Display on Cursor Blinking
  lcd_control_write();
  outdata(0x01);   // Clear Display
  lcd_control_write();
  outdata(0x06);   // Auto Increment
  lcd_control_write();
}

void write_data(char wr_data)
{
  outdata(wr_data);
  outcontrol(0x02);
  delay1(1);
  outcontrol(0x03);
  delay1(1);
  outcontrol(0x02);
  delay1(1);
}

void lcd_control_write( void )
{
  outcontrol(0x01);
  delay1(1);
  outcontrol(0x00);
  delay1(1);
}

void delay1(int count)
{
  volatile long i;
  while(count)
  {
    for(i=0; i<1000; i++);
    count--;
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}