Skip to content

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.

  1. In init_gpio, replace lone RETURN with the two TRIS lines + RETURN from the highlighted block.
  2. Do not change inicio or bucle yet.
  3. Build — should still succeed.
  4. Do not simulate yet — Proteus schematic comes in step 6.
						        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
					
						init_gpio:
        BCF     TRISB, 0      ; RB0 salida (LED)
        BSF     TRISB, 1      ; RB1 entrada (pulsador)
        RETURN
					
  • `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.