Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Robot following wall

Status
Not open for further replies.

Gabi

New Member
need help
Hi all, can someone help me for this code please. I wrote on this MikroC it was compiled and i download it on to the PIC
but it's n't do i was expected get. I was expect this program to make my robot to move it forward when it's in 12 inches and turning left when it's greater than 12 inches and turning right when it is less than 12 inches. I download this code of mine and robot rotate clockwise, right wheel doesn't move. I am not good at MikroC
Is there any wrong with my code?


# define forward 0b01010000 //forward on PORTB (both motors forward).
# define backward 0b10100000 //backward on PORTB (both motors reverse).
# define right 0b10000000 // left on PORTB (right motor forward).
# define sright 0b10010000 // sharp right on PORTB (right motor forward, left motor reverse).
# define left 0b00100000 // right on PORTB (left motor forward).
# define sleft 0b01100000 // sharp left on PORTB (left motor forward, right motor reverse).
# define stop 0b00000000 //stop on PORTB (both motors off).
# define motors PORTB //defines motors (PORTB ).

unsigned int volts, volts2, l_sensor, f_sensor;

void main ()
{
ANSEL = 0b00000011; //this sets all bits of PORTA as digital inputs and outputs
CMCON = 0X07; //turns off the analog voltage comparators on PORTA
OSCCON = 0x70; //this sets internal oscillator, 8MHz and RB4,RB5, RB6 & RB7 as I/O
ADCON1 = 0x80;
TRISB = 0x0f;
TRISA = 0xFF;
PORTA = 0 ;
PORTB = 0 ;

while(1)
{

volts = Adc_read (1);
l_sensor = volts/2;

volts2 = Adc_read (0);
f_sensor = volts2/2;

if (l_sensor == 0x0C)
{motors = forward;}
if (l_sensor < 0x0C )
{motors = right; }
if (l_sensor > 0x0C)
{
motors = left;
}
}
} Reply With Quote
--------------------------------------------------------------------------------
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top