Documente Academic
Documente Profesional
Documente Cultură
SISTEMAS MICROCONTROLADOS
TECLADO MATRICIAL
Como se aprecia en la siguiente imagen, cada botn del teclado est conectado a alguna de las
filas, por un lado; y por el otro, a alguna de las columnas.
Para tener un valor de referencia positiva conectamos las filas con resistencia de
Pull UP a Vcc. Para tener una referencia de GND debemos conmutar las columnas
con 0 lgico o GND en el caso de que todas las columnas estn habilitadas a GND
no exisistiria control sobre el teclado, mas bien deben conmutarse a GND de forma
ordenada como se muestra en la siguiente figura:
Registro OPTION_REG
RBPU - PORTB Pull-up enable bit (resistencia Pull Up del puerto PORTB)
o 0 - Resistencias pull-up del puerto PORTB estn deshabilitadas.
o 1 - Pines del puerto PORTB pueden estar conectados a las resistencias pull-up.
Keypad Library
The mikroBasic PRO for PIC provides a library for working with 4x4 keypad. The library routines
can also be used with 4x1, 4x2, or 4x3 keypad. For connections explanation see schematic at the
bottom of this page.
Library Routines
Keypad_Init
Keypad_Key_Press
Keypad_Key_Click
Keypad_Init
Returns Nothing.
...
Keypad_Init()
Keypad_Key_Press
Requires Port needs to be initialized for working with the Keypad library, see Keypad_Init.
kp = Keypad_Key_Press()
Keypad_Key_Click
Library Example
This is a simple example of using the Keypad Library. It supports keypads with 1..4 rows and 1..4
columns. The code being returned by Keypad_Key_Click() function is in range from 1..16. In this
example, the code returned is transformed into ASCII codes [0..9,A..F] and displayed on Lcd. In
addition, a small single-byte counter displays in the second Lcd row number of key presses.
program Keypad_Test
dim kp, cnt, oldstate as byte
txt as char[7]
main:
oldstate = 0
cnt = 0 ' Reset counter
Keypad_Init() ' Initialize Keypad
ANSEL = 0 ' Configure AN pins as digital I/O
ANSELH = 0
Lcd_Init() ' Initialize LCD
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
Lcd_Out(1, 1, "Key :") ' Write message text on LCD
Lcd_Out(2, 1, "Times:")
while TRUE
case 1
end select
if (kp <> oldstate) then ' Pressed key differs from previous
cnt = 1
oldstate = kp
else ' Pressed key is same as previous
Inc(cnt)
end if
Lcd_Chr(1, 10, kp) ' Print key ASCII value on LCD