NECAIBIA
Newbie level 4

I am using PIC16F877A to light up an LED I use ADC interrupt but the LED doesn't light up. here is my code please help me.
Code:
unsigned int k= 0 ;
unsigned adc_value1,adc_value2;
float V=0,V1,I1,I=0;
void interrupt()
{
if (PIR1.ADIF)
{
PIR1.ADIF=0; // clear AD interrupt flag
for (k=0;k<10;k++)
{
ADCON0 = 0b10000001; // select channel 0
adc_value1 = ADC_Read(0);
V1=adc_value1*5.0;
V1=V1/1024.0;
V1=V1*6.0;
V=V+V1;
ADCON0 = 0b10001001; // select channel 1
adc_value2 = ADC_Read(1);
I1=adc_value2*5.0;
I1=I1/1024.0;
I1=I1-2.5;
I1=I1/0.185;
I=I+I1;
}
I=I/10;
V=V/10;
Delay_Cyc(3); //wait acquisition time
ADCON0.F2=1; //start conversion again
}
}
void main()
{
ADC_Init();
ADCON1 = 0b11000010;
ADCON0 = 0b10000001; // select channel 0
PIE1.ADIE = 1; //Enable ADC interrupt
INTCON.PEIE = 1; //Enable peripheral interrupt
INTCON.GIE = 1; //Enable global interrupt
Delay_us(10); //wait for acquisition time
ADCON0.F2 = 1; //start conversion
TRISA=1;
TRISD=0;
PORTD=0;
while (1)
{
if(V>I)
{
portd.b2=1;
}
if(V<i)
{
portd.b2=0;
}
}
}</i)
Last edited by a moderator: