This is an example of what I mentioned earlier.
I'll call it FAKE INTERRUPT
It does have a latency of a little over a millisecond, but often it is plenty good enough to do what you need done. You can make the interrupt faster if you wish - but remember each time you enter/leave an interrupt, you are stealing quite a few processor cycles.
This code will check the status of any pin once per millisecond. It was written for an 18Fxxxx at 40Mhz. This example is checking the status of PORTC.0.
Code:
Changed VAR BYTE
OldPort VAR BYTE
T0CON = %10001000 ; turn it on, 16 bits, no prescaler (osc/4)
CLEAR
'----------------- DT_INTS section ----------------------------
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, _FakeInt, PBP, yes
endm
INT_CREATE
ENDASM
Goto OverInt
'------------------ Timer 0 interrupt handler-----------------------------------
FakeInt:
TMR0H = $D8 ; Preload depends on clk speed
TMR0L = $F7 ; One millesecond timeout at 40Mhz.
; Always load HIGHBYTE FIRST
Changed = PortC ^ OldPort
IF Changed.0 = 1 THEN ; Pick your pin
OldPort = PortC
;;;; Whatever you want to do when Port bit changes
ENDIF
@ INT_RETURN
Overint:
OldPort = PortC ; Init the var
@ INT_ENABLE TMR0_INT
NormalProgramLoop:
Goto NormalProgramLoop
END
Bookmarks