View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
keypad !!! |
Posted: Sun Feb 16, 2014 11:50 pm |
|
|
Hi, I'm using PIC18F4520, 4Mhz clock, Compiler: CCS 4.114.
Below is the code i used for keypad. Everything is working good. I want to compare the password and display a message. But it's not working.
Code: | #include "18F4520.h"
#fuses XT
#use delay(clock = 4000000)
#include "flex_lcd.c"
#include "flex_kbd.c"
#include "kbd_buffer.c"
#define MAX_PASSWORD_SIZE 8
//==================================
void main()
{
int8 password_array[MAX_PASSWORD_SIZE +1];
char msg[];
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");
sprintf(msg, "%s", password_array);
printf(lcd_putc, "%s", password_array);
delay_ms(3000);
if(msg == 12345678)
{
lcd_putc ("\fcorrect Password\n");
delay_ms(3000);
}
}
} |
Please help. thanks in advance |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Feb 17, 2014 12:41 am |
|
|
What isn't working? Does it display anything? How about giving us a clue as to what isn't working ???? _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Mon Feb 17, 2014 1:43 pm |
|
|
There are numerous problems here:
1) msg is a char string and you're directly trying to check if it's equal to a super long value 12345678... int8 is 8-bits (one byte). 12345678 is 3 bytes long...
You should do like:
Code: | if( strcmp( msg, "12345678" ) == 0 )
{
password is ok
} |
But that still won't work because you have type issues and such.
2) your password_array is a int8 structure... that you're later trying to compare to a character string (no.1 above)...
I also suggest you use unsigned int and unsigned char as opposed to simple int and char as you may end-up with values from -127 to 127 instead of 0-255.
You should perhaps consider comparing characters one by one in a for loop.
I don't have the time at the moment to write something-up for you but you need to fix these issues first...
Just out of curiosity, do you know C programming at all or is this a little project trying to learn PIC development and C at the same time?
Benoit |
|
|
|