Está en la página 1de 6

EL TECLADO MATRICIAL

Los teclados matriciales son ensamblados en forma de matriz.


El diagrama muestra un teclado como una matriz de 4X4 - 16 teclas configuradas en 4
columnas y 4 renglones.
 Cuando no se ha oprimido ninguna tecla, (todas las teclas abiertas) no hay
conexión entre renglones y columnas.
 Cuando se oprime una tecla se hace una conexión entre la columna y el renglón
de la tecla.

CONEXIÓN DEL TECLADO MATRICIAL CON DISPLAY DE 7 SEGMENTOS


CÓDIGO

int tecla;
int i;
void teclado(){
for(i=0;i<3;i++){
switch (i) {
case 0:
portb=0b0001;
if(PORTB.F4==1){tecla=1;}
if(PORTB.F5==1){tecla=2;}
if(PORTB.F6==1){tecla=3;}
if(PORTB.F7==1){tecla=10;}
case 1:
portb=0b0010;
if(PORTB.F4==1){tecla=4;}
if(PORTB.F5==1){tecla=5;}
if(PORTB.F6==1){tecla=6;}
if(PORTB.F7==1){tecla=11;}
case 2:
portb=0b0100;
if(PORTB.F4==1){tecla=7;}
if(PORTB.F5==1){tecla=8;}
if(PORTB.F6==1){tecla=9;}
if(PORTB.F7==1){tecla=12;}
case 3:
portb=0b1000;
if(PORTB.F4==1){tecla=13;}
if(PORTB.F5==1){tecla=0;}
if(PORTB.F6==1){tecla=15;}
if(PORTB.F7==1){tecla=16;}
}
}
}
void main(){
CMCON=7;
TRISA=0;
TRISB=0b11110000;

while (1){
teclado();

if (tecla==0){
porta=0b10000000; } //0

if (tecla==1){
porta=0b11111001; } //1
if (tecla==2){
porta=0b01000100; } //2
if (tecla==3){
porta=0b01110000; } //3
if (tecla==4){
porta=0b00111001; } //4
if (tecla==5){
porta=0b00110010; } //5
if (tecla==6){
porta=0b00000011; } //6
if (tecla==7){
porta=0b11111000; } //7
if (tecla==8){
porta=0b00000000; } //8
if (tecla==9){
porta=0b00111000; } //9
}
}

CONEXIÓN DEL TECLADO MATRICIAL CON DISPLAY LCD


sbit LCD_RS at RA6_bit;
sbit LCD_EN at RA7_bit;
sbit LCD_D4 at RA0_bit;
sbit LCD_D5 at RA1_bit;
sbit LCD_D6 at RA2_bit;
sbit LCD_D7 at RA3_bit;

sbit LCD_RS_Direction at TRISA6_bit;


sbit LCD_EN_Direction at TRISA7_bit;
sbit LCD_D4_Direction at TRISA0_bit;
sbit LCD_D5_Direction at TRISA1_bit;
sbit LCD_D6_Direction at TRISA2_bit;
sbit LCD_D7_Direction at TRISA3_bit;
int tecla;
int i;
void teclado(){
for(i=0;i<3;i++){
switch (i) {
case 0:
portb=0b0001;
if(PORTB.F4==1){tecla=1;}
if(PORTB.F5==1){tecla=2;}
if(PORTB.F6==1){tecla=3;}
if(PORTB.F7==1){tecla=10;}
case 1:
portb=0b0010;
if(PORTB.F4==1){tecla=4;}
if(PORTB.F5==1){tecla=5;}
if(PORTB.F6==1){tecla=6;}
if(PORTB.F7==1){tecla=11;}
case 2:
portb=0b0100;
if(PORTB.F4==1){tecla=7;}
if(PORTB.F5==1){tecla=8;}
if(PORTB.F6==1){tecla=9;}
if(PORTB.F7==1){tecla=12;}
case 3:
portb=0b1000;
if(PORTB.F4==1){tecla=13;}
if(PORTB.F5==1){tecla=0;}
if(PORTB.F6==1){tecla=15;}
if(PORTB.F7==1){tecla=14;}
}
}
}

void main() {
CMCON=7;
TRISA=0;
TRISB=0b11110000;
Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off


Lcd_Out(1,5,"ULADECH");
Lcd_Out(2,1,"MICROCONTROLADOR");
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR); // Clear display
while(1) { // Endless loop
teclado();
Lcd_Out(1,4,"NUMERO");
switch (tecla) {
case 0: Lcd_Out(2,7,"0");break;
case 1: Lcd_Out(2,7,"1");break;
case 2: Lcd_Out(2,7,"2");break;
case 3: Lcd_Out(2,7,"3");break;
case 4: Lcd_Out(2,7,"4");break;
case 5: Lcd_Out(2,7,"5");break;
case 6: Lcd_Out(2,7,"6");break;
case 7: Lcd_Out(2,7,"7");break;
case 8: Lcd_Out(2,7,"8");break;
case 9: Lcd_Out(2,7,"9");break;
case 10: Lcd_Out(2,7,"A");break;
case 11: Lcd_Out(2,7,"B");break;
case 12: Lcd_Out(2,7,"C");break;
case 13: Lcd_Out(2,7,"*");break;
case 14: Lcd_Out(2,7,"D");break;
case 15: Lcd_Out(2,7,"#");break;
}
}
}
1. Desarrollar un sistema de seguridad con 1 sensor conectado en RA5 (LOGICSTATE),
un teclado matricial 4x4, una pantalla LCD y una sirena (Sounder) conectado en RA4.
El sistema debe activarse y desactivarse después de ingresar una clave que ustedes ha
puesto.

También podría gustarte