AC Voltage Code
AC Voltage Code
****
****************************************BILALMALIKUET.BLOGSPOT.COM*************
***/
http://microcontrollerslab.com/ac-voltage-measurement-using-microcontroller/
sbit
sbit
sbit
sbit
sbit
sbit
LCD_RS
LCD_EN
LCD_D4
LCD_D5
LCD_D6
LCD_D7
at
at
at
at
at
at
RB2_bit;
RB3_bit;
RB4_bit;
RB5_bit;
RB6_bit;
RB7_bit;
sbit LCD_RS_Direction
sbit LCD_EN_Direction
sbit LCD_D4_Direction
sbit LCD_D5_Direction
sbit LCD_D6_Direction
sbit LCD_D7_Direction
float v;
at
at
at
at
at
at
TRISB2_bit;
TRISB3_bit;
TRISB4_bit;
TRISB5_bit;
TRISB6_bit;
TRISB7_bit;
char txt[5];
char txt1[5];
void voltage_READ(void)
{
float max;
int i;
int t[40];
ADCON0.ADON=1;
for(i=0; i<=39; i++)
{
v= ADC_Read(0);
v =v*(10.0/1023.0);
v=(v-5.0);
t[i]=v*110.1909091;
}
ADCON0.ADON=0;
max=t[0];
for(i=0; i<=39; i++)
{
if(max<t[i])
max=t[i];
}
max=max*.707106781;
intToStr(max, txt);
Lcd_out(1,9,txt);
delay_ms(1000);
}
void main()
{
Lcd_Init();
ADCON0.ADCS1=1;
ADCON0.ADCS1=0;
// Initialize LCD
ADCON0.ADON=0;
while(1)
{
Lcd_out(1,1, "voltage:");
voltage_READ();
}
}