Skip to content

Step 7 of 11

Minimal ISR: check flag and clear

Goal

Write the isr_alta skeleton: if Timer0, clear TMR0IF and return with RETFIE.

Required pattern in every ISR: 1. Check it is your interrupt (BTFSS TMR0IF) 2. Clear the flag (BCF TMR0IF) — otherwise infinite re-entry 3. RETFIE on exit

We do not save WREG/STATUS or toggle the LED yet — that is step 7.

  1. Replace lone RETFIE in isr_alta with the highlighted block.
  2. Leave isr_baja with only RETFIE (we do not use it in this exercise).
  3. Build and load HEX in Proteus.
  4. Program runs but LED stays fixed — normal at this step.
						        LIST    P=18F4550
        #include <P18F4550.INC>

        CONFIG  FOSC = HS
        CONFIG  WDT = OFF
        CONFIG  LVP = OFF
        CONFIG  PBADEN = OFF

        ORG     0x0000
        GOTO    inicio

        ORG     0x0008
        GOTO    isr_alta

        ORG     0x0018
        GOTO    isr_baja

        CBLOCK  0x20
temp_w
temp_status
        ENDC

init_gpio:
        BCF     TRISB, 0
        BCF     LATB, 0
        RETURN

init_timer0:
        MOVLW   B'00000111'
        MOVWF   T0CON
        MOVLW   B'01100111'
        MOVWF   TMR0H
        MOVLW   B'01101010'
        MOVWF   TMR0L
        RETURN

isr_alta:
        BTFSS   INTCON, TMR0IF
        GOTO    fin_isr
        BCF     INTCON, TMR0IF
fin_isr:
        RETFIE

isr_baja:
        RETFIE

inicio:
        CALL    init_gpio
        CALL    init_timer0
        BCF     INTCON, TMR0IF   ; limpia bandera antes de habilitar
        BSF     INTCON, TMR0IE   ; habilita interrupcion Timer0
        BSF     INTCON, GIE      ; maestro global
        BSF     T0CON, TMR0ON    ; arranca el timer
bucle:
        GOTO    bucle

        END
					
						isr_alta:
        BTFSS   INTCON, TMR0IF
        GOTO    fin_isr
        BCF     INTCON, TMR0IF
fin_isr:
        RETFIE
					
  • `isr_alta` checks TMR0IF before acting.
  • I clear TMR0IF before RETFIE.
  • Builds with no errors.