#include <ADC(16f877a).h>
#include <lcd.c>
//unsigned long int bilgi;
float bilgi=0, V1=0, V2=0, I1=0, I2=0;
byte activeadc=0xff;
void main()
{
set_tris_a(0xff);
set_tris_e(0xff);
setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT | RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
disable_interrupts(GLOBAL);
lcd_init();
delay_ms(5);
float Vcarpan=26.54;
float Icarpan=204.8;
while(true)
{
output_toggle(LED);
delay_ms(500);
output_toggle(LED);
delay_ms(500);
output_toggle(LED);
///V1///
if(activeadc!=0x00){
set_adc_channel(0);
delay_us(100);
activeadc=0x00;
}
bilgi=read_adc();
V1=bilgi/Vcarpan;
if(V1<0)V1=0;
///V2///
if(activeadc!=0x01){
set_adc_channel(1);
delay_us(20);
activeadc=0x01;
}
bilgi=read_adc();
V2=(bilgi/Vcarpan);
if(V2<0)V2=0;
lcd_gotoxy(1,1);
printf(lcd_putc,"\f1->%2.2fV-%fA",V1,I1);
printf(lcd_putc,"\n2->%2.2fV-%fA",V2,I2);
}
}