Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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
2. Diagrama de bloques
SUBRUTINA Move_Delay
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().
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;
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);
Lcd_Out(1,1,txt1);
Lcd_Out(2,5,txt2);
// 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
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
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;
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
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++;
}
if (cnt == 255) {
overflow
cnt = 0;
Lcd_Out(2, 10, "
}
// If counter varialble
ByteToStr(cnt, txt);
value to string
");
// Transform counter
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/SD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D5
D6
D7
4
5
6
RS
RW
E
VSS
VDD
VEE
1
2
3
LCD1
LM016L
7. Conclusiones
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.
/*
* 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:
// Reset counter
// Configure AN pins as digital
// Encera el puerto D
// Initialize LCD
// Clear display
// Cursor off
// Write text in first 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);
Delay_ms(2000);
}mikroC PRO for PIC
PARTE 2
RESPONDER:
1)
2.
sbit
sbit
sbit
sbit
LCD_D4
LCD_D5
LCD_D6
LCD_D7
at
at
at
at
RB0_bit;
RB1_bit;
RB2_bit;
RB3_bit;
// 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;
= 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
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++;
}
LCD
if (cnt == 255) {
overflow
cnt = 0;
Lcd_Out(2, 10, "
}
// If counter varialble
");
WordToStr(cnt, txt);
string
Lcd_Out(2, 10, txt);
LCD
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);