Re: pic16f877 voltmeter
Hello every one!!
I want to measure mili volts from pic and want to display on lcd. can any one help me.
I am using mikroc and pic16f877a.
My code can measure voltages upto 0.05 but not upto 0.005v.
Here is my code in c:
unsigned long adc_value;
unsigned char d1,d2,d3,d4;
#define printV lcd_chr(2,11,48+d1); lcd_chr_cp(d2+48); \
lcd_chr_cp('.'); lcd_chr_cp(48+d3); \
lcd_chr_cp(48+d4); lcd_chr_cp('V');
#define calcV d1=adc_value/1000; d2=(adc_value/100)%10; \
d3=(adc_value/10)%10; d4=adc_value%10;
void main()
{
ADCON1=0b10000010;
TRISA=0XFF;
LCD_Config(&PORTB,2,1,0,7,6,5,4); // RS,E,W,D7..4
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(1,1,"V1.00 : ADC Read");
delay_ms(200);
lcd_out(2,1,"voltage:");
for(;
{
adc_value=ADC_Read(0);
adc_value=adc_value*500/1023;
calcV
printV
delay_ms(20);
}
}