pic18f14k50: teclado matricial 4x4

3
Por: Omar Gurrola 2/22/13 http://www.proprojects.wordpress.com PIC18F14K50: Teclado Matricial 4x4 Realizar un dispositivo que lea un teclado matricial de 4x4 y despliegue la letra presionada en un digito de 7 segmentos. La ventaja de utilizar este tipo de teclados es la reducción de pines requeridos, ya que para leer 16 teclas se utilizan únicamente 8 pines. Para leer un teclado de este tipo se debe realizar un barrido en los renglones o columnas ya sea con uno o con cero. Para este ejemplo el barrido se realizara en los renglones con uno y se leerá el valor de las columnas. También debemos considerar que son botones mecánicos y se genera ruido al ser presionado y debemos esperar unos 50ms para determinar cuál fue la tecla presionada. El siguiente diagrama de flujo se encarga de obtener la tecla presionada con cualquiera de los siguientes métodos: Lock: Espera a que se presione una tecla. Release: Manda la tecla hasta que se suelte.

Upload: dragoon-micromar

Post on 21-Mar-2016

219 views

Category:

Documents


2 download

DESCRIPTION

Como leer un teclado matricial de 4x4 con polling, soporta lock y release.

TRANSCRIPT

Por: Omar Gurrola 2/22/13 http://www.proprojects.wordpress.com

PIC18F14K50: Teclado Matricial 4x4

Realizar un dispositivo que lea un teclado matricial de 4x4 y despliegue la letra presionada en un digito de 7 segmentos. La ventaja de utilizar este tipo de teclados es la reducción de pines requeridos, ya que para leer 16 teclas se utilizan únicamente 8 pines.

Para leer un teclado de este tipo se debe realizar un barrido en los renglones o columnas ya sea con uno o con cero. Para este ejemplo el barrido se realizara en los renglones con uno y se leerá el valor de las columnas. También debemos considerar que son botones mecánicos y se genera ruido al ser presionado y debemos esperar unos 50ms para determinar cuál fue la tecla presionada. El siguiente diagrama de flujo se encarga de obtener la tecla presionada con cualquiera de los siguientes métodos:

Lock: Espera a que se presione una tecla.

Release: Manda la tecla hasta que se suelte.

Por: Omar Gurrola 2/22/13 http://www.proprojects.wordpress.com

main.c

/* * Copyright (c) 2011-2013, http://www.proprojects.wordpress.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1.- Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2.- Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /********************************************************************************** * Author: Omar Gurrola * Site: http://www.proprojects.wordpress.com * Processor: PIC18 * Compiler: C18 v3.45 * File Name: main.c * Description: Main program * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Rev. Date Comment * 1.0 02/22/13 Initial version *********************************************************************************/ /** INCLUDES *******************************************************/ #include <p18f14k50.h> #include "pic18f14k50_cbits.h" #include "pic18f14k50_io.h" #include "stdvars.h" #include "wait.h" #include "7seg.h" #include "keypad4x4.h" /** PROTOTYPES *****************************************************/ /** VARIABLES ******************************************************/ /** DECLARATIONS ***************************************************/ #pragma code // Forces the code below this line to be put into the code section (Memory Adress >= 0x'REMDIR'02A) /** Interrupt Service Routines (ISR)********************************/ #pragma interrupt HighPriorityISR void HighPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. } //This return will be a "retfie fast", since this is in a #pragma interrupt section #pragma interruptlow LowPriorityISR void LowPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. } //This return will be a "retfie", since this is in a #pragma interruptlow section void main(void){ u8 key; // Start-up configuration OSCCONbits.IRCF = 0b110; // Poscaler selected to 8 MHz OSCTUNEbits.SPLLEN = 1; // PLLx4 Enable System FQ = 32 MHz KeypadInit(LOCK,RELEASE); // Ports OpenOutPC(); WritePC(0xFF);

Por: Omar Gurrola 2/22/13 http://www.proprojects.wordpress.com Diagrama esquemático:

Circuito armado:

Referencias

Microchip, “PIC18F/LF1XK50 Data Sheet”, 2010,

http://ww1.microchip.com/downloads/en/DeviceDoc/41350E.pdf

while(TRUE){ key = KeypadRead(); WritePC(Cod7seg(key,COM_ANODE)); }; } // end main()