//my first test balaji sir code 10-03-23
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("AARAV");
  }
 
void write_string(char *ptr)
{
  
  while(*ptr != 0)
  {
    write_data(*ptr);
    delay1(50);
    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(0x30);   // 8bit 2 line//funtion set
  lcd_control_write();
  outdata(0x0F);   // Display on Cursor Blinking
  lcd_control_write();
  outdata(0x01);   // Clear Display
  lcd_control_write();
  outdata(0x07);   // Auto Increment//entry mode
  lcd_control_write();
  outdata(0x80); // cursor or display shift
  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:

}