Skip to content

Step 4 of 11

RAM variables and LED GPIO

Goal

Reserve temp_w and temp_status in RAM and set RB0 as LED output.

The ISR will use WREG and STATUS. If you do not save them, main code corrupts after RETFIE.

Reserve two bytes with CBLOCK / ENDC (course sandwich style). In init_gpio set TRISB and turn LED off with LATB.

  1. Add the CBLOCK block with temp_w and temp_status (see cumulative file).
  2. Complete init_gpio with BCF TRISB,0 and BCF LATB,0 + RETURN.
  3. Do not edit ISRs yet.
  4. Build with no errors.
						        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
					
  • I reserved temp_w and temp_status in CBLOCK.
  • `init_gpio` sets RB0 as output and turns LED off.
  • Builds with no errors.