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.
Follow these steps
- Add the
CBLOCKblock withtemp_wandtemp_status(see cumulative file). - Complete
init_gpiowithBCF TRISB,0andBCF LATB,0+RETURN. - Do not edit ISRs yet.
- Build with no errors.
Your file so far
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
What you add in this step
CBLOCK 0x20
temp_w
temp_status
ENDC
init_gpio:
BCF TRISB, 0 ; RB0 salida (LED)
BCF LATB, 0 ; LED apagado
RETURN
Checklist before you continue
- I reserved temp_w and temp_status in CBLOCK.
- `init_gpio` sets RB0 as output and turns LED off.
- Builds with no errors.