How to build a Line Following Robot 3 – Program the pic using C programming.

In this post I am going to explain the major part of your robot building process. let’s moving to the coding part. In order to program your robot you will need to get inputs from your sensors and make decisions and give output signals to the motor controlling unit. Well for this project we will be using a pic micro controller. (16F877a)

When you give inputs to the pic make sure that you provide it as a pulse.(exact voltage as 5V) use CD4093 kind of IC  for this purpose.

To write the c program I have used the IDE mikroC. To insert the program to the pic I have used picstart plus.

Before start the coding please check the clock rate is correct according to the controller you use.

when assigning ports it can be done in this way,
PORTA=0x03;
what happens there is port numbers will assigned values according to the bit pattern of the hex value.
For example above 0x03=00000011 so port number 6 and 7(ports started from 0 to 7.total 8 ports) will be assigned 1 and others will assigned 0.
PORTA=0x0a;
a means decimal 10 which means 0x0a=00001010 in binary. So in A ports 4 and 6 will be assigned to 1.

Or else you can do it in this way which will be easy to understand
PORTA.F1=1;
which will assign A’s port 1 to 1.
PORTA.F6=1;
which will assign A’s port 6 to 1.

Use either method and take inputs and make the outputs.

void main() {
TRISD = 0x00; //initiating port D for outputs
TRISB = 0xFF; //initiating port B for inputs

Pwm1_Init(5000); //initiating pwm 1
Pwm2_Init(5000); //initiating pwm 2
Pwm1_Start();
Pwm2_Start();

while(1){

if((PORTB.F1==0)&&(PORTB.F2==0)&&(PORTB.F3==0)){   // check the sensors like this and take relevant action.

Pwm1_Change_Duty(150);
Pwm2_Change_Duty(150);
}
………
// like that you can complete the algorithm

}
}

See you soon with next post.

4 Responses to How to build a Line Following Robot 3 – Program the pic using C programming.

  1. Thank you..really informative!!

  2. Wonderful, keep it up thanks.

  3. mj says:

    good one

  4. praba says:

    i need big help 4m u

Leave a comment