PDA

View Full Version : Keypads HELP! hehe, Need advice and possible code.



wdmagic
- 22nd April 2013, 04:50
I have 5 4x4 matrix Keypads (Grayhills), and I have 5 74C922N IC's (Keypad Interfaces)

Now I am trying to use them but they want to use a few capacitors and other IC's in conjuction with the 922 Chip, What I would like is to only have the 922 chip, keypad, and PIC. If this is possible. I have not found good schematics for this, and am unsure what schematic would be best. I was hoping to use the Data Available pin to the INT (RB0) and tie the 4bit to (? PortC 0-3) I could use any pin as the data received. I can use the keypad.bas and tie the keypad strait to the PIC, but I would rather use these chips.

So what should I use a direct Keypad-PIC connection and software code keystrokes? or Use the 922 Chips with Supporting Chip & Capactors? or Other options someone here may provide.

My layout of code in my head right now appears like this.
on INT(RB0) set Variable X = PortC
send data received to 922 chip
continute program, program now uses variable X


PS, im only trying to use 1 keypad, I just noted that I have 5

Dave
- 22nd April 2013, 12:02
hey Wd, What are you talking about having to use more ic's than the 74C922? All you have to do is put a capacitor with the part to operate the oscillator and wala.... you have a keyboard decoder.... I used these IC's about 30 years ago and acording to the data sheet thay haven't changed. Just tie the tristate output control line low and connect the data available linr to the interrupt line.

wdmagic
- 22nd April 2013, 20:31
all the schematics in the data sheet use other chips to help the 922, depending on the configuration you want it uses a 7474, or 7404, or a nand gate. none of the schematics show only the chip. if youve got one please post it to me, I havent found one on the web yet.

wdmagic
- 22nd April 2013, 22:34
Dave I tried that, it gave me really erratic results, numbers were all over the place even above 16. , so i disconnected the 4 data lines to the pic, and tested the lines output

on the 922 Chip output, with 4 LEDS, pressing any key on pad repeatedly should output the same leds every time, however they blink like christmas lights.
on the PIC (when INT fired) it outputs 0, 16, 06 randomly each time INT fires.
tied the datalines back and now PIC does nothing till they are removed???

Here is the code I am using, although this doesnt solve the issue with the 922 chip outputting random bits


include "LCD_D.bas"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
TRISD = 0 ' PORTD is Display
TRISB = 1 ' PORTB is Input
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _KEYPRESS, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts

X VAR BYTE : X = 0

LCDOUT $FE, 2
Pause 1000

Main:
LCDOUT $FE, 2
LCDOUT $FE, $80
LCDOUT DEC X
PAUSE 500
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
KEYPRESS:
X = PORTB <<4 '922 Data lines 0,1,2,3 hooked to 4,5,6,7 of PORTB
@ INT_RETURN

wdmagic
- 22nd April 2013, 23:04
OK the Data Bits from the 922 Chip are working ok now, wrong capacitor was in circuit, i thought it was a .1 and it was a 10. so the 922 chip sends a data available while any key pressed and the 4 data lines go high in binary.

however the pic is not displaying anything but 0 on the LCD? ive even tried removing the <<4 just to get something out. nothing works. anyone see a problem?

elcrcp
- 23rd April 2013, 00:07
I think you have a mistake here


INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _KEYPRESS, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts

I belive it has to be like this ;


INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _KEYPRESS, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT_INT ; enable external (INT) interrupts

actually both are same but you may wanna try

PS: also "X = PORTB <<4" statement is wrong, change it to "X = PORTB >> 4"

wdmagic
- 23rd April 2013, 22:57
I tried both , it still only displays a 0

wdmagic
- 23rd April 2013, 23:10
EDIT: I got it working, it was the TRISB line, I didnt update it for the inputs past 0. So I added TRISB = %11111111 and now its reading the data, its funny though i must have some wires in wrong place because only one row reads corrects numbers all the others are way off, will have to check pinouts of keypad. but its working now :)

BEFORE EDIT:
Ok it was a bit confusing to make sure the INT was firing so I moved the code down to the INT, it places a 0 on LCD when a key is pressed so the interupt is working, but its not reading data on portB

heres a code update


include "LCD_D.bas"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
TRISD = 0 ' PORTD is Display
TRISB = 1 ' PORTB is Input
asm
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _KEYPRESS, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT0_INT ; enable external (INT) interrupts

X VAR BYTE : X = 0

LCDOUT $FE, 2
Pause 1000
Main:
PAUSE 500
GOTO Main
End
'---[INT - interrupt handler]---------------------------------------------------
KEYPRESS:
X = PORTB
X = X >> 4
LCDOUT $FE, 2
LCDOUT $FE, $80
LCDOUT DEC X
@ INT_RETURN

Dave
- 24th April 2013, 12:39
Well Chris, I'm glad you got it going. Did you learn anything? Do you still need those other support IC's? Thats all it takes is a little persiverance.

wdmagic
- 24th April 2013, 19:18
nope you dont these those other IC's, I notice when you start adding outside chips wether it be a temp sensor or a 40 pin digital IC, it has a adverse affect on the project if you have an error, because you cant always test the externals as well as the PIC, and settings can be crucial. a missing CAP, a wrong value CAP, and a TRIS statement was the major problems here. I couldnt find the problem because there was internal and external problems at the same time.

NOTE: I did have to add a capacitor to the KeyBounce pin on the 922.

Thanks

Demon
- 25th April 2013, 18:19
Just a little note:

This code fiirst moves cursor to top of screen, then moves cursors to beginning of line 1. That's the same thing.



LCDOUT $FE, 2
LCDOUT $FE, $80
LCDOUT DEC X


You can simplify that with:


LCDOUT $FE, 1, DEC X


It will clear the screen, move cursor to first line and display value.

Robert

Demon
- 25th April 2013, 18:25
Also, what happens if you try this?



X = PortB >> 4


Robert

.

wdmagic
- 25th April 2013, 22:46
yes thats how i had X set up at first, I just had the>> going the wrong way, I can now put it back like that .

on the screen clearing, ive got to stop using clear except when initializing because of LCD flicker, but i should be able to do

LCDOUT $FE, $80, DEC X , " " 'add spaces to cover excess leftover characters

That way all the other data on screen stays wile updateing line 1

Demon
- 26th April 2013, 01:32
That makes sense.