Hello,
I cannot get the interrupt to work correctly on the following code. Can anybody see what I am doing wrong?
Thanks
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
Direction
LookingFor
temp1
die1
temp2
die2
endc
cblock 0x70
W_Save
STATUS_Save
endc
org 0
goto Start
org 0x004 ; interrupt vector location
Init:
clrf PORTA ; Clears memory in file register A
clrf PORTB ; Clears memory in file register B
clrf PORTC ; Clears memory in file register C
clrf PORTD ; Clears memory in file register D
clrf PORTE ; Clears memory in file register E
bsf STATUS,RP0 ; select Register Bank
bsf IOCB,0
movlw 0x01
movwf TRISB ; Make RB0 input
clrf TRISD ; Make PortD all output
movlw b'10010000'
movwf INTCON
movlw b'00000111'
movwf OPTION_REG ; Maximum Prescale
bcf STATUS,RP0 ; back to Register Bank 0
return
ISR:
movwf W_Save ; Save context
movf STATUS,w
movwf STATUS_Save
btfsc INTCON,INTE
goto DieNumSel
goto ExitISR
DieNumSel:
movf TMR0,w ;grabs a value from TMR0 and stores in working reg.
movwf temp1 ;moves working reg to file temp1.
andlw b'00000111' ;Ands literal 00000111 to working reg
call Tabledie1 ;calls tabledie1
movwf die1 ;moves result of working to file die1
btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb.
goto DieNumSel
movf temp1,w
swapf temp1,w
andlw b'00000111'
call Tabledie2
movwf die2
btfsc die2,7
goto DieNumSel
;swapf die2
;movf die1,w
addwf die1,w
movwf PORTD
goto $
Tabledie1:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
Tabledie2:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
ExitISR:
movf STATUS_Save,w ; Restore context
movwf STATUS
swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would
swapf W_Save,w
retfie
Start:
call Init
rotate:
end
I cannot get the interrupt to work correctly on the following code. Can anybody see what I am doing wrong?
Thanks
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
Direction
LookingFor
temp1
die1
temp2
die2
endc
cblock 0x70
W_Save
STATUS_Save
endc
org 0
goto Start
org 0x004 ; interrupt vector location
Init:
clrf PORTA ; Clears memory in file register A
clrf PORTB ; Clears memory in file register B
clrf PORTC ; Clears memory in file register C
clrf PORTD ; Clears memory in file register D
clrf PORTE ; Clears memory in file register E
bsf STATUS,RP0 ; select Register Bank
bsf IOCB,0
movlw 0x01
movwf TRISB ; Make RB0 input
clrf TRISD ; Make PortD all output
movlw b'10010000'
movwf INTCON
movlw b'00000111'
movwf OPTION_REG ; Maximum Prescale
bcf STATUS,RP0 ; back to Register Bank 0
return
ISR:
movwf W_Save ; Save context
movf STATUS,w
movwf STATUS_Save
btfsc INTCON,INTE
goto DieNumSel
goto ExitISR
DieNumSel:
movf TMR0,w ;grabs a value from TMR0 and stores in working reg.
movwf temp1 ;moves working reg to file temp1.
andlw b'00000111' ;Ands literal 00000111 to working reg
call Tabledie1 ;calls tabledie1
movwf die1 ;moves result of working to file die1
btfsc die1,7 ;tests msb, if 1 go back to beginning to ensure no 1 in msb.
goto DieNumSel
movf temp1,w
swapf temp1,w
andlw b'00000111'
call Tabledie2
movwf die2
btfsc die2,7
goto DieNumSel
;swapf die2
;movf die1,w
addwf die1,w
movwf PORTD
goto $
Tabledie1:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
Tabledie2:
addwf PCL,f ;jump to
retlw b'10000000'
retlw b'00000001'
retlw b'00000010'
retlw b'00000011'
retlw b'00000100'
retlw b'00000101'
retlw b'00000110'
retlw b'10000111'
ExitISR:
movf STATUS_Save,w ; Restore context
movwf STATUS
swapf W_Save,f ; swapf doesn't affect Status bits, but MOVF would
swapf W_Save,w
retfie
Start:
call Init
rotate:
end