• AVR Freaks

Hot!asembler pic16f877 dont finish the routine of interruption

Author
Blogger109
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/05/20 08:00:08
  • Location: 0
  • Status: offline
2020/06/04 21:04:29 (permalink)
0

asembler pic16f877 dont finish the routine of interruption

Hi everyone, i wanted to asked for help, because i have this code and when i execute it in PROTEUS, and a press a button like one in  RB4 to do the interruption routine, the routine never ends. before the routine ands, offcourse i clean the RBIF flag , but it keeps on doing the routine and never gets out.
 
 
 


List p=16f877
Include "P16F877.INC"
ACUM equ h'000C'
STAT equ h'000D'
#DEFINE BANCO0 BCF STATUS,5

;;***DECLARACION DE VARIABLES***;;
contador1 equ 20h
contador2 equ 21h
estado equ 23h

ORG 0X00
GOTO MAIN

ORG 0X04
goto INTERRUPCION ;
MAIN
;;CONFIGURAR PUERTOS
bsf INTCON,7 ;habilitar interrupciones, el registro INTCON esta en el banco 0
bsf INTCON,3 ;RB4-RB7 con INT
bcf INTCON,RBIF ;poner flag en cero;

bsf STATUS,5
; bsf OPTION_REG,6 ;flanco de subida
movlw 0xff
movwf TRISB ;RB4 y RB5 son entrada para INT
movlw b'00000000'
movwf TRISD ;salida para leds
bcf STATUS,5
 
bucle1
movlw b'00001111'
movwf PORTD
call Retardo
call Retardo
movlw 00h
movwf PORTD
call Retardo
goto bucle1



;;***DECLARACION DE SUBRUTINAS***;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Retardo
bucleR decfsz contador1,1
goto bucleR
decfsz contador2,1
goto bucleR
Return

;;;;*****DECLARACION DE RUTINA DE INTERRUPCION*****;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INTERRUPCION
MOVWF ACUM ; Copia el registro W temporalmente al registro acum
MOVF STATUS,W ; Guarda STATUS en el acumulador
BANCO0 ; para restaurarlos antes de volver
MOVWF STAT ; Copia el acumulador al registro STAT
;;;;;;;;;;;;;;;;;;;

clrf PORTD
movlw b'11110000'
movwf PORTD

MOVF STAT,W ; Guarda el contenido de STAT en el W
MOVWF STATUS ; Restaura el STATUS
SWAPF ACUM,F ; Da la vuelta al registro ACUM
SWAPF ACUM,W ; Vuelve a dar la vuelta al registro ACUM , sirva para devolver a W el valor que tenia antes de la interrupcion
bcf INTCON,RBIF

RETFIE


END

#1

8 Replies Related Threads

    Jordiw
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2020/05/21 02:58:55
    • Location: 0
    • Status: offline
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/05 09:58:32 (permalink)
    +2 (2)
    In your interrupt routine you also need to clear the mismatch condition by reading PortB
    #2
    upand_at_them
    Super Member
    • Total Posts : 531
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/05 10:57:17 (permalink)
    +1 (1)
    Put your interrupt code right at 0x04.  No reason to jump, it just wastes time.
    #3
    1and0
    Access is Denied
    • Total Posts : 10903
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/05 12:31:43 (permalink)
    +2 (2)
    In addition to what others said, you are saving your interrupt context into SFR registers and corrupting them.
     
     
    #4
    upand_at_them
    Super Member
    • Total Posts : 531
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/05 13:13:06 (permalink)
    +2 (2)
    The datasheet even has code showing how to save/restore context for interrupts.
    #5
    ric
    Super Member
    • Total Posts : 27629
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/05 15:41:56 (permalink)
    +3 (3)
    upand_at_them
    Put your interrupt code right at 0x04.  No reason to jump, it just wastes time.

    Agree.
    Worse still, when the code expands to use more than one page of FLASH memory, the GOTO at location 4 will cause a crash if the PC is not in page 0.
     
    1and0
    In addition to what others said, you are saving your interrupt context into SFR registers and corrupting them.

    The OP may not understand the terminology.
    You are using locations 0x0c and 0x0d in RAM to save the W and STATUS registers.
    You can't do that in a PIC16F877, General Purpose RAM startrs at locaton 0x20, not 0x0C, so plainly this interrupt service code has been copied from another smaller PIC.
    Then you have to consider that a PIC16F877 has banked memory, and you don't know which bank will be selected when the interrupt triggers, so you should use the 16 "global" locatoins up at addresses 0x70-0x7F for your interrupt storage..
    As mentioned, example code is shown in the PIC16F877 datasheet. As I recall the sample code doesn't save and clear the PCLATH register, which will be required for a large program if there are any GOTO or CALL instructions in your ISR.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    atferrari
    Super Member
    • Total Posts : 1419
    • Reward points : 0
    • Joined: 2004/07/08 13:09:24
    • Location: Buenos Aires - Argentina
    • Status: offline
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/09 02:46:29 (permalink)
    -1 (1)
    My suggestion
    Throw away that ISR and, as already suggested look into the datashet.

    The ISR must have
    Saving process of the 3 typical registers

    Code to identify what intertupt

    Code to deal with the intertupt

    Retrieving process of those 3 registers

    Return
    post edited by atferrari - 2020/06/09 02:48:23

    Agustín Tomás

    In theory, there is no difference between theory and practice. In practice, however, there is.

    http://cablemodem.fibertel.com.ar/atferrari/
    #7
    Jams100001
    Junior Member
    • Total Posts : 90
    • Reward points : 0
    • Joined: 2018/04/12 13:37:33
    • Location: MCHP Chandler
    • Status: offline
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/30 12:58:16 (permalink)
    0
    Andres,
    the above code but also
    Don't forget to clear the interrupt flag before returning otherwise you will immediately interrupt again.
    Jamus
    #8
    dan1138
    Super Member
    • Total Posts : 3625
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: asembler pic16f877 dont finish the routine of interruption 2020/06/30 15:32:38 (permalink)
    0
    @Blogger109,
    This code may work as you want:
            List p=16f877
            Include "P16F877.INC"
    ACUM    equ     h'0070'         ; Use common memory bank not the PIR1 register
    STAT    equ     h'0071'         ; Use common memory bank not the PIR2 register

    ;;***DECLARACION DE VARIABLES***;;
    contador1  equ  20h
    contador2  equ  21h
    estado     equ  23h

            ORG     0X00
            GOTO    MAIN

            ORG     0X04
    ;;;;*****DECLARACION DE RUTINA DE INTERRUPCION*****;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    INTERRUPCION:
            MOVWF   ACUM            ; Copia el registro W temporalmente al registro acum
            MOVF    STATUS,W        ; Guarda STATUS en el acumulador
            CLRF    STATUS          ; para restaurarlos antes de volver
            MOVWF   STAT            ; Copia el acumulador al registro STAT
    ;;;;;;;;;;;;;;;;;;;

            clrf    PORTD
            movlw   b'11110000'
            movwf   PORTD
            movf    PORTB,W         ; Clear Interrupt-On-Change match
            bcf     INTCON,RBIF     ; Clear Interrupt-On-Change flag

            MOVF    STAT,W          ; Guarda el contenido de STAT en el W
            MOVWF   STATUS          ; Restaura el STATUS
            SWAPF   ACUM,F          ; Da la vuelta al registro ACUM
            SWAPF   ACUM,W          ; Vuelve a dar la vuelta al registro ACUM , sirva para devolver a W el valor que tenia antes de la interrupcion

            RETFIE

    MAIN:
    ;;CONFIGURAR PUERTOS
            bsf     INTCON,3        ; RB4-RB7 con INT
            movf    PORTB,W         ; Clear Interrupt-On-Change match
            bcf     INTCON,RBIF     ; poner flag en cero;
            bsf     INTCON,7        ; habilitar interrupciones, el registro INTCON esta en el banco 0

            bsf     STATUS,5
    ;       bsf     OPTION_REG,6    ; flanco de subida
            movlw   0xff
            movwf   TRISB           ; RB4 y RB5 son entrada para INT
            movlw   b'00000000'
            movwf   TRISD           ; salida para leds
            bcf     STATUS,5

    bucle1:
            movlw   b'00001111'
            movwf   PORTD
            call    Retardo
            call    Retardo
            movlw   00h
            movwf   PORTD
            call    Retardo
            goto    bucle1

    ;;***DECLARACION DE SUBRUTINAS***;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Retardo:
    bucleR: decfsz  contador1,1
            goto    bucleR
            decfsz  contador2,1
            goto    bucleR
            Return

            END

    post edited by dan1138 - 2020/06/30 15:33:46
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5