Академический Документы
Профессиональный Документы
Культура Документы
I. TRABAJO EN LABORATORIO: Para cada uno de los incisos realizar: Proyecto MikroBasic Cdigo fuente (impreso) Diagrama de flujo (impreso) Simulacin en ISIS-Proteus (confirmacin con firma) Grabado del microcontrolador Armado y funcionamiento en PROTOBOARD (confirmacin con firma) a) Candado electrnico: se ingresa un cdigo de apertura del candado de 3 dgitos. Si el cdigo es correcto el LCD debe mostrar el mensaje ABIERTO, caso contrario el mensaje ser CERRADO. Cdigo fuente:
program CANDADO symbol Alerta=PortB.0 dim Tecla, i, j, valor as byte dim TeclaT as string[3] dim vec_dato, nvec_dato as string[3] ' KeyPad module dim keypadPort as byte at PORTD ' Lcd module connections dim LCD_RS as sbit at RC4_bit LCD_EN as sbit at RC5_bit LCD_D4 as sbit at RC0_bit LCD_D5 as sbit at RC1_bit LCD_D6 as sbit at RC2_bit LCD_D7 as sbit at RC3_bit LCD_RS_Direction as sbit at LCD_EN_Direction as sbit at LCD_D4_Direction as sbit at LCD_D5_Direction as sbit at LCD_D6_Direction as sbit at LCD_D7_Direction as sbit at ' End Lcd module connections main: ANSEL = 0 ANSELH = 0 C1ON_bit = C2ON_bit = 0 portb=$00 TrisB=%11111110
Keypad_Init() Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF) Lcd_Out(1, 1, "CANDADO ELECTRONICO") delay_ms(500) Lcd_Cmd(_LCD_Clear) Lcd_Out(1, 1, " INTRODUZCA") delay_ms(500) Lcd_Out(1, 1, "CODIGO SECRETO:") Lcd_Cmd(_LCD_second_row) i=0 while (i<3) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend vec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) i=i+1 wend delay_ms(1000) Lcd_Out(1, 1, "CODIGO GUARDADO....") Lcd_Out(2, 1, "**********************") delay_ms(1000) while (1) Lcd_Cmd(_LCD_CLEAR) Lcd_Out(1,1,"Introduzca clave:") Lcd_Out(2,1," ") i=0 while(i<3) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend nvec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) i=i+1 wend delay_ms(1000) valor=0 for j=0 to 2 if(vec_dato[j]=nvec_dato[j]) valor= valor +1 end if next j
then
Alerta=1 Delay_ms(3000) Alerta=0 else Lcd_Out(2,1," Delay_ms(2000) end if wend end. CERRADO =(")
Diagrama de flujo:
CANDADO
ABIERTO
CERRADO
Mostrar en el LCD
b) Calculadora bsica: se ingresa dos nmeros de un digito (del 0 al 9), posteriormente ingresa una operacin a realizar: +, -, *, /, finalmente el LCD muestra el resultado de la operacin. Cdigo fuente:
program CALCULADORA dim Tecla, i, dato1, dato2, res as byte dim TeclaT, ress as string[3] ' KeyPad module dim keypadPort as byte at PORTD ' Lcd module connections dim LCD_RS as sbit at RC4_bit LCD_EN as sbit at RC5_bit LCD_D4 as sbit at RC0_bit LCD_D5 as sbit at RC1_bit LCD_D6 as sbit at RC2_bit LCD_D7 as sbit at RC3_bit LCD_RS_Direction as sbit at TRISC4_bit LCD_EN_Direction as sbit at TRISC5_bit
LCD_D4_Direction as sbit LCD_D5_Direction as sbit LCD_D6_Direction as sbit LCD_D7_Direction as sbit ' End Lcd module connections main: ANSEL = 0 ANSELH = 0 C1ON_bit = C2ON_bit = 0 Keypad_Init() Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF)
at at at at
while (1) Lcd_Out(1, 1, " CALCULADORA BASICA ") Lcd_Out(2, 1, " Introducir datos: ") delay_ms(1000) Lcd_Cmd(_LCD_Clear) DATO1: Lcd_Out(1, 3, "DATO 1:") delay_ms(500) i=0 Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend if Tecla <= 9 then if i<1 then dato1=Tecla i=1 BytetoStr(Tecla,TeclaT) Lcd_Out(1,11,TeclaT) delay_ms(1000) else goto DATO2 end if else goto DATO1 end if DATO2: Lcd_Out(2, 3, "DATO 2:") delay_ms(500) i=0 Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend if (Tecla <= 9) then if i<1 then dato2=Tecla i=1 BytetoStr(Tecla,TeclaT) Lcd_Out(2,11,TeclaT) delay_ms(1000)
else goto OPERACION end if else goto DATO2 end if OPERACION: Tecla=0 while Tecla=0 Tecla = Keypad_Key_Click() wend select case Tecla case 16 res= dato1 + dato2 Lcd_Out(2, 17, "+") case 15 res = dato1 - dato2 Lcd_Out(2, 17, "-") case 14 res= dato1 * dato2 Lcd_Out(2, 17, "*") case 13 res = dato1 / dato2 Lcd_Out(2, 17, "/") end select delay_ms(1000) Lcd_Cmd(_LCD_Clear) Lcd_Out(1, 1, "El resultado es: ") BytetoStr(res,ress) Lcd_Out(2, 7, ress) delay_ms(1000) wend end.
Diagrama de flujo:
CALCULADORA BASICA
Datos >=9??
Si
Elegir operacin + * /
c) Nmero secreto: se ingresa un nmero de dos dgitos, se compara con el nmero secreto. Si el numero ingresado es mayor se muestra en el LCD Mayor si es menor se muestra Menor. El proceso se repite hasta encontrar el nmero secreto, en cuyo caso el LCD muestra Numero secreto. Cdigo fuente:
program NUMSEC dim Tecla, i, dato1, numsec as byte dim TeclaT as string[3] ' KeyPad module dim keypadPort as byte at PORTD ' Lcd module connections dim LCD_RS as sbit at RC4_bit LCD_EN as sbit at RC5_bit LCD_D4 as sbit at RC0_bit LCD_D5 as sbit at RC1_bit LCD_D6 as sbit at RC2_bit LCD_D7 as sbit at RC3_bit LCD_RS_Direction as sbit at LCD_EN_Direction as sbit at LCD_D4_Direction as sbit at LCD_D5_Direction as sbit at LCD_D6_Direction as sbit at LCD_D7_Direction as sbit at ' End Lcd module connections main: ANSEL = 0 ANSELH = 0 C1ON_bit = C2ON_bit = 0 Keypad_Init() Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF) numsec=24 ' se puede cambiar BUSCA EL NUMERO SECRETO ") ")
while (1) dato1=0 Lcd_Cmd(_LCD_Clear) Lcd_Out(2,3," buscalo... ") Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend if Tecla <= 9 then dato1=dato1 + Tecla*10 BytetoStr(Tecla,TeclaT) Lcd_Out(1,7,TeclaT) delay_ms(500)
end if Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend if Tecla <= 9 then dato1= dato1 + Tecla BytetoStr(Tecla,TeclaT) Lcd_Out(1,10,TeclaT) delay_ms(500) end if if dato1 > numsec then Lcd_Out(2,3," Mayor ") delay_ms(1000) else if dato1 < numsec then Lcd_Out(2,3," Menor ") delay_ms(1000) else Lcd_Out(2,3,"Numero secreto") delay_ms(1000) end if end if delay_ms(1000) wend end.
Diagrama de flujo:
NUMERO SECRETO
Configuracin de puertos Insertar el nmero secreto de dos cifras Leer un dato por teclado
si
Numsecret > dato ledo?? Nmero Secreto
si
menor mayor
II. TRABAJO DE INVESTIGACION: Detallar (incluir cdigo ejemplo en MikroBasic Pro) el procedimiento de escritura y lectura de la memoria EEPROM de datos en el PIC16F887, de tal manera que pueda almacenar en esta memoria los datos correspondientes al cdigo de apertura del Candado electrnico y al Numero Secreto. Candado electrnico:
program CAND_EE dim Tecla, i, j, valor, v as byte dim TeclaT as string[3] dim vec_dato, nvec_dato as string[3] ' KeyPad module dim keypadPort as byte at PORTD ' Lcd module connections dim LCD_RS as sbit at RC4_bit LCD_EN as sbit at RC5_bit LCD_D4 as sbit at RC0_bit LCD_D5 as sbit at RC1_bit LCD_D6 as sbit at RC2_bit LCD_D7 as sbit at RC3_bit LCD_RS_Direction as sbit at LCD_EN_Direction as sbit at LCD_D4_Direction as sbit at LCD_D5_Direction as sbit at LCD_D6_Direction as sbit at LCD_D7_Direction as sbit at ' End Lcd module connections main: ANSEL = 0 ANSELH = 0 C1ON_bit = C2ON_bit = 0 portb=$00 TrisB=%11111110 Keypad_Init() Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF) if(EEPROM_Read(0x50)=1) then goto start end if Lcd_Out(1, 1, "CANDADO ELECTRONICO") delay_ms(500) Lcd_Cmd(_LCD_Clear) Lcd_Out(1, 1, " INTRODUZCA") delay_ms(500) Lcd_Out(1, 1, "CODIGO SECRETO:") Lcd_Cmd(_LCD_second_row) i=0 while (i<3) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click()
wend vec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) EEPROM_Write(0x02+i,Tecla) EEPROM_Write(0x50,1) i=i+1 wend delay_ms(1000) Lcd_Out(1, 1, "CODIGO GUARDADO....") Lcd_Out(2, 1, "**********************") delay_ms(1000) start: while (1) Lcd_Cmd(_LCD_CLEAR) Lcd_Out(1,1,"Introduzca clave:") Lcd_Out(2,1," ") i=0 while(i<3) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend nvec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) i=i+1 wend delay_ms(1000) valor=0 for j=0 to 3 if(EEPROM_Read(0x02+j)=nvec_dato[j]) then valor= valor +1 end if next j if (valor=3) then Lcd_Out(1,1,"**********************") Lcd_Out(2,1," clave correcta =) ") Delay_ms(1000) Alerta=1 Delay_ms(3000) Alerta=0 else Lcd_Out(2,1," clave incorrecta =(") Delay_ms(2000) end if wend end.
Nmero Secreto:
program NUMSEC_EE dim Tecla, i, valor, j as byte
dim TeclaT as string[3] dim vec_dato, nvec_dato as string[3] ' KeyPad module dim keypadPort as byte at PORTD ' Lcd module connections dim LCD_RS as sbit at RC4_bit LCD_EN as sbit at RC5_bit LCD_D4 as sbit at RC0_bit LCD_D5 as sbit at RC1_bit LCD_D6 as sbit at RC2_bit LCD_D7 as sbit at RC3_bit LCD_RS_Direction as sbit at LCD_EN_Direction as sbit at LCD_D4_Direction as sbit at LCD_D5_Direction as sbit at LCD_D6_Direction as sbit at LCD_D7_Direction as sbit at ' End Lcd module connections main: ANSEL = 0 ANSELH = 0 C1ON_bit = C2ON_bit = 0 Keypad_Init() Lcd_Init() Lcd_Cmd(_LCD_CLEAR) Lcd_Cmd(_LCD_CURSOR_OFF) if(EEPROM_Read(0x50)=1) then goto start end if Lcd_Out(1, 1, " INTRODUCE ") Lcd_Out(2, 1, " NUMERO SECRETO ") delay_ms(1000) Lcd_Cmd(_LCD_CLEAR) i=0 while (i<2) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend vec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) EEPROM_Write(0x02+i,Tecla) EEPROM_Write(0x50,1) i=i+1 wend delay_ms(1000) Lcd_Out(1, 1, "NUMERO GUARDADO....") Lcd_Out(2, 1, "**********************") delay_ms(1000) start: while(1) Lcd_Cmd(_LCD_CLEAR) Lcd_Out(1, 1, "
BUSCA EL
")
Lcd_Out(2, 1, " NUMERO SECRETO ") delay_ms(1500) Lcd_Cmd(_LCD_CLEAR) i=0 while(i<2) Tecla = 0 while Tecla=0 Tecla = Keypad_Key_Click() wend nvec_dato[i]=Tecla BytetoStr(Tecla,TeclaT) Lcd_Out_cp(TeclaT) i=i+1 wend delay_ms(1000) valor=0 for j=0 to 1 if(EEPROM_Read(0x02+j)=nvec_dato[j]) then valor= valor +1 end if next j if (valor=2) then Lcd_Out(1,1,"**********************") Lcd_Out(2,1," NUMERO SECRETO =) ") Delay_ms(1000) else if(nvec_dato[0]=EEPROM_Read(0x02)) then if(nvec_dato[1]>EEPROM_Read(0x02+1)) then Lcd_Out(1,1,"**********************") Lcd_Out(2,1," mayor ") Delay_ms(1000) else Lcd_Out(1,1,"**********************") Lcd_Out(2,1," menor ") Delay_ms(1000) end if else if(nvec_dato[0]>EEPROM_Read(0x02)) then Lcd_Out(1,1,"**********************") Lcd_Out(2,1," mayor ") Delay_ms(1000) else Lcd_Out(1,1,"**********************") Lcd_Out(2,1," menor ") Delay_ms(1000) end if end if end if wend end.
EEPROM_Write
Prototipo //Para PIC16 sub procedure EEPROM_Write(dim Direccin as byte, dim Dato as byte) //Para PIC18 sub procedure EEPROM_Write(dim Direccion as word, dim Dato as byte)
Nada Retorna Descripcin Escribe un dato en la direccin especfica. El parmetro de direccin es dependiente de MCU; para la familia PIC16 es de tipo byte, y para la familia PIC18 es de tipo word. Para PIC18 MCUs con ms localizaciones de datos EEPROM, esto es responsabilidad de programar el registro SFR EEADRH apropiadamente. Sepa que todas las interrupciones estarn deshabilitadasdurante la ejecucin de las rutina de EEPROM_Write (GIE bit del registro INTCON ser limpiado). La rutina pondr ese bit a uno en la salida. Requiere el modulo EEPROM. Requiere Asegurar mnimo 20ms de retardo entre usos sucesivos de las rutinas EEPROM_Write y EEPROM_Read. Aunque PIC escribir el valor correcto, el EEPROM_Read podra devolver un resultado indefinido. EEPROM_Write($32, $AA) Ejemplo
EEPROM_Read
//Para PIC16 sub function EEPROM_Read(dim Direccin as byte) as byte // Para PIC18 sub function EEPROM_Read(dim Direccion as word) as byte Retorna un byte de una direccin especfica. Retorna Descripcin Lee los datos de memorias especficas. El parmetro de direccin depende de MCU; para la familia PIC16 es de tipo byte, y para la familia PIC18 es de tipo word. For PIC18 MCUs con mas localizaciones de datos EEPROM esto es responsabilidad de programar el registro SFR EEADRH apropiadamente. Requiere el modulo EEPROM. Requiere Asegurar mnimo 20ms de retardo entre usos sucesivos de las rutinas EEPROM_Write y EEPROM_Read. Aunque PIC escribir el valor correcto, el EEPROM_Read podra devolver un resultado indefinido. tmp = EEPROM_Read($3F) Ejemplo Prototipo
CONCLUSIONES: Se logro comprender el uso del teclado matricial junto al LCD, viendo las aplicaciones que se le pueden dar. Se realizo la implementacin en hardware del ejemplo de la prctica observando un resultado bueno, y un funcionamiento correcto. Se logro realizar los programas de los incisos a), b) y c) en simulacin, comprobando su funcionamiento correcto, con un poco de demora en el anlisis de los mismos, pero fue posible entendiendo cada uno de los pasos a seguir. Se logro comprender como se utilizaba la librera de mikroBasic para la escritura y lectura de la memoria EEPROM del microcontrolador. De la misma manera se logro entender el uso de las mltiples libreras de MikroBasic PRO, utilizndolas del modo adecuado para las aplicaciones necesarias.