0% found this document useful (0 votes)
26 views

AC Voltage Code

This document describes code for measuring AC voltage using a microcontroller. It includes definitions for connecting a LCD display to the microcontroller ports. The code initializes the LCD, sets the analog to digital converter configuration, then takes 40 voltage samples in a loop. It finds the maximum sample value and converts it to a string to display the voltage reading on the LCD in volts. The main loop continuously calls the voltage reading function to display updated measurements.

Uploaded by

Marius Paulet
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

AC Voltage Code

This document describes code for measuring AC voltage using a microcontroller. It includes definitions for connecting a LCD display to the microcontroller ports. The code initializes the LCD, sets the analog to digital converter configuration, then takes 40 voltage samples in a loop. It finds the maximum sample value and converts it to a string to display the voltage reading on the LCD in volts. The main loop continuously calls the voltage reading function to display updated measurements.

Uploaded by

Marius Paulet
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/****************************************BILAL MALIK UET***********************

****
****************************************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();
}
}

You might also like