#include<avr/io.h>
#include<util/delay.h>
#define rs 0x01;
#define rw 0x02;
#define en 0x04;
unsigned char EEPROM_read(unsigned int uiAddress);
void lcd_cmd(unsigned char cmd);
void lcd_data(unsigned char data);
void initialize();
void EEPROM_write(unsigned int uiAddress, unsigned char ucData);
void kepad();
void lcd_cmd(unsigned char cmd)
{
PORTC=0x00;
PORTD=cmd;
PORTC|=en;
_delay_ms(20);
PORTC^=en;
}
void lcd_data(unsigned char data)
{
PORTC=0x00;
PORTC|=rs;
PORTD=data;
PORTC|=en;
_delay_ms(50);
PORTC^=en;
}
void initialize()
{
lcd_cmd(0x38);
lcd_cmd(0x0f);
}
void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
//Wait for completion of previous write
while(EECR & (1<<EEWE));
// Set up address and data registers
EEAR = uiAddress;
EEDR = ucData;
// Write logical one to EEMWE
EECR |= (1<<EEMWE);
// Start eeprom write by setting EEWE
EECR |= (1<<EEWE);
}
unsigned char EEPROM_read(unsigned int uiAddress)
{
// Wait for completion of previous write
while(EECR & (1<<EEWE));
// Set up address register
EEAR = uiAddress;
// Start eeprom read by writing EERE
EECR |= (1<<EERE);
// Return data from data register
return EEDR;
}
void kepad()
{
unsigned char name1[15];
unsigned char star="*";
unsigned char arry[9]={0,1,2,3,4,5,6,7,8,9};
initialize();
lcd_cmd(0x80);
unsigned int uiAddress=0060;
PORTA = 0xf7;
if(PINA==0xf6)//1
{
while(PINA==0xf6)
{
EEPROM_write(uiAddress,arry[1]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xf5)//2
{
while(PINA==0xf5)
{
EEPROM_write(uiAddress,arry[2]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xf3)//3
{
while(PINA==0xf3)
{
EEPROM_write(uiAddress,arry[3]);
uiAddress++;
lcd_data(star);
}
}
PORTA = 0xef;
if(PINA==0xee)//4
{
while(PINA==0xee)
{
EEPROM_write(uiAddress,arry[4]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xed)//5
{
while(PINA==0xed)
{
EEPROM_write(uiAddress,arry[5]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xeb)//6
{
while(PINA==0xeb)
{
EEPROM_write(uiAddress,arry[6]);
uiAddress++;
lcd_data(star);
}
}
PORTA = 0xdf;
if(PINA==0xde)//7
{
while(PINA==0xde)
{
EEPROM_write(uiAddress,arry[7]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xdd)//8
{
while(PINA==0xdd)
{
EEPROM_write(uiAddress,arry[8]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xdb)//9
{
while(PINA==0xdb)
{
EEPROM_write(uiAddress,arry[9]);
uiAddress++;
lcd_data(star);
}
}
PORTA = 0xbf;
if(PINA==0xbd)//0
{
while(PINA==0xbd)
{
EEPROM_write(uiAddress,arry[0]);
uiAddress++;
lcd_data(star);
}
}
else if(PINA==0xbb)//*
{
while(PINA==0xbb)
{
}
int m=0;
m=uiAddress--;
uiAddress=0060;
for(int i=0; i<m; i++)
{
name1[i]=EEPROM_read(uiAddress);
uiAddress++;
}
initialize();
lcd_cmd(0x80);
if(name1[4]==1234)
{
unsigned char correct[]="Correct password";
for(int p=0; p<sizeof(correct);p++)
lcd_data(correct[p]);
return 0;
}
else
{
unsigned char wrong[]="wrong password";
for(int p=0; p<sizeof(wrong);p++)
lcd_data(wrong[p]);
kepad();
}
}
else if(PINA==0xbe)//#
{
while(PINA==0xbe)
{
}
int l=0;
l=uiAddress--;
uiAddress=0060;
for(int i=0; i<l; i++)
{
name1[i]=EEPROM_read(uiAddress);
uiAddress++;
for(int p=0; p<sizeof(name1);p++)
lcd_data(name1[p]);
}
}
}
int main()
{
DDRC=0x07;
DDRD=0xff;
DDRA=0xf8;
initialize();
lcd_cmd(0x80);
//unsigned int uiAddress=0060;
unsigned char ucData[]="Enter the password";
//unsigned char name1[50];
for( int k=0; k<sizeof(ucData); k++)
{
lcd_data(ucData[k]);
//EEPROM_write(uiAddress,ucData[k]);
//uiAddress++;
}
lcd_cmd(0xc2);
void keypad();
/*
uiAddress=0060;
for(int i=0; i<sizeof(ucData); i++)
{
name1[i]=EEPROM_read(uiAddress);
lcd_data(name1[i]);
uiAddress++;
}
//lcd_cmd(0xc2);
//for(int j=0; j<sizeof(name1); j++)
//lcd_data(name1[j]);
*/
return(1);
}