Skip to content

Instantly share code, notes, and snippets.

@jerivas
Last active May 29, 2024 23:24
Show Gist options
  • Save jerivas/6382489 to your computer and use it in GitHub Desktop.
Save jerivas/6382489 to your computer and use it in GitHub Desktop.
Control de teclado matricial 4x4
;Control de teclado matricial 4x4
;José Eduardo Rivas Melgar RM100161
;David Antonio Escobar Contreras EC100119
;Angel Gerardo Moreno Galan MG070209
;Escanea un teclado matricial de 4x4 y muestra la ultima teclada presionada
;en base 16 en un display de 7 segmentos.
title "Control de teclado matricial"
list p=18f4550
#include <p18f4550.inc>
;Directivas para activar los bits de configuracion
config FOSC = INTOSCIO_EC ;Oscilador Interno, Puerto A RA6 activo,
config WDT = OFF ;Watchdog timer apagado
config PBADEN = OFF ;Parte baja del puerto B digitales
config MCLRE = ON ;MCLRE Disponible
config DEBUG = ON ;Modo de depuracion disponible
config LVP = OFF ;Fuente de ISCP apagada
;------------------------
;DEFINICION DE CONSTANTES
;------------------------
#define display LATD ;PORTD como salida de displays
;Tabla de códigos para display de 7 segmentos
#define cod0 b'00111111' ;0
#define cod1 b'00000110' ;1
#define cod2 b'01011011' ;2
#define cod3 b'01001111' ;3
#define cod4 b'01100110' ;4
#define cod5 b'01101101' ;5
#define cod6 b'01111101' ;6
#define cod7 b'00000111' ;7
#define cod8 b'01111111' ;8
#define cod9 b'01101111' ;9
#define cod10 b'01110111' ;A
#define cod11 b'01111100' ;B
#define cod12 b'00111001' ;C
#define cod13 b'01011110' ;D
#define cod14 b'01111001' ;E
#define cod15 b'01110001' ;F
;----------------------------------------------
;DEFINICION DE MACROS
;http://goo.gl/Ow9gWx Chapter 5: Macro Language
;----------------------------------------------
scan_macro macro
;Escanear las 16 teclas y retornar con el valor presionado en W
local col = 0
local row = 0
while col <= 3 ;Se probaran las columnas del 0 al 3
bcf LATB,#v(col) ;Poner en bajo la columna
row = 0
while row <= 3 ;Se probaran las filas del 0 al 3
btfss PORTA,#v(row) ;La fila esta en alto?
retlw cod#v(4*col+row) ;No: retornar el codigo de la tecla
row++
endw ;Seguir probando filas
bsf LATB,#v(col) ;Volver a poner en alto la columna
col++
endw ;Seguir probando columnas
endm ;Fin de la macro
;--------------
;INICIALIZACION
;--------------
org 0
init:
clrf TRISD ;Configurar todo el puerto D como salida
clrf TRISB ;PORTB como salida
setf LATB ;PORTB en alto (switches activos en bajo)
clrf PORTA ;Limpiar PORTA
movlw 0Fh
movwf ADCON1 ;Deshabilitar A/D
movlw 07h
movwf CMCON ;Deshabilitar comunicacion
setf TRISA ;Configurar PORTA como entrada
movlw b'01000000' ;Codigo de estado "en espera"
;-----------------------------------------------------------------
;Programa principal:
;Rutina que muestra en el display la ultima tecla presionada
;-----------------------------------------------------------------
main:
setf LATB ;Poner PORTB en alto (teclas activas en bajo)
call scan ;Escanear las teclas. Se recibe el codigo en W
movwf display ;Mostrar el codigo en el display
goto main ;Repetir
scan:
scan_macro ;Simplemente se llama a la macro
return ;Si no se presiono nada, no modificar W
end
@MathProcell
Copy link

hola

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment