You are on page 1of 3

Microcontroladores

Medidor de Voltaje
#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>
#define DATO_LCD PORTD
#define CONTROL_LCD PORTC
const int EN=7;
const int RS=6;
const int RW=5;
char ValText;
char Text_line2[16]="Voltaje:";
float temp;
int Wait_LCD();
int Init_LCD();
int Clear_LCD();
int Write_LCD();
int Return_LINE();
int ADC_temp();
/* Programa Principal */
int main(void)
{
int i;
char Text_line1[16];
DDRD=0xFF;
DDRC=0xFF;
DDRA=0X00;
_delay_ms(200);
CONTROL_LCD &=~_BV(RW);
Init_LCD();
init_ADC();
Clear_LCD();
while(1)
{
ADC_temp();
int d1=temp;
float f1=temp-d1;
int d2=trunc(f1*100);
sprintf(Text_line1," %d.%02d\V",d1,d2);
for(i=0;i<strlen(Text_line2);i++)
{
ValText=Text_line2[i];
Write_LCD();
_delay_ms(1);
}

Microcontroladores
Return_LINE();
for(i=0;i<strlen(Text_line1);i++)
{
ValText=Text_line1[i];
Write_LCD();
_delay_us(100);
}
_delay_ms(500);
Clear_LCD();
}
}
/* Espera del LCD */
int Wait_LCD()
{
_delay_us(200);
}
int Init_LCD()
{
CONTROL_LCD &=~_BV(RS);
DATO_LCD=0x38;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
Wait_LCD();
CONTROL_LCD &=~_BV(RS);
DATO_LCD=0x0C;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
Wait_LCD();
CONTROL_LCD &=~_BV(RS);
DATO_LCD=0x06;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
Wait_LCD(); }
/* Limpia al LCD */
int Clear_LCD()
{
CONTROL_LCD &=~_BV(RS);
DATO_LCD=0x01;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
CONTROL_LCD &=~_BV(RS);
Wait_LCD();
}

Microcontroladores
/* Escribe en el LCD */
int Write_LCD()
{
CONTROL_LCD |=_BV(RS);
DATO_LCD=ValText;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
Wait_LCD();
}
/* Salta de lnea */
int Return_LINE()
{
CONTROL_LCD &=~_BV(RS);
DATO_LCD=0XC0;
CONTROL_LCD |=_BV(EN);
CONTROL_LCD &=~_BV(EN);
Wait_LCD();
}
void init_ADC ()
{
ADMUX=0b01000000; //87;
ADCSRA=0b11011011;
}
int ADC_temp ()
{
ADCSRA |=(1<<ADSC);
while(!(ADCSRA&(1<<ADIF)));
{
ADCSRA|=(1<<ADIF);
temp=(float)ADC*5/(1024);
}
}

Alemn Lpez Juan Carlos


12070415
Esquivel Martnez Israel
11070841
Prez Reyes Mara de Jess
11070820
Vzquez Antonio Natanael
11071451

You might also like