last_samurai
Newbie level 5
- Joined
- May 7, 2014
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 74
hi.
I'm using pic16f877a ,lcd , keypad 4x4,
i wrote a code for door lock
but I'm facing such a problem , i don't know exactly what is that mistake ,
Kindly help me if you can ,
thanks
-----------------------------------------------------------
#define press keypad_key_press()
#define click keypad_key_click()
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
char keypadPort at PORTd;
char kb;
char x;
char key_value;
char fromuser[4];
char password[4]={1,2,3,4};
char check;
char *ptr;
char i=0;
void show(char,char);
void init()
{
adcon1=7;
portc=0;
trisc=0;
lcd_init();
lcd_cmd(12);
keypad_init();
}
void startup()
{
portc=0b11111111;
delay_ms(100);
portc=0b00000000;
delay_ms(100);
lcd_out(1,1,"welcome");
delay_ms(200);
lcd_cmd(1);
ptr=&fromuser[0];
}
void main() {
init();
startup();
x=0;
while(kb!=4)
{ // 4 it mean the ON/c button
kb=keypad_key_press();
while(!kb);
fromuser[x]=kb;
show(kb,x);
x++;
}//end while
for(x=0;x<4;x++){lcd_chr(1,2,fromuser[x]+48);} //show saved pass
check=memcmp(fromuser,password,4);
if(check==0)lcd_out(2,2,"matching");
else
lcd_out(2,2,"not matching");
} //end main
void show(char key,char pos)
{
switch(key)
{
case 1:key_value=7;break;
case 2:key_value=4;break;
case 3:key_value=1;break;
case 4:key_value=30;break;
case 5:key_value=8;break;
case 6:key_value=5;break;
case 7:key_value=2;break;
case 8:key_value=0;break;
case 9:key_value=9;break;
case 10:key_value=6;break;
case 11:key_value=3;break;
}
lcd_chr(1,1+pos,key_value+48);
}
I'm using pic16f877a ,lcd , keypad 4x4,
i wrote a code for door lock
but I'm facing such a problem , i don't know exactly what is that mistake ,
Kindly help me if you can ,
thanks
-----------------------------------------------------------
#define press keypad_key_press()
#define click keypad_key_click()
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
char keypadPort at PORTd;
char kb;
char x;
char key_value;
char fromuser[4];
char password[4]={1,2,3,4};
char check;
char *ptr;
char i=0;
void show(char,char);
void init()
{
adcon1=7;
portc=0;
trisc=0;
lcd_init();
lcd_cmd(12);
keypad_init();
}
void startup()
{
portc=0b11111111;
delay_ms(100);
portc=0b00000000;
delay_ms(100);
lcd_out(1,1,"welcome");
delay_ms(200);
lcd_cmd(1);
ptr=&fromuser[0];
}
void main() {
init();
startup();
x=0;
while(kb!=4)
{ // 4 it mean the ON/c button
kb=keypad_key_press();
while(!kb);
fromuser[x]=kb;
show(kb,x);
x++;
}//end while
for(x=0;x<4;x++){lcd_chr(1,2,fromuser[x]+48);} //show saved pass
check=memcmp(fromuser,password,4);
if(check==0)lcd_out(2,2,"matching");
else
lcd_out(2,2,"not matching");
} //end main
void show(char key,char pos)
{
switch(key)
{
case 1:key_value=7;break;
case 2:key_value=4;break;
case 3:key_value=1;break;
case 4:key_value=30;break;
case 5:key_value=8;break;
case 6:key_value=5;break;
case 7:key_value=2;break;
case 8:key_value=0;break;
case 9:key_value=9;break;
case 10:key_value=6;break;
case 11:key_value=3;break;
}
lcd_chr(1,1+pos,key_value+48);
}