Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

comparing password on keypad !!!

Status
Not open for further replies.

hemnath

Advanced Member level 3
Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Visit site
Activity points
6,589
Hi,
I'm interfacing matrix keypad with pic 18F4520. 4Mhz internal oscillator, Compiler: CCS.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "18F4520.h"
#fuses XT
#use delay(clock = 4000000)
 
#include "flex_lcd.c"
#include "flex_kbd.c"
#include "kbd_buffer.c"
#include "string.h"
 
#define MAX_PASSWORD_SIZE  8
 
//==================================
void main()
{ 
    int8 password_array[MAX_PASSWORD_SIZE +1];
    
    lcd_init();
    kbd_init();   
    kbd_buffer_init();
    
    while(1)
    {
        lcd_putc("\fEnter Password:\n");
        
        // Get the password from keypad input by the user.  The password
        // can be from 1 to 8 digits.
        // The user must press '#' key to exit the password entry screen.
        // The user can press '*' key to backspace over chars.
        kbd_get_string(password_array, MAX_PASSWORD_SIZE);
        
        // Display the password that we just got.
        lcd_putc("\fPassword is:\n");
        printf(lcd_putc, "%s", password_array);
        
        delay_ms(3000); 
 
        if(password_array == 1234)
        {
            lcd_putc("\fCorrect Password\n");   
        }       
    }
}



I have entered the password 1234. But it doesn't display "correct password" on LCD. Why is it?
 
Last edited by a moderator:

I have entered the password 1234. But it doesn't display "correct password" on LCD. Why is it?

Perhaps, because you are retrieving and storing the password in an array and then comparing the array name, pointer constant value, to numerical value 1234.

The following are equivalent:

Code:
int8 * ptr;

ptr = &password_array[0];

ptr = password_array

The constant value contained in password_array is a pointer (memory address) which points to the first element of the array of the same name.

**broken link removed**

Code:
int8 password_array[MAX_PASSWORD_SIZE +1];
....
....
kbd_get_string(password_array, MAX_PASSWORD_SIZE); // password_array points to the first element 
....
....
if([COLOR="#FF0000"]password_array == 1234[/COLOR]) // pointer constant value is compared to 1234
{
	lcd_putc("\fCorrect Password\n");	
}

As the source for the kbd_get_string() routine is not available, it is difficult to advise you on the correct method of comparison.

If the kbd_get_string() does indeed retrieve the numerical values and store them as ASCII characters into seqential elements of the password_array, then you should use the strcmp() routine to perform the comparison.

C library function - strcmp()


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "18F4520.h"
#fuses XT
#use delay(clock = 4000000)
 
#include "flex_lcd.c"
#include "flex_kbd.c"
#include "kbd_buffer.c"
#include "string.h"
 
#define MAX_PASSWORD_SIZE  8
 
//==================================
void main()
{ 
    char password_array[MAX_PASSWORD_SIZE +1];
    char correct_password[] = "1234";
    
    lcd_init();
    kbd_init();   
    kbd_buffer_init();
    
    while(1)
    {
        lcd_putc("\fEnter Password:\n");
        
        // Get the password from keypad input by the user.  The password
        // can be from 1 to 8 digits.
        // The user must press '#' key to exit the password entry screen.
        // The user can press '*' key to backspace over chars.
        kbd_get_string(password_array, MAX_PASSWORD_SIZE);
        
        // Display the password that we just got.
        lcd_putc("\fPassword is:\n");
        printf(lcd_putc, "%s", password_array);
        
        delay_ms(3000); 
 
        if(strcmp(password_array, correct_password) == 0)
        {
            lcd_putc("\fCorrect Password\n");   
        }       
    }
}



Please post the source code for the kbd_get_string() routine for more definitive advice.

I'm not familiar with CCS and its builtin types, so I'm assuming there is a char type available


Hope this clears a few things up,

BigDog
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top