Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with keypad code

Status
Not open for further replies.

pic_programm3r

New Member
Hi everyone,

I'm having a problem with the verification of a key code that i set for my Burglar Alarm system .

When i first power up the circuit a key is automatically pressed and the key counter automatically increments to 1 instead of staying at 0. Instead of entering 4 keys to verify the code it allows only 3 key presses since the key that was automatically pressed counted as 1 of the keys pressed.

After the 1st attempt at entering the code the circuit doesn't do this anymore as i am able to enter 4 key presses.

i cant figure out the problem that the hardware or the program code is having at power up.

Please see the attachment to see the code im using.

Thanks in advance
 

Attachments

  • key example.txt
    1.5 KB · Views: 197
Last edited:
Where's the rest of the code?

Are you sure this a code problem and not hardware? Can you show your schematic?


Torben
 
Your compiler should have given you a warning with this code,
Code:
    if(correct==4)               //correct code was entered
    {
        Alarm_enabled();
        correct=0; 
 
    else   //the code is incorrect
    {          
        incorrect_key();                   //show that the incorrect code was entered 
        correct =0;                //reset the code comparing bit to its default
          
    }

Note the lack of closing brace on the if statement.

Even when this is corrected, consider what will happen when correct=1.

Looking at the rest of the code, braces seem to be missing everywhere. Try indenting your code correctly and see if this helps you spot the errors.

Mike.
 
the code builds and it works alright in the simulator.
As for the schematic i cant attach it because the forum says its a invalid file, being a .sch file.

this is just a portion of the code that i copied from the main code which is a lot larger.

also im using a 3x4 keypad and for some reason the column that has the key numbers 7,8,9 when i press the key a random number appears such as 0,2,1. those keys seem to rotate around those number (0,1,2) on each key press and then at a random time the correct key number actually shows up. it only happens to this column.

same with the previous problem it works fine in the simulator but when used in the hardware it screws up. Because of this my keycode can be unlocked even though i appear to be pressing the wrong key. since 7,8,9 are replaced with 0,1,2


Thanks
 
Last edited:
i thought that may have been a problem but i've got a 150mS delay in the keypad scan routine and also another 200mS in that for loop
 
With the code posted above, the variable "correct" will never get above 1.

You have the equivalent of,
Code:
    if correct = 4
        correct=0
    else
        correct=0
    endif

Edit, looks like I'm getting confused with your braces. Maybe you should post all your code.

I assume you based this on the code I posted on your other thread. Did that not work as expected?

Mike.
 
Last edited:
yes i have based it around that other thread. the variable increments each time a correct key has been pressed.
This is for a different part of the code that i had previously thought was working perfectly.
i had to use a for loop to make sure that i could get exactly 4 digits to compare with the 4 digit code that i had set.
 
pic_programm3r said:
yes i have based it around that other thread. the variable increments each time a correct key has been pressed.
This is for a different part of the code that i had previously thought was working perfectly.
i had to use a for loop to make sure that i could get exactly 4 digits to compare with the 4 digit code that i had set.

I agree with Mike--I don't see how that code could even compile, much less work.

Can you please post the entire file exactly as it compiles for you?


Torben
 
need help

Hello there.. I really need your help for my project. I design automatic fish feeder. I used alarm clock concept. I use PIC16F690 and need to program it in assembly language. I try to work on it but it doesn’t work in my circuit. I really need help as soon as possible.. Here I give you my coding and my circuit. Hope you can help me and get my coding function on my circuit.. Thank you
 

Attachments

  • clock.txt
    6.5 KB · Views: 129
  • circuit.JPG
    circuit.JPG
    67.1 KB · Views: 158
I think your original problem is caused by not turning on the WPUs on PortB. Your delay routine does turn them on but this isn't called until after the first key read. Try adding OPTION=2; to your setup routine.

Mike.
 
fza,

You diagram shows a 4MHz crystal but your config selects the internal oscillator at 32k.

Mike.
 
what is the WPU?
Is it the pull up resistors? If it is i have enabled them in a couple of previous keypad programs and it caused some other problem. But i'll try it anyway.

Or how about adding in a 100mS delay routine straight after the setup routine.

Cheers
 
fza said:
if possible, can you reply me through my email.. *******@yahoo.com

Hi FZA,

Can you please start your own thread instead of hijacking someone else's? It just makes it hard to follow which conversation is which. Thanks.

One hint: it's not really a good idea to put your email address on the web like that, since spambots will harvest it and you will probably start getting ridiculous amounts of spam in your email. Also, we like to respond here on the forum, where everyone can make use of the information, instead of hiding it for only one person by using direct email.


Good luck!

Torben
 
Thanks Mike.

Adding OPTION =2 in the setup did correct the first problem of a key being automatically pressed. I'm not sure how this corrected the problem.
Could you please tell me.


Thanks again
 
By setting OPTION=2; you reset bit 7 of the option register. When bit 7 is zero it turns on the weak pullup resistors on Port B.

Mike.
 
hi mike

any ideas on the second problem which i'm currently testing. the keys in the column of 7,8,9 are outputting random numbers that are in each of their columns. Such as column 7 has 1,4,*, column 8 with 2,5,0.
it does sometimes output the correct key in random order with the incorrect keys.

thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top