CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

password

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
michmatar



Joined: 06 Aug 2014
Posts: 1

View user's profile Send private message

password
PostPosted: Wed Aug 06, 2014 8:14 am     Reply with quote

Hello everyone, i just want to ask you if you could help me with my code, i want to write a code that asks for a password and when i write the code it gives me correct pass if its correct or incorrect pass if its wrong
my code :
int first_key;
int second_key;
int third_key;
int fourth_key;
lcd_putc('\f');
lcd_gotoxy(1,1);
printf(lcd_putc,"Enter pin:");
delay_ms(10);
lcd_gotoxy(1,2);
while(!enter){
ad = kbd_getc();
if(ad!=' ') {
if(ad == '#') enter = true;
else { printf ( lcd_putc, "%c", ad);
posX++;
}
}
}

first_key=kbd_getc();
second_key=kbd_getc();
third_key=kbd_getc();
fourth_key=kbd_getc();
if((first_key =='1')&&(second_key =='2')&&(third_key =='3') &&(fourth_key =='4'))
{
lcd_putc('\f');
printf(lcd_putc,"incorrect pass");
delay_ms(10);
}
else
{
lcd_putc('\f');
printf(lcd_putc,"correct pass");
delay_ms(10);
}
}
the problem is when i type any number it gives me correct pass
any help?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 9:50 am     Reply with quote

Several points:-

!) Use the General Discussion section for this type of query.
2) Provide complete compilable code we can copy and paste to test.
3) Learn to use the code button.
4) Learn to indent code.
5) Read the forum guidelines.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 06, 2014 2:55 pm     Reply with quote

Your basic assumption is that kbd_getc() is similar to getc(), such that
it waits for a key to be pressed. Unfortunately, kbd_getc() doesn't work
that way. It needs to be polled continuously at a suitable interval.
Your code doesn't do that.

In this post below, I've written a little routine called keypad_getc().
It waits in a loop until a key is pressed, and then it returns the key:
http://www.ccsinfo.com/forum/viewtopic.php?t=41848&start=4
If you put that routine above main() and substitute keypad_getc()
for every place in your code where you have kbd_getc(), your program
will work better. To make this work, you have to edit kbd.c as follows:
Code:
#define KBD_DEBOUNCE_FACTOR  0


I didn't look at your code closely, so I don't guarantee all your problems
will be fixed. But this should fix part of it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group