#include <main.h>
#include <lcd16x2.c>
#include <KBD4X3.c>
#use delay(clock=4000000)
#define OPEN_LED RC3
#define CLOSE_LED RC4
#define LOCK_LED RC5
#define BUZZER RC6
#define SOLENOID RC7
unsigned char pw_digit[4]={1,2,3,4}; // Fixed password
char digit[4]={0,0,0,0}; //Password entered by keypad will save in this array
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_4MHZ);
lcd_init();
kbd_init();
lcd_putc("\fTest1\n");
lcd_putc("Test2");
delay_ms(2000);
lcd_putc("\fTest3\n");
lcd_putc("Test4");
delay_ms(2000);
lcd_putc("\fEnter Password..\n");
while(1)
{
k=kbd_getc();
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
void keyarray()
{
char k=0;
for(i=0;i<4;i++)
{
k=kbd_getc();
if(k!=0)
{
digit[i]=k;
}
}
}
kbd_init() Must be called before any other function. ////
//// ////
//// c = kbd_getc(c) Will return a key value if pressed or /0 if not ////
//// This function should be called frequently so as ////
//// not to miss a key press.
void keyarray()
{
char k=0;
unsigned char i;
for(i=0; i<4; i++)
{
do {
k=kbd_getc();
}
while(k==0);
digit[i]=k;
}
}
if(digit[0]==pw_digit[0] && digit[1]==pw_digit[1] && digit[2]==pw_digit[2] && digit[3]==pw_digit[3]
Alexan sir, the function you suggested is working fine.
In next stage I want to implement number of wrong password entry and time out. When three time wrong password enter happen then it goes in locked state and require master password. And during password entry a some second of time is set, if user delayed in entering password it automatically goes to normal state in some second say 10 second.
For time out thing, I thought about using timer, so it will count accordingly.
I used this technique to compare the password if there any better way please suggest.
Code:if(digit[0]==pw_digit[0] && digit[1]==pw_digit[1] && digit[2]==pw_digit[2] && digit[3]==pw_digit[3]
I used this technique to compare the password if there any better way please suggest.
Code:if(digit[0]==pw_digit[0] && digit[1]==pw_digit[1] && digit[2]==pw_digit[2] && digit[3]==pw_digit[3]
for(i=0;i<4;i++)
{
if(digit[i] != pwdigit[i])
{
lcd_putc("\fWrong Password");
}
else
{
lcd_putc("\fRight Password");
}
}
Code:for(i=0;i<4;i++) { if(digit[i] != pwdigit[i]) { lcd_putc("\fWrong Password"); } else { lcd_putc("\fRight Password"); } } [\code][/QUOTE] \code is wrong so as you see the code tags don't work, you have to use /code. If you use the codetag icon you can avoid such mistakes
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?