Está en la página 1de 5

INSTITUTO POLITÉCNICO NACIONAL

UNIDAD PROFESIONAL EN INGENIERÍA Y


TECNOLOGÍAS AVANZADAS

PRÁCTICA 7

TOLEDO LÓPEZ ISRAEL


2MV8
MESA 11

UNIDAD DE APRENDIZAJE
MICROPOCESADORES, MICROCONTROLADORES E INTERFAZ

PROFESOR

PÉREZ DELGADO IVES JESÚS


Programa 1
//Conexiones del LCD
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;

//Declarar variables
int lecturaADC_A0; //Variable donde se guarda la lectura del ADC
char *text; //Apuntador para el texto
char valorText[6]; //Arreglo de caracteres donde se guarda el valor del
texto
float volts_A0; //Valor en volts de la lectura en A0

void FlotanteATexto(float num) {//En el fotmado a.aaa


short i;
long numMult=(long)(1000*num); //Valor de num multiplicado
por
valorText[0]=(numMult/1000)%10+48; //Extrae x de xaaa
valorText[1]='.';
valorText[2]=(numMult/100)%10+48; //Extrae x de axaa
valorText[3]=(numMult/10)%10+48; //Extrae x de aaxa
valorText[4]=(numMult/1)%10+48; //Extrae x de aaax

void main() {
LCD_Init(); //Inicializacion del LCD
LCD_Cmd(_LCD_CURSOR_OFF); //Comando LCD para apagar
el cursor
LCD_Cmd(_LCD_CLEAR); //Comando LCD para borrar
LCD

TRISA = 0xFF; //Se configuran los pines


del puerto A como entradas
ADCON0 = 0x81; //Se selecciona FOSC/64 y
se enciende el modulo ADC
ADCON1 = 0xC0; //Se selecciona FOSC/64,
todas las entradas analógicas y Verf=VDD;

text = "Lectura ADC"; //Se define el primer


texto
LCD_Out(1,1,text); //Se escribe el primer
mensaje en la fila 1 columa 1
text = "V_A0"; //Se define el segundo
texto
LCD_Out(2,1,text); //Se escribe el segundo
mensaje en la fila 2 columna 1
while(1){
lecturaADC_A0=ADC_Read(0); //Conversion A/D. Pin
RA0 es una entrada
volts_A0=5*(float)lecturaADC_A0/1023; //Valor en
milivoltios
FlotanteATexto(volts_A0); //El valor se
convierte a texto
LCD_Out(2,6,valorText); //Se escribe el valor
en el LCD en la fila 2, columna 6
LCD_Out_CP("V"); //Se escribe en la
posicion actual del LCD
Delay_ms(10); //Retardo de 10ms
}
}

Programa 2
//Conexiones del LCD
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;

//Declarar variables
int lecturaADC_A0; //Variable donde se guarda la lectura del ADC
char *text; //Apuntador para el texto
char valorText[6]; //Arreglo de caracteres donde se guarda el valor del
texto
float volts_A0; //Valor en volts de la lectura en A0

void FlotanteATexto(float num) {//En el fotmado saa.a s=signo


short i;
long numMult=abs((long)(10*num)); //Valor de num
multiplicado por 10
if (num<0)
valorText[0]='-';
else
valorText[0]=' ';

valorText[1]=(numMult/100)%10+48; //Extrae x de xaa


valorText[2]=(numMult/10)%10+48; //Extrae x de axa
valorText[3]='.';
valorText[4]=(numMult/1)%10+48; //Extrae x de aax

void main() {
LCD_Init(); //Inicializacion del LCD
LCD_Cmd(_LCD_CURSOR_OFF); //Comando LCD para apagar
el cursor
LCD_Cmd(_LCD_CLEAR); //Comando LCD para borrar
LCD

TRISA = 0xFF; //Se configuran los pines


del puerto A como entradas
ADCON0 = 0x81; //Se selecciona FOSC/64 y
se enciende el modulo ADC
ADCON1 = 0xC0; //Se selecciona FOSC/64,
todas las entradas analógicas y Verf=VDD;

text = "Temperatura"; //Se define el primer


texto
LCD_Out(1,1,text); //Se escribe el primer
mensaje en la fila 1 columa 1

while(1){
lecturaADC_A0=ADC_Read(0); //Conversion
A/D. Pin RA0 es una entrada
volts_A0=5*(float)lecturaADC_A0/1023; //Valor en
milivoltios
FlotanteATexto((volts_A0-1.2)/0.085); //El valor se
convierte a texto
LCD_Out(2,1,valorText); //Se escribe el
valor en el LCD en la fila 2, columna 6
LCD_Chr_CP(223); //Se escribe °
en la posicion actual del cursor
LCD_Chr_CP('C'); //Se escribe C
en la posicion actual del cursor
Delay_ms(10); //Retardo de
10ms
}
}
Ilustración 1 Programa 1

Ilustración 2 Programa 2

También podría gustarte