msterdang
Newbie
- Joined
- Mar 30, 2015
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 18
i wrote asm code for interrupts enternal (RB0) to turn on LED with button but i don't it not working.Can you help me?
Code:
#include "p16F887.inc"
;CONFIG1
; __config 0xFFF7
__CONFIG _CONFIG1, _FOSC_EXTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_ON
;CONFIG2
; __config 0xFFFF
__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF
org 0x00
goto main
org 0x04 ;interrupt vector location
goto Interrupt
;=================================================
cblock 0x20
cycle1,cycle2,W_SAVE,STAT_SV,PCH_SV,FSR_SV
ENDC
;==================================================
org 0x05
main
bsf STATUS,RP0
movlw 0x01;RB0 is input
movwf TRISB
clrf TRISC
bsf OPTION_REG,6
bcf STATUS,RP0
bcf PORTC,0
bsf INTCON,4
bsf INTCON,7
GOTO $
;=======================================
Interrupt
;---------Save context-------
movwf W_SAVE ;save WREG
swapf STATUS,w ;movf affects Z bit,
clrf STATUS ;use swapf instead
MOVWF STAT_SV ; STAT_SV = swap_nibbles
MOVF PCLATH, W
MOVWF PCH_SV ; PCH_SV = PCLATH
clrf PCLATH
movf FSR,w
MOVWF FSR_SV ; FSR_SV = FSR
;-----------------------------
;program in here
btfsc INTCON,INTF ;
goto ISR_program
goto exit_ISR
ISR_program
bsf PORTC,0
bcf PORTC,0
bcf INTCON,1;clear int0if
;--------------------------------
;Restore_context:
MOVF FSR_SV, W
MOVWF FSR ; FSR = FSR_SV
MOVF PCH_SV, W
MOVWF PCLATH ; PCLATH = PCH_SV
SWAPF STAT_SV, W
MOVWF STATUS ; STATUS = swap_nibbles
SWAPF W_SAVE,F
SWAPF W_SAVE, W ; W = swap
BSF INTCON, GIE
exit_ISR
RETFIE
;=================================================
Delay
movlw d'20'
movwf cycle1
movlw d'3'
movwf cycle2
decfsz cycle1
goto $-1
decfsz cycle2
goto $-3
return
end