modifyit
- 19th September 2005, 02:02
I've been trying to get a handle on how to write an assembly interrupt, but I feel like I am missing something simple.
The example given in the Pic Basic Pro manual makes sense, but I'm not sure exactly what to do since the 877a has 4 banks of RAM. I realize I need to save the W and Status register and that I am supposed to reserve a system variable in each bank similar to the following:
--------------
wsave var byte $20 system
wsave1 var byte $a0 system ' If device has RAM in bank1
wsave2 var byte $120 system ' If device has RAM in bank2
wsave3 var byte $1a0 system ' If device has RAM in bank3
--------------
The following is the example given in the PBP manual, but it appears it is an example for a chip with a single bank of RAM. How do I convert the following code so it will work on the 877a and save "wsave1" and "wsave2" etc when needed?
--------------
' Assembly language interrupt example
led var PORTB.1
wsave var byte $20 system
ssave var byte bank0 system
psave var byte bank0 system
Goto start ' Skip around interrupt handler
' Define interrupt handler
define INTHAND myint
' Assembly language interrupt handler
asm
; Save W, STATUS and PCLATH registers
myint movwf wsave
swapf STATUS, W
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave
; Insert interrupt code here
; Save and restore FSR if used
bsf _led ; Turn on LED (for example)
; Restore PCLATH, STATUS and W registers
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
retfie
endasm
' PICBASIC PRO™ program starts here
start: Low led ' Turn LED off
' Enable interrupt on PORTB.0
INTCON = %10010000
loop: Goto loop ' Wait here till interrupted
--------------
Thanks in advance for any help
The example given in the Pic Basic Pro manual makes sense, but I'm not sure exactly what to do since the 877a has 4 banks of RAM. I realize I need to save the W and Status register and that I am supposed to reserve a system variable in each bank similar to the following:
--------------
wsave var byte $20 system
wsave1 var byte $a0 system ' If device has RAM in bank1
wsave2 var byte $120 system ' If device has RAM in bank2
wsave3 var byte $1a0 system ' If device has RAM in bank3
--------------
The following is the example given in the PBP manual, but it appears it is an example for a chip with a single bank of RAM. How do I convert the following code so it will work on the 877a and save "wsave1" and "wsave2" etc when needed?
--------------
' Assembly language interrupt example
led var PORTB.1
wsave var byte $20 system
ssave var byte bank0 system
psave var byte bank0 system
Goto start ' Skip around interrupt handler
' Define interrupt handler
define INTHAND myint
' Assembly language interrupt handler
asm
; Save W, STATUS and PCLATH registers
myint movwf wsave
swapf STATUS, W
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave
; Insert interrupt code here
; Save and restore FSR if used
bsf _led ; Turn on LED (for example)
; Restore PCLATH, STATUS and W registers
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
retfie
endasm
' PICBASIC PRO™ program starts here
start: Low led ' Turn LED off
' Enable interrupt on PORTB.0
INTCON = %10010000
loop: Goto loop ' Wait here till interrupted
--------------
Thanks in advance for any help