Step 6 of 11
TRIS: RB0 output, RB1 input
Goal
Set pin directions in init_gpio with TRISB before using LAT or PORT.
In TRIS: 0 = output, 1 = input. BCF TRISB, 0 → RB0 output (LED). BSF TRISB, 1 → RB1 input (button).
Rule: always TRIS before LAT/PORT. Without this step the LED will not respond even if you write LAT.
Follow these steps
- In
init_gpio, replace loneRETURNwith the two TRIS lines +RETURNfrom the highlighted block. - Do not change
inicioorbucleyet. - Build — should still succeed.
- Do not simulate yet — Proteus schematic comes in step 6.
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
init_gpio:
BCF TRISB, 0 ; RB0 salida (LED)
BSF TRISB, 1 ; RB1 entrada (pulsador)
RETURN
inicio:
CALL init_gpio
bucle:
GOTO bucle
END
What you add in this step
init_gpio:
BCF TRISB, 0 ; RB0 salida (LED)
BSF TRISB, 1 ; RB1 entrada (pulsador)
RETURN
Checklist before you continue
- `init_gpio` has BCF TRISB,0 and BSF TRISB,1 before RETURN.
- Builds with no errors.
Tip: TRIS does not turn the LED on — it only sets direction.