PDA

View Full Version : DT instant interrupts with mister_e keypad



Tomexx
- 26th November 2008, 16:52
DT instant interrupts with mister_e keypad (16F628A)

I'm new to interrupts and tried DT instant interrupts by Darrel Taylor (thanks Darrel). The blinky works great with the INT_INT.

I want for my program to sleep until woken up by the keypad then go to keypad rutine and flash led as many times as the number pressed.

So I connected keypad's columns to PortB and tried to invoke RBC_INT. Spent few hours double checking everything. No luck.

I had the RBC_INT working with a switch on PortB.6 before and that part worked. Sometimes it will work after I cycle the power but on the first press only (press 5, flashes 5 times), after that it won't till I shut power off again. Sometimes it won't flash the led at all. So when it works, the keypad works as well

Schematic attached.


CMCON = 7 ' Set portA to i/o
DEFINE OSC 20

TRISA = %00000
TRISB = %01110000

INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
include "modedefs.bas"
include "keypad.bas"

'================================================= ======
' SCAN_ONCE is set to 1 as well as proper keypad settings inside the keypad.bas
'================================================= ======

LED_Grn var PortA.1
ctr var byte

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _Scan, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RBC_INT ; enable external (INT) interrupts

Main:
@ sleep
goto Main

'---[INT - interrupt handler]---------------------------------------------------
Scan:
gosub KeypadScan

for ctr = 1 to key
high led_grn
pause 200
low led_grn
pause 200
next ctr
@ INT_RETURN

end


As always any help appreciated,
Tom

Darrel Taylor
- 26th November 2008, 17:24
mister-e's keypad program wasn't written to use RBC interrupts.
He doesn't leave the pins in the right state after scanning. Only 1 row is left active, and the rest won't trigger an interrupt.

I think I overcame it awhile back, but I can't find the program at the moment.

Essentialy, after doing a scan, it just sets all keypad outputs low (RB0-3).
But it only left the one row active when a key was pressed.

Wish I could find it. :o
<br>

Tomexx
- 26th November 2008, 17:32
Oh no.
I was hoping to use that in my gate opener and run it from a battery, that's why I need the pic to sleep for 99.9% of the time.

In case you do find your version, please let me know. Till then I guess I'll have to forget about the battery and continually scan the keypad instead of interrupts...

Is there any other way to do it with interrupts and have pic sleeping in the main loop? Maybe another keypad rutine or something?

Thanks Darrel
Tom

Darrel Taylor
- 26th November 2008, 17:42
Woohoo! Found it.

http://www.picbasic.co.uk/forum/showpost.php?p=32457&postcount=9

The Rows and Columns may be different than yours. ?

The "fix" was
KeypadINT:
@ READKEYPAD _ByteA ; Get the keypress
TRISB=%11110000 ; Reset I/O's
PORTB=0 ; Set all columns LOW

But now it sounds like that whole program is what you want. (With some sleep time added)
Combination Gate Opener.

Check the rest of the thread. It developed further.

Tomexx
- 26th November 2008, 18:51
Works!!!

Quick question, why are you enabling the interrupts after the ASM-ENDASM not inside?



ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _Scan, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RBC_INT ; enable external (INT) interrupts


Why not this?


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




Also, why the funny indentation inside ASM-ENDASM? Remember, I'm new to interrupts and don't know assmebler :)
Thank you Darrel,
Tom

Darrel Taylor
- 26th November 2008, 20:02
Quick question, why are you enabling the interrupts after the ASM-ENDASM not inside?

Either way will work fine. But ...
Different types of interrupts, like Timers or CCP Capture, need to have things set-up before the interrupt is enabled. I just put it that way to show that you don't have to enable it inside that same ASM block. It can be done later in the program too (if needed).


Also, why the funny indentation inside ASM-ENDASM? Remember, I'm new to interrupts and don't know assmebler :)
The INT_LIST macro, or anything else that creates a label, must start in column 1.
The rest is arbitrary and cannot start in column 1.

It might look strange because I tried to line up the commas with the comment above the line just as a reminder of what the INT_Handler parameters are.
Guess it didn't work so good. :o
<br>