All pastes #1757667 Raw Edit

car

public cpp v1 · immutable
#1757667 ·published 2010-01-19 17:08 UTC
rendered paste body
#define __16f876a#include "pic16f876a.h"#include "delay.h"#define OUTPUT 0#define INPUT 1#define TRIGGERL RA0#define ECHOL RA1#define TRIGGERR RA2#define ECHOR RA3#define MOTOR RA4/*void waitms(long time) {  long j;  while (time--)    for (j=0; j < 20000; j++)      ;}*/void go(int direction){  /*   * Depends if we have   * a motor or a servo   */}void main(void){  int i,l,r;  i=0;  ADCON1=7;  TRISA0=OUTPUT;  TRISA1=INPUT;  TRISA2=OUTPUT;  TRISA3=INPUT;  TRISA4=OUTPUT;  void getdistance(void)  {    l = 0;    r = 0;    // Left    TRIGGERL = 0;    TRIGGERL = 1;    DelayBigUs(300);    TRIGGERL = 0;    DelayBigUs(10);    while (ECHOL==1) {      DelayMs(1);      l=l+1;    }        // Right    TRIGGERR = 0;    TRIGGERR = 1;    DelayBigUs(300);    TRIGGERR = 0;    DelayBigUs(10);    while (ECHOR==1) {      DelayMs(1);      r=r+1;    }  }  int speed;  while (1)  {    getdistance();    if ( l < r ) {      go(0);    } else {      go(1);    }  speed=100/(l+r);  if (i % speed != 1) {    MOTOR = 1;  } else {    MOTOR = 0;  }  }