#include<avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
//#include <avr/signal.h>
//#include <avr/io.h>
#include <asm.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>
#define LCD_PORT PORTC
#define rombyte pgm_read_byte
#define EN SBIT(PORTC,6)
#define SW SBIT(PORTA,1)
#//define LCD_EN {LCD_PORT|=0x40;_delay_us(1);LCD_PORT&=~0x40;}
#define LCD_EN {EN=1;_delay_us(1);EN=0;}
unsigned int a;
unsigned char d;
#define RS 0x10
#define RW 0x20
int x;
char s[] PROGMEM={"ARUN KUMAR SHARMA"};
char f[] PROGMEM={"Abhay Sharma"};
char *p;
char g;
void busy()
{
DDRC=0xF0;
LCD_PORT=0x2F;
//LCD_PORT|=0x20;
do
{
LCD_PORT|=0x40;
_delay_us(1);
ASM_NOP();
d=(PINC&0x0F)<<4;
LCD_PORT&=~0x40;
_delay_us(1);
LCD_PORT|=0x40;
_delay_us(1);
//d|=(PINC&0x0F)<<4;
LCD_PORT&=~0x40;
}while(d&0x80);
DDRC=0xFF;
}
void LCD_WRITE_DATA(unsigned char data)
{
LCD_PORT&=~RW;
LCD_PORT|=RS;
LCD_PORT=(LCD_PORT&0xF0)|(data>>4);
LCD_EN;
LCD_PORT=(LCD_PORT&0xF0)|(data&0x0F);
LCD_EN;
busy();
// _delay_us(1000);
}
void LCD_WRITE_CMD(unsigned char data)
{
LCD_PORT&=~RW;
LCD_PORT&=~RS;
LCD_PORT=(LCD_PORT&0xF0)|(data>>4);
LCD_EN;
LCD_PORT=(LCD_PORT&0xF0)|(data&0x0F);
LCD_EN;
busy();
//_delay_us(1000);
}
void init_LCD()
{
LCD_PORT=0x00;
LCD_PORT|=0x02;
LCD_EN;
_delay_us(50);
LCD_WRITE_CMD(0x28);
LCD_WRITE_CMD(0x0F);
LCD_WRITE_CMD(0x01);
LCD_WRITE_CMD(0x02);
}
ISR(INT0_vect)
{
LCD_WRITE_CMD(0x01);
}
int main()
{
int i=0;
DDRA=0xf1;
PORTA=0x02;
DDRC=0xFF;
PORTC=0x00;
DDRD=0b11111011;
PORTD=0b00000100;
MCUCR=(1<<ISC00)|(1<<ISC01);
GICR=0b01000000;
sei();
init_LCD();
p=&s[0];
//g=rombyte(&s);
while(rombyte(&*p))
{
LCD_WRITE_DATA(rombyte(&*p));
i++;
//p=pgm_read_byte(s[i]);
p++;
}
// LCD_WRITE_DATA('S');
while(1)
{
if(bit_is_set(PINA,1)/*PINA&0x02*/)
g=1;
if(g&&bit_is_clear(PINA,1)/*((PINA&0x02)==0)*/)
{
g=0;
p=f;
//LCD_WRITE_CMD(0x01);
LCD_WRITE_CMD(0xC0);
while(rombyte(&*p))
{
LCD_WRITE_DATA(rombyte(&*p));
p++;
}
}
}
//return 0 ;
}