User manual

Robotics experiment with PIC microcontroller l 73
Listing A8-1 : The C program for reading ZX-03 line tracking sensor of Robo-
PICA
/********************************************************/
/************ Reading line tracking sensor **************/
/********************************************************/
int Sensor0,Sensor1; // Save Analog
char Txt[6]; // Save convert to string
void Read_Adc()
{
ADCON0=0b11000001; // Select Analog0 RC_Mode and ADON
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
Sensor0=(ADRESH*4)+(ADRESL/64); // 10 bit Data ==> sensor0
ADCON0=0b11000101; // Select Analog1 RC_Mode and ADON
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
Sensor1=(ADRESH*4)+(ADRESL/64); // 10 bit Data ==> sensor1
}
void main()
{
Delay_ms(1000); // Start up Delay
Lcd_Init(&PORTD); // Initial LCD
ANSEL = 0xFF; // PORTA ==> Analog
TRISA = 0xFF; // PORTA ==> input
Lcd_Cmd(LCD_CURSOR_OFF); // LCD cursor off
while(1)
{
Read_Adc();
WordToStr(Sensor0,Txt); // Convert Sensor0 to string
Lcd_Out(1,1,Txt); // and show on LCD
WordToStr(Sensor1,Txt); // Convert Sensor1 to string
Lcd_Out(2,1,Txt); // and show on LCD
}
}
E
If different value between white and black surface reflection is less. Builder must
adjust the distance from sensor to surface decreasing. If the sensor far from sur-
face more, value will near zero.