#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/delay.h>
#include <inttypes.h>

void LCD_Wait(void);
void LCD_Init(void);
char LCD_Write_Data(char);
int	 LCD_Write_Command(int);
char print(char *a);
main()
{
	//DDRC  = 0xff;
	//LCD_Init();
	//printf('H');
	//int i = 0;
	//char a[] = "I My god what happened";
	print("Shit! My God!");
	//char *pmessage  = amessage;
	//print(pmessage);
	
	//for (i; i<16; i++)
	//{
	//LCD_Write_Data(amessage[i]);
	//pmessage++;
	//}
	//int *ps;
	//ps = &s[];
	


	//LCD_Write_Data('H');
	//LCD_Write_Data('E');
	//LCD_Write_Data('L');
	//LCD_Write_Data('L');
	//LCD_Write_Data('O');
	//LCD_Write_Data(' ');
	//LCD_Write_Data('W');
	//LCD_Write_Data('O');
	//LCD_Write_Data('R');
	//LCD_Write_Data('L');
	//LCD_Write_Data('D');
	//LCD_Write_Data('!');
	//LCD_Write_Data(' ');
	//PORTC = 0x30;		//'3'
	//LCD_Wait();
	//PORTC = 0x35;
	//LCD_Wait();
	//PORTC = 0X40;
	//LCD_Wait();
	//PORTC = 0X45;
	//LCD_Wait();

	//PORTC = 0x30;		//'3'
	//LCD_Wait();
	//PORTC = 0x35;
	//LCD_Wait();
	//PORTC = 0XF0;
	//LCD_Wait();
	//PORTC = 0XF5;
	//LCD_Wait();
	//PORTC = 0X30;
	//PORTC = 0X35;

}
void LCD_Init(void)
{
	LCD_Write_Command(0x33);
	LCD_Write_Command(0x32);	//set 4 bit mode
	LCD_Write_Command(0x2c);	//2 lines
	LCD_Write_Command(0x0f);	//display on; cursor on; blink on
	LCD_Write_Command(0x01);	//clear screen; cursor home
	LCD_Write_Command(0x06);
	
	//PORTC = 0x30;		//$33
	//LCD_Wait();
	//PORTC = 0x34;
	//LCD_Wait();
	//PORTC =0x30;
	//LCD_Wait();
	//PORTC = 0x34;
	//LCD_Wait();
	//PORTC = 0x30;		//$32
	//LCD_Wait();
	//PORTC = 0x34;
	//LCD_Wait();
	//PORTC = 0X30;
	//LCD_Wait();
	//PORTC = 0X24;
	//LCD_Wait();
	//PORTC = 0x20;		//$2C
	//LCD_Wait();
	//PORTC = 0x24;
	//LCD_Wait();
	//PORTC = 0XC0;
	//LCD_Wait();
	//PORTC = 0XC4;
	//LCD_Wait();
	//PORTC = 0x00;		//$0f
	//LCD_Wait();
	//PORTC = 0x04;
	//LCD_Wait();
	//PORTC = 0XF0;
	//LCD_Wait();
	//PORTC = 0XF4;
	//LCD_Wait();	
	//PORTC = 0x00;		//$01
	//LCD_Wait();
	//PORTC = 0x04;
	//LCD_Wait();
	//PORTC = 0X10;
	//LCD_Wait();
	//PORTC = 0X14;
	//LCD_Wait();
}
void LCD_Wait(void)
{
	int f = 0;
	for (f = 0; f <1000; f++){};

}
char LCD_Write_Data(char data)
{	
	char nibble1;
	char nibble2;
	nibble1 = data & 0xf0;
	PORTC 	= nibble1 | 0x01;
	LCD_Wait();
	PORTC 	= nibble1 | 0x05;
	LCD_Wait();
	nibble2 = data << 4;
	PORTC 	= nibble2 | 0x01;
	LCD_Wait();
	PORTC 	= nibble2 | 0x05;
	LCD_Wait(); 
}
int LCD_Write_Command(int command)
{
	int nibble1;
	int nibble2;
	nibble1 = command & 0xf0;
	PORTC 	= nibble1;
	LCD_Wait();
	PORTC	= nibble1 | 0x04;
	LCD_Wait();
	nibble2 = command << 4;
	PORTC	= nibble2;
	LCD_Wait();
	PORTC	= nibble2 | 0x04;
	LCD_Wait();
}
char print(char *s)
{	
	DDRC  = 0xff;
	LCD_Init();
	int i = 0;

	while ((*s != '\0') & (i != 16)  )
	{	
		LCD_Write_Data(*s);
		i++;
		s++;
	}
	LCD_Write_Command(0xc0);
	while (*s != '\0')
	{	
		LCD_Write_Data(*s);
		s++;

	}
	LCD_Write_Data(' ');

}
