Hi Peterdeco1,
I appreciate the feedback but unfortunately I have made a circuit board for this design which is already installed in a piece of equipment. If I cannot get this to work I’ll give your idea a try.
Thanks,
Mark
Hi Peterdeco1,
I appreciate the feedback but unfortunately I have made a circuit board for this design which is already installed in a piece of equipment. If I cannot get this to work I’ll give your idea a try.
Thanks,
Mark
Alternative...
Just modify the include to suite your requirementCode:include "C:\PBP_PROG\INCLUDE_ROUTINES\KeyPad.bas" define OSC 20 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_SPBRG 129 ' 9600 Baud @ 0.16% DEFINE HSER_CLROERR 1 ' Clear overflow automatically DEFINE KEYPAD_ROW 4 ' 4 ROW keypad DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB DEFINE KEYPAD_ROW_BIT 0 ' ROW0 = PORTB.4 DEFINE KEYPAD_COL 4 ' 4 COL keypad DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.0 DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature INTCON2.7=0 kKey var byte Start: @ READKEYPAD _kKey hserout ["Key=",dec kkey,13,10] goto start
kEYpAD.BAS... AVAILABLE BELLOW
http://www.picbasic.co.uk/forum/showthread.php?t=3250
and IN YOUR serout LINE...
AND now that some know you experiment a Write/Read/Modify behaviour... use your existing code but modify it likeCode:SEROUT serpin,N2400,[#key,#B0]'Send key value out PortA.1
What happen now ?Code:getkeyu:' Wait for all keys up LATB = 0 ' All output-pins low TRISB = $f0 ' Bottom 4-pins out, top 4-pins in @ nop IF ((PORTB >> 4) != $f) THEN getkeyu'If keys down, loop PAUSE 50 ' Debounce key-input getkeyp:' Wait for keypress FOR row = 0 TO 3 ' 4 rows in keypad LATB = 0 ' All output-pins low TRISB = (DCD row) ^ $ff ' Set one row pin to output @ nop col = PORTB >> 4 ' Read columns IF col != $f THEN gotkey' If any keydown, exit NEXT row GOTO getkeyp ' No keys down, go look again
Last edited by mister_e; - 22nd November 2006 at 19:16.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
If you still have problem after Steve's suggestions, please check the circuits. Better send the circuit here to see how you connected the buttons to the PIC. I suspect noise from some lines.
Ioannis
FYI, using his code, i had similar problem as markcadam, so i decide to use my 'easy to use' INCLUDE with the same PIC and crystal... confirm that my hardware was good (EasyPIC4 + Keypad 4X4 adapter). Worked with internal pull-up AND external (of course).
Then i worked around his code. Use LATB intead of PORTB to write to the port for safety sake. On a whole port write, it doesn't really matter.. but when you write to few bit .. it may cause some problem. In this case leaving PORTB AS IS, will work anyways.
Writing to PORT before TRIS is also for safety sake even if some don't believe itBut if you leave it like this... it still working.. but sometimes you have some screwed values
BUT the real magic is in the @ nop. remove those lines and the readings are screwed up.. or intermittent. just by this famous PIC18Xxxxx feature called 'Read/Modify/write' behaviour.
18Fs are much noise sensitive.. so i would avoid to use internal weak-pull-ups... IMHO.. you know i hate those anyways![]()
Last edited by mister_e; - 23rd November 2006 at 07:51.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
mmm, just double/triple/quad check the whole thing...
it appear that the TRIS work better if before the PORT/LATB line ....DOH!
BUT if you want to use the 'Microchip says' approach (write to PORT before TRIS), replace @ nop by @ GOTO $+2
That way... it works ... a treat
M.F.Sorry!
Last edited by mister_e; - 23rd November 2006 at 08:15.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi Steve. Doesn't @ GOTO $+2 being equal to jump to next instruction? Also the same as NOP. So whats the difference?
Ioannis
Bookmarks