I did this project using PIC16F877A and it went ok.
nothing wrong.
but the problem is how can i change a new password and it doesn't lost when the power is turn off.
what i mean is the new password will be save in memory of the pic.
and the LCD display will go like this "please enter new password".
can someone show me.
please.. !!
this is the code.
please tell me what i need to add.

nothing wrong.
but the problem is how can i change a new password and it doesn't lost when the power is turn off.
what i mean is the new password will be save in memory of the pic.
and the LCD display will go like this "please enter new password".
can someone show me.
please.. !!
this is the code.
Code:
// :PIC16F877A + 4x3 keypad + LCD are used to build a keypad door
// security system which will activate the relay and buzzer after
// a preset 6-digit password is entered.
// LCD will display ****** when keypad is pressed.
// preset password for this program is 123456
//
//
// include
//==========================================================================
//#include <p16F877A.h>
// configuration
//==========================================================================
//__CONFIG ( 0x3F32 );
// define
//==========================================================================
#define rs portc.f0 //RC0
#define e portc.f1 //RC1
#define led_red portc.f2 //RC2
#define led_green portc.f3 //RC3
#define lcd_data PORTD
#define relay portb.f1 //RB1
#define buzzer portb.f2 //RB2
#define RE0 porte.f0
#define RE1 porte.f1
#define RA5 porta.f5
#define RA4 porta.f4
#define RA3 porta.f3
#define RA2 porta.f2
#define RA1 porta.f1
#define RA0 porta.f0
// function prototype
//==========================================================================
void delay(unsigned long data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void e_pulse(void);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void scanrow1(void);
void scanrow2(void);
void scanrow3(void);
void scanrow4(void);
// global variable
//==========================================================================
unsigned char step=0;
unsigned char lcd_count=0;
unsigned char password_count=0;
unsigned char password_wrong=0;
unsigned char sequence=0;
unsigned char testbit=0x01;
unsigned char init;
// main function
//==========================================================================
void main(void)
{
ADCON1=0b00000110; //set all portA pins as digital I/O
TRISA=0b11001111; //clear bit 4&5 portA as output and set the rest as input
TRISB=0b00000000; //set portB as output
TRISD=0b00000000; //set portD as output
TRISC=0b11110000; //set bit4-7 portC as input(connected to 4 row of keypad)
TRISE=0b00000000; //set portE as output
PORTC=1;
PORTD=0;
relay=0;
buzzer=0;
led_green=0;
led_red=0;
init=0;
sequence=0;
send_config(0b00001001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function
lcd_clr();
delay(1000);
lcd_goto(0); //initial display
send_string("PLEASE ENTER");
lcd_goto(20);
send_string("6-DIGIT PASSWORD");
while(1)
{
//keypad scanning
RE1=0; //clear the 1st column and set the others
RE0=1;
RA5=1;
RA4=1;
scanrow1(); //scan row
RE1=1; //clear the 2nd column and set the others
RE0=0;
RA5=1;
RA4=1;
scanrow2(); //scan row
RE1=1; //clear the 3rd column and set the others
RE0=1;
RA5=0;
RA4=1;
scanrow3(); //scan row
RE1=1; //clear the 4th column and set the others
RE0=1;
RA5=1;
RA4=0;
scanrow4(); //scan row
if(password_count==6)
{
if(testbit==1) //test whether password is correct
{
lcd_clr(); //clear lcd
lcd_goto(0);
send_string("SUCCESS"); //display SUCCESS
lcd_goto(20);
send_string("DOOR OPEN");
led_green=1; //green light on
buzzer=1; //buzzer on
relay=1; //relay on
delay(8000);
buzzer=0; //buzzer off
while(1);
}
else
{
lcd_clr(); //clear lcd
lcd_goto(0);
send_string("ACCESS"); //display ERROR!
lcd_goto(20);
send_string("DENIED");
led_red=1; //red light on
buzzer=1; //buzzer on
delay(8000);
buzzer=0; //buzzer off
delay(13000);
buzzer=1; //buzzer on
delay(8000);
buzzer=0; //buzzer off
while(1);
}
}
}
}
// scanning functions
//=========================================================================
void scanrow1(void)
{
if(RA3==0) //value '#'
{
while(RA3==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
testbit=testbit&0x00; //to clear the testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
}
void scanrow2(void)
{
if(RA3==0) // value 3
{
while(RA3==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==2) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA2==0) // value 2
{
while(RA2==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==1) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA1==0) // value 1
{
while(RA1==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==0) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA0==0) // value 0
{
while(RA0==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==2) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
}
void scanrow3(void)
{
if(RA3==0) // value 7
{
while(RA3==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
testbit=testbit&0x00; //clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA2==0) // value 6
{
while(RA2==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==5) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA1==0) // value 5
{
while(RA1==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==4) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA0==0) // value 4
{
while(RA0==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
if(sequence==3) //if the sequence of password is correct
{
testbit=testbit&0x01; //maintain testbit as 1
sequence+=1; //increase sequence by 1
}
else testbit=testbit&0x00; //else clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
}
void scanrow4(void)
{
if(RA1==0) // value 9
{
while(RA1==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
testbit=testbit&0x00; //clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
else if(RA0==0) // value 8
{
while(RA0==0)continue; //waiting the key to be released
if(init==0)lcd_clr(); //if init is clear, clear the lcd
lcd_goto(lcd_count);
send_char(0x2A); //send symbol '*'
testbit=testbit&0x00; //clear testbit
lcd_count+=1; //increase lcd_count by 1
password_count+=1; //increase password_count by 1
init=1; //set init
}
}
// LCD functions
//==========================================================================
void delay(unsigned long data)
{
for( ;data>0;data-=1);
}
void send_config(unsigned char data)
{
rs=0; //clear rs into config mode
lcd_data=data;
delay(50);
e_pulse();
}
void send_char(unsigned char data)
{
rs=1; //set rs into write mode
lcd_data=data;
delay(50);
e_pulse();
}
void e_pulse(void)
{
e=1;
delay(50);
e=0;
delay(50);
}
void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}
void lcd_clr(void)
{
send_config(0x01);
delay(50);
}
void send_string(const char *s)
{
unsigned char i=0;
while (s && *s)send_char (*s++);
}
please tell me what i need to add.