Hi,
I have program a code using C18 by using the function Adcon. I am connecting GP2D120 connecting to 18F452, the code is not working, what is wrong with it? i have set the range to active different led
Here is the code
void main()
{
int x;
TRISA = 0xFF;
TRISB = 0x00;
PIE1bits.ADIE = 1;
while(1)
{
ADCON1 = 0b00000101;
ADCON0bits.GO = 1;
while(PIR1bits.ADIF ==0);
ADCON0bits.GO = 0;
PIR1bits.ADIF =0;
x = ADRESH;
if(x>0x7B && x<0x52) // 32cm - 22cm 0x52 - 0x7B
{
PORTBbits.RB0 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
if(x>0x10A && x<0x7C) // 21cm - 10cm 0x7C - 0x10A
{
PORTBbits.RB1 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
if(x>0x214 && x<0x10B) // 9cm - 4cm 0x10B - 0x214
{
PORTBbits.RB2 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
}
}
I have program a code using C18 by using the function Adcon. I am connecting GP2D120 connecting to 18F452, the code is not working, what is wrong with it? i have set the range to active different led
Here is the code
void main()
{
int x;
TRISA = 0xFF;
TRISB = 0x00;
PIE1bits.ADIE = 1;
while(1)
{
ADCON1 = 0b00000101;
ADCON0bits.GO = 1;
while(PIR1bits.ADIF ==0);
ADCON0bits.GO = 0;
PIR1bits.ADIF =0;
x = ADRESH;
if(x>0x7B && x<0x52) // 32cm - 22cm 0x52 - 0x7B
{
PORTBbits.RB0 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
if(x>0x10A && x<0x7C) // 21cm - 10cm 0x7C - 0x10A
{
PORTBbits.RB1 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
if(x>0x214 && x<0x10B) // 9cm - 4cm 0x10B - 0x214
{
PORTBbits.RB2 = 1;
Delay1KTCYx(1000);
PORTBbits.RB0 = 0;
}
}
}