Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 28th March 2008, 04:08 PM   #1
Default Problem with keypad code

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
Attached Files
File Type: txt key example.txt (1.5 KB, 35 views)

Last edited by pic_programm3r; 28th March 2008 at 04:11 PM.
pic_programm3r is offline  
Old 29th March 2008, 03:39 AM   #2
Default

Where's the rest of the code?

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


Torben
Torben is offline  
Old 29th March 2008, 04:25 AM   #3
Default

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.
Pommie is online now  
Old 29th March 2008, 05:57 AM   #4
Default

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 by pic_programm3r; 29th March 2008 at 06:11 AM.
pic_programm3r is offline  
Old 29th March 2008, 06:02 AM   #5
Default

Quote:
Originally Posted by pic_programm3r
the code builds and it works alright in the simulator.
Switch bounce? Simulator switches don't bounce.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline  
Old 29th March 2008, 06:04 AM   #6
Default

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
pic_programm3r is offline  
Old 29th March 2008, 06:07 AM   #7
Default

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 by Pommie; 29th March 2008 at 06:13 AM.
Pommie is online now  
Old 29th March 2008, 06:17 AM   #8
Default

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 is offline  
Old 29th March 2008, 06:54 AM   #9
Default

Quote:
Originally Posted by pic_programm3r
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
Torben is offline  
Old 29th March 2008, 07:20 AM   #10
Default

here is pretty much all the code that is required to run this program
Attached Files
File Type: txt key_example2.txt (5.3 KB, 16 views)
pic_programm3r is offline  
Old 29th March 2008, 07:32 AM   #11
Default

ermm..how to attached files in this forum?
fza is offline  
Old 29th March 2008, 07:39 AM   #12
Default 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
Attached Thumbnails
Problem with keypad code-circuit.jpg  
Attached Files
File Type: txt clock.txt (6.5 KB, 4 views)
fza is offline  
Old 29th March 2008, 07:50 AM   #13
Default

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.
Pommie is online now  
Old 29th March 2008, 07:54 AM   #14
Default

fza,

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

Mike.
Pommie is online now  
Old 29th March 2008, 10:48 AM   #15
Default

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
pic_programm3r is offline  
Reply

Tags
code, keypad, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Code problem: bypass not working? hotrodhed120 Micro Controllers 9 11th June 2007 03:23 PM
Problem in making assembly code ahsanbilal Electronic Projects Design/Ideas/Reviews 2 11th September 2006 07:21 AM
Question about the PIC chip lineup mramos1 Micro Controllers 23 31st May 2006 08:51 AM
Problem; Random pic performance timothyjackson Micro Controllers 7 19th February 2005 07:20 PM
Tough assembly program for the PIC16F84 asmpic Micro Controllers 34 3rd December 2004 07:50 PM



All times are GMT. The time now is 02:19 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker