#include <16F877A.h>
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B2
#define LCD_DATA6 PIN_B1
#define LCD_DATA7 PIN_B0
#define LCD_RW_PIN PIN_D2
#define LCD_ENABLE_PIN PIN_B5
#define LCD_RS_PIN PIN_B4
#device adc = 10
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOLVP, NOPUT, NOWRT, NODEBUG, NOCPD
#use delay(clock=16000000)
#include <lcd.c>
void main()
{
float v;
float v1, v2;
float i;
set_tris_a(0xFF); //0xFF defines A port as input.
set_tris_b(0x00); //0x00 defines B port as output.
lcd_init(); //Initialization of the LCD
delay_ms(5);
setup_adc_ports(AN0);//Set the pin where input is connected
setup_adc(ADC_CLOCK_DIV_64); //Setting up Tad
set_adc_channel(0);//channel from which the ADC will be reading the data
setup_vref(FALSE);
while(true)
{
delay_ms(10);
read_adc(ADC_START_ONLY);
delay_ms(2);
v1 = read_adc();
v = v1 * 250.0 * (5.0/1023.0);
v2 = v1 * (5.0/1023.0);
i = v2 / 4000.0;
lcd_gotoxy(1,1);
printf(lcd_putc,"V:%2.4f"v);
delay_ms(100);
printf(lcd_putc,"V");
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc, "I:%2.9f"i);
delay_ms(100);
printf(lcd_putc, "A");
delay_ms(100);
};
}