0% found this document useful (0 votes)
199 views5 pages

24 Project 22 EEPROM Based Password Controlled Application

This document contains code for an embedded system that stores a password in EEPROM and compares user input to the stored password to control access. It initializes an LCD display and uses it to prompt for a password entry and indicate access status. It also allows control of a bulb by pressing buttons to turn it on or off after successful password entry. Functions are defined for LCD initialization and control, reading/writing EEPROM, scanning buttons, comparing strings, and clearing the LCD display.

Uploaded by

Yashaswa Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views5 pages

24 Project 22 EEPROM Based Password Controlled Application

This document contains code for an embedded system that stores a password in EEPROM and compares user input to the stored password to control access. It initializes an LCD display and uses it to prompt for a password entry and indicate access status. It also allows control of a bulb by pressing buttons to turn it on or off after successful password entry. Functions are defined for LCD initialization and control, reading/writing EEPROM, scanning buttons, comparing strings, and clearing the LCD display.

Uploaded by

Yashaswa Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<avr/io.

h>
#define F_CPU 1000000UL
#include<util/delay.h>
#include<avr/eeprom.h>
/*
#include<avr/eeprom.h>
uint8_t eeprom_read_byte(const uint8_t *addr)
void eeprom_write_byte(uint8_t *addr, uint8_t value)
uint16_t eeprom_read_word(const uint16_t *addr)
void eeprom_write_word(uint16_t *addr, uint16_t value)
void eeprom_read_block(void *pointer_ram, const void *pointer_eeprom, si
ze_t n)
void eeprom_write_block(void *pointer_eeprom, const void *pointer_ram, s
ize_t n)
*/
#define lcd PORTC
#define rs 0
#define rw 1
#define en 2
void lcd_init();
void lcd_command(unsigned char);
void lcd_data(unsigned char);
void lcd_string(char *str);
void lcd_number(unsigned int);
void lcd_clear(unsigned char pos);
char keyscan();
unsigned char match_password(unsigned char *str1,unsigned char *str2);
/*
Steps to store data into eeprom:Initially you have to program the hex file into controller and
then you have to program the .eep file into eeprom
*/
char eeprom_data[] EEMEM= "1234\0";

int main()
{
char password[15];
char string[15];
char y,result;
int i;
DDRC = 0XFF;
DDRD = 0XFF;
DDRA = 0X00;
DDRB = 0xFF;
PORTA = 0XFF;
lcd_init();

main_loop:
lcd_command(0x80);
lcd_string("Enter password

");

lcd_command(0xc0);
i=0;
while(1)
{
y = keyscan();
if(y == 'E')
{
string[i]='\0';
break;
}
string[i] = y;
lcd_data('*');
i++;
}
eeprom_read_block(password,0,15);
result = match_password(string,password);
if(result=='Y')
{
lcd_command(0x80);
lcd_string("
matched
");
lcd_command(0xc0);
lcd_string("
");
_delay_ms(1000);
goto next;
}
else
{
lcd_command(0x80);
lcd_string("Not matched
");
lcd_command(0xc0);
lcd_string("Please retry ");
_delay_ms(1000);
lcd_clear(3);
goto main_loop;
}
next:
lcd_command(0x80);
lcd_string("Press 1-ON 2-OFF");
while(1)
{
y=keyscan();
if(y=='E')
{
lcd_clear(3);
goto main_loop;
}
if(y=='1')
{
lcd_command(0xc0);

lcd_string("
Bulb ON
PORTB |=(1<<PB0);
}
if(y=='2')
{
lcd_command(0xc0);
lcd_string("
Bulb OFF
PORTB &=~(1<<PB0);
}

");

");

}
return 0;
}
void lcd_init()
{
lcd_command(0x02);
lcd_command(0x28);
lcd_command(0x06);
lcd_command(0x0c);
}
void lcd_command(unsigned char com)
{
lcd = com & 0xF0;
lcd &= ~(1<<rs);
lcd &= ~(1<<rw);
lcd |=(1<<en);
_delay_ms(1);
lcd &= ~(1<<en);
_delay_ms(1);

//send higher bit


//rs =0
//rw =0
//en =1
//en =0

lcd = (com<<4) & 0xF0; //send lower bit


lcd &= ~(1<<rs);
lcd &= ~(1<<rw);
lcd |=(1<<en);
_delay_ms(1);
lcd &= ~(1<<en);
_delay_ms(1);
}
void lcd_data(unsigned char value)
{

//rs =0
//rw =0
//en =1
//en =0

lcd =value & 0xF0;

//send higher bit

lcd |= (1<<rs);
lcd &= ~(1<<rw);
lcd |=(1<<en);
_delay_ms(1);
lcd &= ~(1<<en);
_delay_ms(1);

//rs =1
//rw =0
//en =1
//en =0

lcd =(value<<4) & 0xF0; //send lower bit


lcd |= (1<<rs);
lcd &= ~(1<<rw);
lcd |=(1<<en);
_delay_ms(1);

//rs =1
//rw =0
//en =1

lcd &= ~(1<<en);


_delay_ms(1);
}

//en =0

void lcd_clear(unsigned char pos)


{
if(pos==1)
{
lcd_command(0x80);
lcd_string("
}
else if(pos==2)
{
lcd_command(0xc0);
lcd_string("
}
else if(pos==3)
{
lcd_command(0x80);
lcd_string("
lcd_command(0xc0);
lcd_string("
}

");

");

");
");

}
void lcd_string(char *str)
{
int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
}
}
void lcd_number(unsigned int value)
{
unsigned int d=0;
lcd_command(0x04);
//auto decrement mode
if(value==0)
lcd_data(value+48);
while(value!=0)
{
d=value%10;
lcd_data(d+48);
value=value/10;
}
lcd_command(0x06);

//auto increment mode

}
char keyscan()
{
while(1)
{
PORTD = 0X0e;
_delay_ms(5); /////must for response at porta when key press
if((PINA&0b00000001)==0){while(!(PINA&0b00000001)); return '0';}
if((PINA&0b00000010)==0){while(!(PINA&0b00000010)); return '1';}

if((PINA&0b00000100)==0){while(!(PINA&0b00000100)); return '2';}


if((PINA&0b00001000)==0){while(!(PINA&0b00001000)); return '3';}
PORTD = 0X0d;
_delay_ms(5);
if((PINA&0b00000001)==0){while(!(PINA&0b00000001));
if((PINA&0b00000010)==0){while(!(PINA&0b00000010));
if((PINA&0b00000100)==0){while(!(PINA&0b00000100));
if((PINA&0b00001000)==0){while(!(PINA&0b00001000));

return
return
return
return

'4';}
'5';}
'6';}
'7';}

PORTD = 0X0b;
_delay_ms(5);
if((PINA&0b00000001)==0){while(!(PINA&0b00000001));
if((PINA&0b00000010)==0){while(!(PINA&0b00000010));
if((PINA&0b00000100)==0){while(!(PINA&0b00000100));
if((PINA&0b00001000)==0){while(!(PINA&0b00001000));

return
return
return
return

'8';}
'9';}
'A';}
'B';}

PORTD = 0X07;
_delay_ms(5);
if((PINA&0b00000001)==0){while(!(PINA&0b00000001));
if((PINA&0b00000010)==0){while(!(PINA&0b00000010));
if((PINA&0b00000100)==0){while(!(PINA&0b00000100));
if((PINA&0b00001000)==0){while(!(PINA&0b00001000));

return
return
return
return

'C';}
'D';}
'E';}
'F';}

}
}
unsigned char match_password(unsigned char *str1,unsigned char *str2)
{
unsigned int i=0;
while(str1[i]!='\0')
{
if((str1[i] != str2[i]))
{
return 'N';
}
else
i++;
}
i=0;
while(str2[i]!='\0')
{
if((str1[i] != str2[i]))
{
return 'N';
}
else
i++;
}
return 'Y';
}
//************************************END***************************************
***********

You might also like