Ir al contenido

Paso 6 de 11

Habilitar interrupciones (GIE y TMR0IE)

Objetivo

Encender la cadena de habilitacion: limpiar TMR0IF, activar TMR0IE, GIE y arrancar el timer.

Sin GIE = 1 ninguna ISR se ejecuta — es el interruptor maestro global.

Secuencia del curso (Timer0): 1. BCF INTCON, TMR0IF — limpia bandera vieja 2. BSF INTCON, TMR0IE — habilita la fuente 3. BSF INTCON, GIE — habilita globalmente 4. BSF T0CON, TMR0ON — el contador empieza a correr

El bucle principal (bucle) puede quedar vacio: el LED lo movera la ISR en el paso 8.

  1. En inicio, despues de los dos CALL, agrega las cuatro lineas del bloque resaltado.
  2. Orden: limpiar TMR0IF antes de habilitar interrupciones.
  3. Compila sin errores.
  4. Si cargas en Proteus ahora, el LED aun no parpadea — falta el cuerpo de la ISR.
						        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:
        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
					
						        BCF     INTCON, TMR0IF
        BSF     INTCON, TMR0IE
        BSF     INTCON, GIE
        BSF     T0CON, TMR0ON
					
  • Agregué las cuatro lineas de habilitacion en inicio.
  • Se que GIE es obligatorio para cualquier ISR.
  • Compila sin errores.