Você está na página 1de 17

ESCUELA SUPERIOR POLITCNICA DEL

LITORAL
FIEC
Laboratorio de Microcontroladores
Prctica
LCD y Teclado

Alumno/a
Tonny Toscano, Xavier Tandazo
Paralelo: # 5
Grupo: # 3
Fecha de presentacin:
19/01/2015
2014 2 TRMINO
1. Enunciado del proyecto

El propsito principal de esta prctica es aprender a manejar un LCD y


Teclado matricial; adems de comprender el uso de sus respectivas
libreras que son: keypad y lcd

2. Diagrama de bloques

3. Diagrama de flujo funcional del programa principal y de las subrutinas


Programa Principal: Parte 1

SUBRUTINA Move_Delay

Programa Principal: Parte 2

4. Descripcin del algoritmo o estrategia utilizada

Parte 1
1. Declaramos los arreglos de char txt1[ ], txt2[ ], txt3[ ], txt4[ ] con
diversos contenidos en cada uno para luego mostrarlo en la
pantalla.LCD.
2. Declaramos la variable tipo char i.
3. Viajamos directamente a el programa principal Void main(){.
4. Se configura el puerto B como salida.
5. Se carga el puerto B con 0xFF.
6. Se configura PORTB como entrada.
7. Seteo de puerto para que sean digitales
8. Se inicializa la pantalla LCD con la instruccin Lcd_Init().
9. Se limpia la pantalla.
10. Se apaga el cursor.
11. Se escribe el contenido de txt3 en la fila uno de la pantalla.
12. Se escribe el contenido de txt4 en la fila dos de la pantalla.
13. Se llama al retardo DELAY por 2 segundos para visualizar lo escrito
por un momento.
14. Luego se limpia la pantalla.
15. Se escribe el contenido de txt1 en la fila uno de la pantalla.
16. Se escribe el contenido de txt2 en la fila dos de la pantalla.
17. Nuevamente se llama al retardo por dos segundos.
18. Se ingresa a while(1) { Subrutina }.
19. Fin del programa.
o Subrutina: Move_Delay
1. Llama a la funcin DELAY la cual genera un retardo de 500
milisegundos.
2. Retorna de donde salt.

Parte 2
1. Declaramos los arreglos de unsigned short kp, cnt, oldstate = 0, char
txt[6]
2. con diversos contenidos en cada uno para luego mostrarlo en la
pantalla.LCD.
3. Declaramos la variable tipo char i.
4. Viajamos directamente a el programa principal Void main(){.
5. Se configura el puerto B como salida.
6. Se carga el puerto B con 0xFF.
7. Se configura PORTB como entrada.
8. Seteo de puerto para que sean digitales
9. Se inicializa la pantalla LCD con la instruccin Lcd_Init().

10. Se limpia la pantalla.


11. Se apaga el cursor.
12. Se escribe el contenido de txt3 en la fila uno de la pantalla.
13. Se escribe el contenido de txt4 en la fila dos de la pantalla.
14. Se llama al retardo DELAY por 2 segundos para visualizar lo escrito
por un momento.
15. Luego se limpia la pantalla.
16. Se escribe el contenido de txt1 en la fila uno de la pantalla.
17. Se escribe el contenido de txt2 en la fila dos de la pantalla.
18. Nuevamente se llama al retardo por dos segundos.
19. Se ingresa a while(1) { Subrutina }.
20. Fin del programa.

o Subrutina
1. Se ingresa al for donde se rota el mensaje que muestra la pantalla
LCD a la derecha.
2. Salta a Move_Delay() { Subrutina };
3. Se ingresa al segundo for que rota el mensaje que muestra la
pantalla hacia la izquierda.
4. Salta a Move_Delay() { Subrutina };
5. Regresa al programa principal.
5. Listado del programa fuente en lenguaje ensamblador con
comentarios en las lneas de cdigo que considere fundamentales
PARTE 1
/*
* Nombre del Proyecto:
P8a_lcd.c
* Nombre del Autor:
(c) Mikroelektronika, 2009.
* Description:
(Explicacin del ejercicio)
* Test configuration:
MCU:
PIC16F887
Oscillator:
HS, 08.0000 MHz
SW:
mikroC PRO for PIC
* NOTES:
*/
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;

sbit LCD_D6 at RB2_bit;


sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char
char
char
char

txt1[]
txt2[]
txt3[]
txt4[]

=
=
=
=

"mikroElektronika";
"EasyPIC5";
"Lcd4bit";
"example";

unsigned short i;
void Move_Delay() {
moving
Delay_ms(500);
speed here
}
void main(){
ANSEL = 0;
digital I/O
ANSELH = 0;
Lcd_Init();

// Loop variable
// Function used for text
// You can change the moving

// Configure AN pins as
// Initialize LCD

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt3);

// Clear display
// Cursor off
// Write text in first row

Lcd_Out(2,6,txt4);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);

// Write text in second row

Lcd_Out(1,1,txt1);
Lcd_Out(2,5,txt2);

// Write text in first row


// Write text in second row

// Clear display

Delay_ms(2000);
while(1) {
// Moving text
for(i=0; i<16; i++) {
times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
for(i=0; i<16; i++) {
times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}

// Endless loop
// Move text to the right 4

// Move text to the left 7

PARTE 2
/*
* Nombre del Proyecto:
P8b_keyboard.c
* Nombre del Autor:
(c) Mikroelektronika, 2009.
* Description:
(Explicacin del ejercicio)
* Test configuration:
MCU:
PIC16F887
Oscillator:
HS, 08.0000 MHz
SW:
mikroC PRO for PIC
*/
unsigned short kp, cnt, oldstate = 0;
char txt[4];
// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
void main() {
ANSEL = 0;
ANSELH = 0;
cnt = 0;
Keypad_Init();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "Key :");
Lcd
Lcd_Out(2, 1, "Times:");
do {
kp = 0;
variable

// Reset counter
// Initialize Keypad
// Initialize Lcd
// Clear display
// Cursor off
// Write message text on

// Reset key code

// Wait for key to be pressed and released


do
//kp = Keypad_Key_Press();
// Store key code in
kp variable
kp = Keypad_Key_Click();
// Store key code in kp
variable
while (!kp);
// Prepare value for output, transform key to it's ASCII value
switch (kp) {
//case 10: kp = 42; break; // '*'
// Uncomment this block
for keypad4x3
//case 11: kp = 48; break; // '0'
//case 12: kp = 35; break; // '#'
//default: kp += 48;
case 1:
for keypad4x4
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:

kp = 49; break; // 1
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;

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

// Uncomment this block

2
3
A
4
5
6
B
7
8
9
C
*
0
#
D

}
if (kp != oldstate) {
from previous
cnt = 1;
oldstate = kp;
}
else {
as previous
cnt++;
}

// Pressed key differs

Lcd_Chr(1, 10, kp);


on Lcd

// Print key ASCII value

if (cnt == 255) {
overflow
cnt = 0;
Lcd_Out(2, 10, "
}

// If counter varialble

ByteToStr(cnt, txt);
value to string

// Pressed key is same

");
// Transform counter

Lcd_Out(2, 10, txt);


on Lcd
} while (1);
}

// Display counter value

6. Copia impresa del circuito armado en PROTEUS para la simulacin en


el momento de su ejecucin
Parte 1
U1
1
2
3
4
5
6
7
14
13

RV2
10k

33
34
35
36
37
38
39
40

50%

RE3/MCLR/VPP

RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RA0/AN0/ULPW U/C12IN0RC2/P1A/CCP1
RA1/AN1/C12IN1RC3/SCK/SCL
RA2/AN2/VREF-/CVREF/C2IN+
RC4/SDI/SDA
RA3/AN3/VREF+/C1IN+
RC5/SDO
RA4/T0CKI/C1OUT
RC6/TX/CK
RA5/AN4/SS/C2OUT
RC7/RX/DT
RA6/OSC2/CLKOUT
RA7/OSC1/CLKIN
RD0
RD1
RB0/AN12/INT
RD2
RB1/AN10/C12IN3RD3
RB2/AN8
RD4
RB3/AN9/PGM/C12IN2RD5/P1B
RB4/AN11
RD6/P1C
RB5/AN13/T1G
RD7/P1D
RB6/ICSPCLK
RB7/ICSPDAT
RE0/AN5
RE1/AN6
RE2/AN7

LCD1
LM016L

Parte 2

7
8
9
10
11
12
13
14
D0
D1
D2
D3
D4
D5
D6
D7

4
5
6
RS
RW
E

VSS
VDD
VEE

1
2
3

PIC16F887

15
16
17
18
23
24
25
26
19
20
21
22
27
28
29
30
8
9
10

U1

PIC16F887

RD7

ON

8
9
10

R1

+
4

RD6

R2

RD3

RD5

50%

19 RD0
20 RD1
21 RD2
22 RD3
27 RD4
28 RD5
29 RD6
30 RD7

RD4

RD2

33
34
35
36
37
38
39
40

15
16
17
18
23
24
25
26

10k

RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RA0/AN0/ULPWU/C12IN0RC2/P1A/CCP1
RA1/AN1/C12IN1RC3/SCK/SCL
RA2/AN2/VREF-/CVREF/C2IN+ RC4/SDI/SDA
RA3/AN3/VREF+/C1IN+
RC5/SDO
RA4/T0CKI/C1OUT
RC6/TX/CK
RA5/AN4/SS/C2OUT
RC7/RX/DT
RA6/OSC2/CLKOUT
RA7/OSC1/CLKIN
RD0
RD1
RB0/AN12/INT
RD2
RB1/AN10/C12IN3RD3
RB2/AN8
RD4
RB3/AN9/PGM/C12IN2RD5/P1B
RB4/AN11
RD6/P1C
RB5/AN13/T1G
RD7/P1D
RB6/ICSPCLK
RB7/ICSPDAT
RE0/AN5
RE1/AN6
RE2/AN7

RD1

RV2

RE3/MCLR/VPP

2
3
4
5
6
7
14
13

RD0

R3

R4

7
8
9
10
11
12
13
14
D0
D1
D2
D3
D4
D5
D6
D7

4
5
6
RS
RW
E

VSS
VDD
VEE

1
2
3

PULLUP PULLUP PULLUP PULLUP

LCD1
LM016L

7. Conclusiones

Notamos que el cdigo ASCII es esencial si con LCDs se va a


trabajar; ya que algunos componentes en la implementacin del
mismo solo entiende este tipo de lenguaje y por ende es
importante familiarizarse con estos cdigos para poder usarlos
correctamente.
Al utilizar un visualizador LCD para presentar los datos
generados por algn proceso que se realice es exclusividad de
los PIC ya que en un circuito ms elaborado, es decir, con ms
componentes el nico que tiene la capacidad de gobernarlo es
el PIC, de ah la necesidad de aprender a controlarlos bien.
Al Utilizar la memoria RAM para almacenar datos perdemos los
datos con el reset pero en la EEPROM eso no pasa, pero en
cambio esta tiene sistemas de seguridad que nos permite
habilitar y deshabilitar la lectura y escritura en la mismo.
8. Recomendaciones

Siempre se deber tener en cuenta la configuracin de la frecuenta que

tiene el PIC en el programa de simulacin del circuito PROTEUS, ya que


no importa lo que est en el cdigo de ensamblador con respecto a la
frecuencias ya que el PIC es el que manda en este aspecto y la
frecuencias que utilizamos en esta prctica fue de 8MHz.

Hay que tener presente como se realiza la conexin del LCD para que la
simulacin en PROTEUS funcione de manera adecuada, ya que es muy
comn realizar conexiones erradas.

Tener en cuidado con los cambios bancos, cuando se quiera usar un


registro primero se tiene que estar en el banco correspondiente de dicho
registro caso contrario habr error, en este caso usamos BANKSELF este
busca el banco donde se encuentra el registro.

Tener en cuenta al momento de armar el circuito simulado en PROTEUS,


ya que es muy comn que aparezcan ciertos errores como lo son, poner
mal la etiqueta en el cable que usamos o peor an no hacer bien el
contacto entre los diferentes dispositivos que utilizamos con frecuencia.
ANEXO DE RESPUESTAS A PRCTICA 8

INTEGRANTE 1: Tony Toscano


INTEGRANTE 2: Xavier Tandazo
PARALELO: 5
GRUPO: 3
PARTE 1
RESPONDER:
1)

Al ejercicio anterior agregue un botn en RD0 y cada vez que se


presione el botn se mostrar en la pantalla LCD cuantas veces ha sido
presionado el botn, es decir que se cuente cuantos pulsos van
ingresando por RD0.

/*
* Nombre del Proyecto:
P8a_lcd(2).c
* Nombre del Autor:
(c) Mikroelektronika, 2009.
* Description:
El boton en RD0 se incrementa cada vez
que que se preciona y se muestra en pantalla.
* Test configuration:
MCU:
PIC16F887

*/

Oscillator:
SW:

HS, 08.0000 MHz


mikroC PRO for PIC

// LCD module connections


sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt[] = "Contador en RD0";
//char txt2[] = cont;
//char txt3[] = "Lcd4bit";
//char txt4[] = "example";
char i;
// Loop variable
unsigned short kp, cnt, oldstate = 0;
void Move_Delay() {
Delay_ms(500);
speed here
}
void main(){
cnt = 0;
TRISB = 0;
ANSEL = 0;
I/O
ANSELH = 0;
PORTD = 0;
TRISD = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,txt);
do{
if( PORTD.F0 == 1)
cnt++;
Lcd_Out(2,5,cont);
//

Lcd_Out(2, 10, cnt);


Delay_ms(1000);

// Function used for text moving


// You can change the moving

// Reset counter
// Configure AN pins as digital
// Encera el puerto D
// Initialize LCD
// Clear display
// Cursor off
// Write text in first row

// Write text in second row

if (cnt == 255){
overflow
cnt = 0;
Lcd_Out(5, 5, "
}

// If counter varialble
");

WordToStr(cnt, txt);
to string
Lcd_Out(2, 5, cnt);
LCD
}while(1);

// Transform counter value


// Display counter value on

Delay_ms(2000);
}mikroC PRO for PIC

PARTE 2
RESPONDER:
1)

Modifique el programa anterior para que se ingrese 4 caracteres desde el teclado


4x4 y se graben estos datos en la memoria Eeprom. En la primera lnea de la
pantalla LCD se muestra los caracteres en el mismo orden que ingres el usuario
y en la segunda lnea se muestran los caracteres al revs. Por ejemplo:
1.

1234 Primera lnea en el LCD

2.

4321 Segunda lnea en el LCD

unsigned short kp, cnt, oldstate = 0;


char txt[6];
char ii;
// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;

sbit
sbit
sbit
sbit

LCD_D4
LCD_D5
LCD_D6
LCD_D7

at
at
at
at

RB0_bit;
RB1_bit;
RB2_bit;
RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;


sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
void main() {
cnt = 0;
Keypad_Init();
ANSEL = 0;
digital I/O
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0;
ext=0;

// Reset counter
// Initialize Keypad
// Configure AN pins as
// Disable comparators

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

// Initialize LCD
// Clear display
// Cursor off

do {
kp = 0;

// Reset key code variable

// Wait for key to be pressed and released


do
// kp = Keypad_Key_Press();
// Store key code in kp
variable
kp = Keypad_Key_Click();
// Store key code in kp
variable
while (!kp);
// Prepare value for output, transform key to it's ASCII value
switch (kp) {
//case 10: kp = 42; break; // '*'
// Uncomment this block for
keypad4x3
//case 11: kp = 48; break; // '0'
//case 12: kp = 35; break; // '#'
//default: kp += 48;
case 1: kp
keypad4x4
case 2: kp
case 3: kp
case 4: kp
case 5: kp
case 6: kp
case 7: kp
case 8: kp
case 9: kp
case 10: kp
case 11: kp

= 49; break; // 1
=
=
=
=
=
=
=
=
=
=

50;
51;
65;
52;
53;
54;
66;
55;
56;
57;

break;
break;
break;
break;
break;
break;
break;
break;
break;
break;

//
//
//
//
//
//
//
//
//
//

2
3
A
4
5
6
B
7
8
9

// Uncomment this block for

case
case
case
case
case

12:
13:
14:
15:
16:

kp
kp
kp
kp
kp

=
=
=
=
=

67;
42;
48;
35;
68;

break;
break;
break;
break;
break;

//
//
//
//
//

C
*
0
#
D

}
if (kp != oldstate) {
previous
cnt = 1;
oldstate = kp;
}
else {
previous
cnt++;
}

// Pressed key differs from

// Pressed key is same as

Lcd_Chr(1, 10, kp);

// Print key ASCII value on

LCD
if (cnt == 255) {
overflow
cnt = 0;
Lcd_Out(2, 10, "
}

// If counter varialble
");

WordToStr(cnt, txt);
string
Lcd_Out(2, 10, txt);
LCD

// Transform counter value to


// Display counter value on

EEPROM_Write(0x80+ii, txt);
0x80+ii
ii=i++;
do{
for(ii = 0; ii < 4; ii++) {
0x80
txt = EEPROM_Read(0x80+ii);
Lcd_Out(1, ii, txt);
}
LCD
Delay_ms(250);
for(ii = 0; ii < 4; ii++) {
0x80
txt = EEPROM_Read(0x83-ii);
Lcd_Out(2, ii, txt);
}
LCD
Delay_ms(250);
}
While(ii>5)

} while (1);

// Write data to address

// Read 32 bytes block from address


//

and display data on PORTD


// Display counter value on

// Read 32 bytes block from address


//

and display data on PORTD


// Display counter value on

Você também pode gostar