Professional Documents
Culture Documents
HERRAMIENTAS
-Protoboard
-Cable USB
-Computadora
OBJETIVO
Armar una practica utilizando la librera keypad la cual soporta un teclado
de 4 filas y 4 columnas. El cdigo regresado por la funcin esta en el rango de 1 a
16 dependiendo de la tecla. En este ejemplo, el cdigo regresado es convertido
a cdigo ASCII [0..9,A..F] y desplegado en el LCD. Ademas un contador despliega
en la segunda lnea del LCD, el numero de teclas presionadas. Esto mediante un
programa previamente subido al microcontrolador.
DESARROLLO
DIAGRAMA A REALIZAR:
PROGRAMA
LCD_RS_Direction
LCD_EN_Direction
LCD_D4_Direction
LCD_D5_Direction
LCD_D6_Direction
LCD_D7_Direction
at
at
at
at
at
at
TRISB4_bit;
TRISB5_bit;
TRISB0_bit;
TRISB1_bit;
TRISB2_bit;
TRISB3_bit;
void main() {
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, "1");
Lcd_Out(1, 1, "Key :");
// Write message text on LCD
Lcd_Out(2, 1, "Times:");
do {
kp = 0;
4x4
case
case
case
case
case
case
case
case
case
case
case
case
case
case
case
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
kp
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
50;
51;
65;
52;
53;
54;
66;
55;
56;
57;
67;
42;
48;
35;
68;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
2
3
A
4
5
6
B
7
8
9
C
*
0
#
D
}
if (kp != oldstate) {
previous
cnt = 1;
oldstate = kp;
}
else {
previous
cnt++;
}
Lcd_Chr(1, 10, kp);
//
Pressed
key
is
same
as
LCD
if (cnt == 255) {
overflow
cnt = 0;
Lcd_Out(2, 10, "
");
//
If
counter
varialble
}
WordToStr(cnt, txt);
string
Lcd_Out(2, 10, txt);
LCD
} while (1);
}
IMAGENES DE LA PRACTICA
CONCLUSIN
Esta practica fue un poco complicada tuvimos varias complicaciones por
la manera en que la armamos. Pero al final logramos que funcionara de
manera correcta. Al presionar una tecla esta apareca en el display.