nazstaphobia
Newbie level 5
/**********************************************************/
/***** Robot with Object Detector *************************/
/**********************************************************/
int Adc; // Save analog Data
void Read_Adc()
{
ADCON0=0b10000001; // Select Analog2 and ADON
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
Adc=(ADRESH*4)+(ADRESL/64); // 10 bit Data ==> Adc
}
void main()
{
TRISA=0xFF; //SET PORT A AS INPUT
TRISC = 0X00; //SET PORT C AS OUTPUT
while(1)
{
Read_Adc(); // Read Analog 2
if (Adc>300) // if Detect object in range
{
PortC.F0 = 1;
delay_us(1000); //servo turn left
PortC.F0 = 0;
}
else
{
PortC.F0 = 1;
delay_us(1500); //servo turn to normal position 90 degree
PortC.F0 = 0;
}
}
}
/**********************************************************/
this coding has been tested in MikroC and working. I would like to add 1 more same sensor to detect for right and turn the servo to right.my problem is i stuck on how to declare the sensor in adcon0.i already read the datasheet, search forums, ask my friend and some tutorials.most of them only show 1 adc module.so how to insert 2 adc modules in this coding.please2 help me.i really appreciate it.i'm using sharp IR GP2y0a21yk and pic16f877a.please help me how to integrate 2 adc modules to this coding.thanks.
Added after 2 minutes:
i forgot to tell.the first coding using port AN0.and i would like to insert AN1 for another sensor.so how to configure the ADCON0??
/***** Robot with Object Detector *************************/
/**********************************************************/
int Adc; // Save analog Data
void Read_Adc()
{
ADCON0=0b10000001; // Select Analog2 and ADON
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
Adc=(ADRESH*4)+(ADRESL/64); // 10 bit Data ==> Adc
}
void main()
{
TRISA=0xFF; //SET PORT A AS INPUT
TRISC = 0X00; //SET PORT C AS OUTPUT
while(1)
{
Read_Adc(); // Read Analog 2
if (Adc>300) // if Detect object in range
{
PortC.F0 = 1;
delay_us(1000); //servo turn left
PortC.F0 = 0;
}
else
{
PortC.F0 = 1;
delay_us(1500); //servo turn to normal position 90 degree
PortC.F0 = 0;
}
}
}
/**********************************************************/
this coding has been tested in MikroC and working. I would like to add 1 more same sensor to detect for right and turn the servo to right.my problem is i stuck on how to declare the sensor in adcon0.i already read the datasheet, search forums, ask my friend and some tutorials.most of them only show 1 adc module.so how to insert 2 adc modules in this coding.please2 help me.i really appreciate it.i'm using sharp IR GP2y0a21yk and pic16f877a.please help me how to integrate 2 adc modules to this coding.thanks.
Added after 2 minutes:
i forgot to tell.the first coding using port AN0.and i would like to insert AN1 for another sensor.so how to configure the ADCON0??