PDA

View Full Version : @Darrel Taylor Interrupt ;-)



Robson
- 30th August 2007, 22:22
Hi Darrel,
iīm using your last interrupt posting to me for a 16F913. But something is not working just like at the 16F872. I read the datasheet for the 16F913 and i think itīs the same parameter like 16F872.
I set all PORTS to DIGITAL I/O (this was really hard to find out for this device). I think they are ok so.

Maybe you know why the interrupt is not working.


DEFINE OSC 8
ADCON1 = %111
ANSEL = 0
CMCON0 = 7
LCDCON = %01000000
LCDSE0 = 0
LCDSE1 = 0

@ERRORLEVEL -306

RBCPins VAR Byte
LastPins VAR Byte
Lastpins = PORTB

INTCON.0 = 0
INTCON.3 = 1

TRISA = %00111000 ' RA0-2 OUT, RA3-5 INPUT
TRISB = %11100000 ' RB7 & RB6 PORTChange by Interrupt, RB5 Input Clicker as Input is not needed for Interrupt change
TRISC = %00000000

ON INTERRUPT GOTO MyINT

Main:
'...
'...
'...
GOTO Main

DISABLE
MyINT:
RBCpins = PORTB
IF RBCpins.7 <> Lastpins.7 THEN
DPO2 = 0
PAUSE 20
DPO1 = 0
PAUSE 40
DPO2 = 1
DPO1 = 1
ENDIF

IF RBCpins.6 <> Lastpins.6 THEN
DPO1 = 0
PAUSE 20
DPO2 = 0
PAUSE 40
DPO1 = 1
DPO2 = 1
ENDIF
INTCON.0 = 0
RESUME
ENABLE


thx Robson

Darrel Taylor
- 30th August 2007, 22:38
Maybe ....


IF RBCpins.7 <> Lastpins.7 THEN
Lastpins.7 = RBCpins.7
DPO2 = 0
PAUSE 20
DPO1 = 0
PAUSE 40
DPO2 = 1
DPO1 = 1
ENDIF

IF RBCpins.6 <> Lastpins.6 THEN
Lastpins.6 = RBCpins.6
DPO1 = 0
PAUSE 20
DPO2 = 0
PAUSE 40
DPO1 = 1
DPO2 = 1
ENDIF

Bruce
- 30th August 2007, 22:52
Are you setting INTCON.GIE somewhere not shown?

Darrel Taylor
- 30th August 2007, 23:04
That Horrible Nasty Wicked ON INTERRUPT sets GIE for you. :)

Bruce
- 30th August 2007, 23:20
Hmm! Maybe one more reason I don't use it...;o}

Darrel Taylor
- 30th August 2007, 23:29
Here's another reason ..., :eek:

You can't turn GIE off. If you do, it jumps to the handler then turns GIE back on.

LED1 VAR PORTB.0

ON INTERRUPT GOTO MyINT

Main:
PAUSE 500
INTCON.7 = 0
GOTO Main

DISABLE
MyINT:
TOGGLE LED1
RESUME

That will flash the LED via the Interrupt handler, even though no interrupts have occured.
<br>

Bruce
- 30th August 2007, 23:36
One more reason to use DT-INTS ehh..;o}

BTW: Nice work on the new interrupt routines Darrel. Most impressive.

Robson
- 30th August 2007, 23:58
Itīs not working. The INTCON registers seems to be the same, but nothing happens to PORTB change...
Oh i didnīt see your last post.
Is it not possible to work like before with RBCPins ... ?

What does Note1 means?
bit 7 GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6 PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5 T0IE: Timer0 Overflow Interrupt Enable bit
1 = Enables the Timer0 interrupt
0 = Disables the Timer0 interrupt
bit 4 INTE: RB0/INT External Interrupt Enable bit
1 = Enables the RB0/INT external interrupt
0 = Disables the RB0/INT external interrupt
bit 3 RBIE: PORTB Change Interrupt Enable bit(1)
1 = Enables the PORTB change interrupt
0 = Disables the PORTB change interrupt
bit 2 T0IF: Timer0 Overflow Interrupt Flag bit(2)
1 = TMR0 register has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1 INTF: RB0/INT External Interrupt Flag bit
1 = The RB0/INT external interrupt occurred (must be cleared in software)
0 = The RB0/INT external interrupt did not occur
bit 0 RBIF: PORTB Change Interrupt Flag bit
1 = When at least one of the PORTB general purpose I/O pins changed state (must be cleared in software)
0 = None of the PORTB general purpose I/O pins have changed state
Note 1: The appropriate bits in the IOCB register must also be set.

Robson
- 31st August 2007, 00:34
Oh i get it ;-)
Only to set
IOCB.7 = 1
IOCB.6 = 1

and it works !

Thanks a lot

with
INTCON.7 = 0 in the main loop the interrupt is repeating 2 times. Pushed 1x and release 1x.
With the IOCB only on change till the interrupt is executed.

Darrel Taylor
- 31st August 2007, 00:52
Oh, Very good!

I didn't even notice the 913 had individual enable bits for the RBC interrupts.
Sitting here with the datasheet too going, "It should work!" Doh!, wrong.

Nice job.
<br>

Darrel Taylor
- 31st August 2007, 00:59
BTW: Nice work on the new interrupt routines Darrel. Most impressive.
Thanks Bruce,

Let me know when you get the CAN module working. :D<hr>

Oh, and Robson,

I was just chit-chating with Bruce before.

INTCON.7 = 0 should not be in your program.

Sorry for the confusion.
<br>