Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem with interrupt exteral in PIC16f887

Status
Not open for further replies.

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
Capture.JPG
 

What is not working? What are you expecting it to do that it is not?
Have you tried using a debugger and seeing how far you get through the code?
Just a quick look at your code (and I must admit I don't use assembler myself) but I think you have the FOSC config bit set to an external oscillator but according to your circuit diagram you have not provided one. Try changing that config setting to one of the INTOSC settings so that at least you will have some form of oscillator - without one then nothing will happen at all.
Also turn off the brown-out checks - again they are a complication that you really don;t want to deal with when you are getting started.
If you are starting out with these devices, then don't use interrupts. It is much better you write a continuous loop and check the status of your input pin and set the output pin accordingly. This is MUCH simpler and you can get the whole thing going more easily. Once that is working then you can start adding the complications to make the program 'useful'.
By the way, there is a world of pain waiting for you if you try to use a mechanical switch on an input pin without some form of debouncing. At this stage, where you are simply turning a LED on and off when the button is pressed or released, then you will not see any problems and so this is a good place to get started, BUT one of the first things you should do after that is to read up on debouncing switches and try implementing that.
Susan
 
Try again by connecting led to pin 27 RD4 because this pin is not multiplexed to any module. By performing this you will be sure about your interrupt program if it's ok or not.
 

hello,

You don't use any delay between ON/OFF bit 0 PORTC , in your interrupt ?
so you can't see anything !

in your interupt , go to Restore context instead of exit_ISR even you don't detect RB0 bit interrupt
because you first SAVE the contexte.. you must restitute it before leaving the interrupt.

Check also, config bit !
Internal osc ?
if external RC , where it is ?

maybe other problems due to bank select ...

Code:
Message[302] C:\_MPLAB8\_MESPROJETS_ASM\_16F887\16F887_TEST.ASM 34 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\_MPLAB8\_MESPROJETS_ASM\_16F887\16F887_TEST.ASM 35 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\_MPLAB8\_MESPROJETS_ASM\_16F887\16F887_TEST.ASM 36 : Register in operand not in bank 0.  Ensure that bank bits are correct.
 
Last edited:
I did follow you: changed config bit and using Internal osc , inserted delay between bsc/bcf PORTC
but when i press button LED not light.
I don't know why MPLAB have message" Register in operand not in bank 0. Ensure that bank bits are correct".Arccoding datashet: TRISB, TRIS C,OPTION_REG in bank 1.
Please tell me why PORTB look like the under picture.thankyou bro to help me.



Code:
#include "p16F887.inc"

 ;CONFIG1
; __config 0xFFF7
 __CONFIG _CONFIG1, _FOSC_INTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_OFF
;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,5 ;select bank1
       movlw 0x01 ;RB0 is input
       movwf TRISB
       clrf TRISC
       bcf OPTION_REG,6
       bcf STATUS,5 ;return bank0
       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 Restore_context
ISR_program
	     bsf PORTC,0
         call Delay
         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

	   RETFIE
;=================================================
   
Delay
		movlw d'20'
		movwf cycle1
		movlw d'3'
		movwf cycle2
		decfsz cycle1
		goto $-1
		decfsz cycle2
		goto $-3
		return

     end


inter.JPG
 

hello

Code:
            ; Changement de banques
            ; ----------------------

BANK0    macro                ; passer en banque0
        bcf    STATUS,RP0
        bcf    STATUS,RP1
    endm

BANK1    macro                ; passer en banque1
        bsf    STATUS,RP0
        bcf    STATUS,RP1
    endm

BANK2    macro                ; passer en banque2
        bcf    STATUS,RP0
        bsf    STATUS,RP1
    endm

BANK3    macro                ; passer en banque3
        bsf    STATUS,RP0
        bsf    STATUS,RP1
    endm

; addd this to disable analog input...

     BANK3
     movlw 0x00
     movwf ANSEL  ;
     movwf ANSELH ;
    
    BANK1
     movlw 0x01
    movwf TRISB
    clrf TRISC
    
    BANK0
.... etc ..
 

Nooooooo.......

Please use 'banksel' instead. Follow it with the name of the register you want to access like this: 'banksel PORTA'.
I will make the assembler generate the correct STATUS,RP0 and STATUS,RP1 without having to know which bank it is in. Works for all registers, regardless of which bank they live in and it also works for bigger processors where there are more RP bits.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top