Keypad Decoder

knight

Member
Well now that we've solved the problem of the subscript error, i would like to ask for help with my program.

I'm using the 18X as a decoder. I have a 4x3 way matrix keypad. The rows are connected to 4 outputs from the chip (0-3) then fed back, though current limiting resistors to 3 inputs. By scanning through the outputs and inputs, when a certain key is pressed a certain output and a certain input will be high, thus the number can be determined.

The inputs are held low with 10k resistors to stop them floating (these were once removed to test if these were the fault described below, but to no effect.)

Here is the code, i will explain the problem at the end:
<code><pre><font size=2 face='Courier'>
'b0 is the code to be transmitted

main:
'this looks for the entry of the # key to show that a code is being entered
lookforhash: high 6 'Red LED
high 4
if pin0=1 then goto getcode 'waits for a # before beginning transmission of code
goto lookforhash

'this works out which number was pressed
getcode: low 6 'low Red LED
high 5 'High Orange LED

high 1 'checks for 1, 2 or 3
if pin2=1 then press1
if pin1=1 then press2
if pin0=1 then press3
low 1

high 2 'checks for 4, 5 or 6
if pin2=1 then press4
if pin1=1 then press5
if pin0=1 then press6
low 2

high 3 'checks for 7, 8 or 9
if pin2=1 then press7
if pin1=1 then press8
if pin0=1 then press9
low 3

high 4 'checks for 0 OR press of * indicating completion of code entry
if pin1=1 then press0
if pin2=0 then goto lookforhash
low 4

goto getcode


'this sends the code to the computer
transmitcode: 'serout 7, t2400, (b0) 'sends the number just entered to the computer
high 4 'Green LED high
sertxd (#b0)
pause 1000 'puts a break in
low 4 'green LED low
goto getcode 'checks for the next number


'the following sets b0 to the number entered
press1: let b0=1
goto transmitcode 'goes to seriel transmission

press2: let b0=2
goto transmitcode 'goes to seriel transmission

press3: let b0=3
goto transmitcode 'goes to seriel transmission

press4: let b0=4
goto transmitcode 'goes to seriel transmission

press5: let b0=5
goto transmitcode 'goes to seriel transmission

press6: let b0=6
goto transmitcode 'goes to seriel transmission

press7: let b0=7
goto transmitcode 'goes to seriel transmission

press8: let b0=8
goto transmitcode 'goes to seriel transmission

press9: let b0=9
goto transmitcode 'goes to seriel transmission

press0: let b0=0
goto transmitcode 'goes to seriel transmission

</font></pre></code>

As you can see it spends most of its time looking for the Hash key, but unfortunatly at the moment this is all it spends it doing. I've tried pushing every other key incase of a wiring mistake, but to no avail.

Any suggestions as to why it is not moving on would be appreciated.

Also any suggestions as to how to tidy the code (not that i need the space, but this is my Software Design major project, and i want it to look tidy.)
 

hippy

Ex-Staff (retired)
It looks like your code should detect key presses. It's probably best to go back to basics, remove the keypad, write a test program which toggles Ouput 4 every second or so and then have the PICAXE SERTXD the input pins value back to the PC. You can test the Output is toggling with a LED+R, and should be able to see the input pins activate when pulled up to +V with a bit of wire, and when connected to Out 4 you should see them follow the state of that pin. Do that for all output pins and input pins then it should be a simple case of putting the keypad in place.

Double check your wiring, and which pins are which on the keypad.

I'd also strongly recommend putting current limiting resistors or diodes on the outputs which drive the keypad, even though the keypad example circuit doesn't show that. If you don't, pressing two keys can short PICAXE outputs together and may destroy the chip.

Also, on your entry into 'getcode:', you don't set Output 4 low. Output 4 seems to be driving the keypad and a LED, and maybe there's some hardware interaction there.
 

Technical

Technical Support
Staff member
When you press the hash key down, it will jump out of top section. However as the hash key is still active and down it will instantly process another part of the code. Perhaps you have forgotten a 'low 4' at the start of getcode to sort this out - the hash column is still active all the time!?


Re-arranging the two bottom sections will gives you lots of code optimisation

<code><pre><font size=2 face='Courier'>
'the following sets b0 to the number entered
press9: let b0= b0 + 1
press8: let b0= b0 + 1
press7: let b0= b0 + 1
press6: let b0= b0 + 1
press5: let b0= b0 + 1
press4: let b0= b0 + 1
press3: let b0= b0 + 1
press2: let b0= b0 + 1
press1: let b0= b0 + 1

transmitcode:
'serout 7, t2400, (b0) 'sends the number just entered to the computer
high 4 'Green LED high
sertxd (#b0)
pause 1000 'puts a break in
low 4 'green LED low
let b0 = 0 'reset b0
goto getcode 'checks for the next number
</font></pre></code>


Edited by - Technical on 08/05/2006 13:15:51
 
Top