Skip to content

Step 10 of 11

Preview: RB4–RB7 interrupt (keyboard)

Goal

Understand how to enable RBIE for the matrix keyboard — bridge to Practice 2.

The same file already works with Timer0. For matrix keyboard (Practice 2) you will add another source in the same isr_alta:

- RBIE in INTCON — interrupt on RB4–RB7 change - Column pull-ups (BCF INTCON2, RBPU if using internal) - In ISR: scan rows, debounce, and clear RBIF by reading PORTB (hardware requirement)

Not required to test now; it is the next interrupt application in the course.

  1. Read the RBIE code block below — no need to integrate if your LED already blinks.
  2. Compare with RB4–RB7 in theory.
  3. Save guia-interrupciones.asm as a template for labs.
  4. Mark all steps 0–8 in the tracker.
						        LIST    P=18F4550
        #include <P18F4550.INC>

        CONFIG  FOSC = HS
        CONFIG  WDT = OFF
        CONFIG  LVP = OFF
        CONFIG  PBADEN = OFF

        ORG     0x0000
        GOTO    inicio

        ORG     0x0008            ; alta prioridad (08H)
        GOTO    isr_alta

        ORG     0x0018            ; baja prioridad (18H)
        GOTO    isr_baja

        CBLOCK  0x20
temp_w
temp_status
        ENDC

init_gpio:
        BCF     TRISB, 0      ; RB0 salida (LED)
        BCF     LATB, 0
        RETURN

init_timer0:
        MOVLW   B'00000111'    ; 16 bit, interno, PS 1:256
        MOVWF   T0CON
        MOVLW   B'01100111'
        MOVWF   TMR0H
        MOVLW   B'01101010'
        MOVWF   TMR0L
        RETURN

isr_alta:
        BTFSS   INTCON, TMR0IF
        GOTO    fin_isr

        ; guardar contexto minimo
        MOVWF   temp_w
        SWAPF   STATUS, W
        MOVWF   temp_status

        BCF     T0CON, TMR0ON
        BCF     INTCON, TMR0IF
        MOVLW   B'01100111'    ; recarga Timer0 (~2 s)
        MOVWF   TMR0H
        MOVLW   B'01101010'
        MOVWF   TMR0L
        BSF     T0CON, TMR0ON

        ; toggle LED en RB0
        BTFSC   LATB, 0
        GOTO    apagar_led
        BSF     LATB, 0
        GOTO    restaurar
apagar_led:
        BCF     LATB, 0

restaurar:
        SWAPF   temp_status, W
        MOVWF   STATUS
        MOVF    temp_w, W
fin_isr:
        RETFIE

isr_baja:
        RETFIE

inicio:
        CALL    init_gpio
        CALL    init_timer0
        BCF     INTCON, TMR0IF
        BSF     INTCON, TMR0IE
        BSF     INTCON, GIE
        BSF     T0CON, TMR0ON
bucle:
        GOTO    bucle

        END
					
						; --- Agregar en inicio (ademas de Timer0) para teclado ---
        BCF     INTCON2, RBPU    ; pull-ups PORTB (segun practica)
        BSF     INTCON, RBIE     ; cambio en RB4-RB7

; --- Dentro de isr_alta, despues de atender Timer0 ---
        BTFSS   INTCON, RBIF
        GOTO    fin_rb
        ; escanear teclado, antirrebote...
        MOVF    PORTB, W         ; limpia RBIF (obligatorio)
fin_rb:
					
  • My Timer0 + ISR program works and is saved.
  • I understand RBIE and why PORTB must be read.
  • I know Practices 2 and 5 use these ideas.