q2

mail@pastecode.io avatar
unknown
plain_text
a year ago
577 B
5
Indexable
Never
// control line motor d0,d1
// infraed detecd d2
//pot1 -->  a2
//led enable d7
unsigned int pot1;
unsigned int rev_no;
unsigned int i;
void main( ){
trisd.f0=0;  // motor con
trisd.f1=0;  // motor con
trisd.f2=1;//infrared detect
trisd.f7=0; //led enable
trisa.f2=0; // pot1 enable
trisb=0x00;
while(1){

  pot1=adc_read(2)*5/1023;
  rev_no=pot1*5;
  portd.f7=1;
  portb=rev_no & 0x0f;
  portd.f0=1; //motor on
  portd.f1=0;
  for(i=1;i<=3*rev_no;i++){
  while(portd.f2==0){}
  while(portd.f2==1){}
  }
  portd.f0=0; //motor stop
  portd.f1=0;
}  }