Ir al contenido

Paso 4 de 11

Variables en RAM y GPIO del LED

Objetivo

Reservar temp_w y temp_status en RAM y configurar RB0 como salida del LED.

La ISR va a usar WREG y STATUS. Si no los guardas, el programa principal se corrompe al volver de RETFIE.

Reserva dos bytes con CBLOCK / ENDC (estilo sandwich del curso). En init_gpio configura TRISB y apaga el LED con LATB.

  1. Agrega el bloque CBLOCK con temp_w y temp_status (ver archivo acumulado).
  2. Completa init_gpio con BCF TRISB,0 y BCF LATB,0 + RETURN.
  3. No toques las ISR todavia.
  4. Compila sin errores.
						        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      ; RB0 salida (LED)
        BCF     LATB, 0       ; LED apagado al arrancar
        RETURN

init_timer0:
        RETURN

isr_alta:
        RETFIE

isr_baja:
        RETFIE

inicio:
        CALL    init_gpio
        CALL    init_timer0
bucle:
        GOTO    bucle

        END
					
						        CBLOCK  0x20
temp_w
temp_status
        ENDC

init_gpio:
        BCF     TRISB, 0      ; RB0 salida (LED)
        BCF     LATB, 0       ; LED apagado
        RETURN
					
  • Reservé temp_w y temp_status en CBLOCK.
  • init_gpio configura RB0 como salida y apaga el LED.
  • Compila sin errores.