PDA

View Full Version : 4x4 Matrix Keypad Controller PIC with LED Confirmation of Data Received



wdmagic
- 13th December 2012, 23:09
I started out with a 74c922 but that didnt work many problems, so I designed this. it requires the PIC its hooked up to to receive the data after a pulse has been sent to its IRQ pin, then after the data has been received the PIC must send a pulse back to the Controller PIC's IRQ (RB0) to clear the data (which will let the user know data was sent and received by the LED)

Looking for some of you more knoledgeable programmers to tell me if you see a problem, or a better way, etc.... I am using the "On Interrupt's" right now till I get that down then I will learn that other package for IRQ's

Basic layout of code on the External PIC


ON Interrupt goto handler
handler
read data in on 4 pins your choice and store in a variable
send a high to RB0 on the Controller PIC with a pin of your choice
pause 10
exit handler
resume

now for the Controller PIC's Code

TRISA = %11110000
TRISB = %00000001
OUT VAR Byte

on Interrupt Goto MYINT ' Define interrupt handler
INTCON = $90 ' Enable INT0 interrupt
OPTION_REG = $7f 'PORTB Pull Up
LOOP:
'************Clear All data**************************
PORTA = 0
out = 16
PORTB.1 = 0
PORTB.2 = 0
'************Data Cleared, Start Data Collection*****
PORTB.4 = 1
if PORTA.4 = 1 then out = 0
if PORTA.5 = 1 then out = 1
if PORTA.6 = 1 then out = 2
if PORTA.7 = 1 then out = 3
PORTB.4 = 0
PORTB.5 = 1
if PORTA.4 = 1 then out = 4
if PORTA.5 = 1 then out = 5
if PORTA.6 = 1 then out = 6
if PORTA.7 = 1 then out = 7
PORTB.5 = 0
PORTB.6 = 1
if PORTA.4 = 1 then out = 8
if PORTA.5 = 1 then out = 9
if PORTA.6 = 1 then out = 10
if PORTA.7 = 1 then out = 11
PORTB.6 = 0
PORTB.7 = 1
if PORTA.4 = 1 then out = 12
if PORTA.5 = 1 then out = 13
if PORTA.6 = 1 then out = 14
if PORTA.7 = 1 then out = 15
PORTB.7 = 0
if out < 16 then goto send
Goto loop 'No Buttons Pressed, Check Again
'Loop will continue to send pulse for data ready till OUT = 16 (see MYINT)
SEND:
PORTA = out 'Will output to PORTA 0 - 3
if out > 15 then goto loop 'Failsafe for Bad Data
PORTB.1 = 1 'Send Data Ready Pulse for External Microprocessor's INT0 (RB0)
pause 5
PORTB.1 = 0 'Clear Pulse & External Microprocessor will run its Interrupt
goto send
' ****** Interrupt handler *******
Disable ' No interrupts past this point
MYINT: 'Should only be triggered during the SEND loop
out = 16 'Sets OUT to default, when returned to SEND loop, returns to LOOP
PORTB.2 = 1 'Signal Received LED ON
pause 1000 ' will be changed to 25 after program tests good.
PORTB.2 = 0 'Signal LED OFF
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable


Tell me what you think, ideas, options, etc...

mackrackit
- 14th December 2012, 04:45
You will want to get out of the habit of using LOOP as a label, in PBP3 LOOP in an instruction.

Is is best to get out of an ISR as fast as possible, set a flag for the main routine if a long (time wise) instruction needs carried out. Using ON INTERRUPT gets around this problem and you can get around it when using ASM interrupts but you will find it troublesome. So I would get rid of the PAUSE in the ISR all together.

wdmagic
- 15th December 2012, 01:19
ok i got that, moveing that out of the ISR is no problem.