Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Servo Problems - need your help about my code in mikroC

Status
Not open for further replies.

adalah

Newbie level 6
Joined
Mar 2, 2009
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,368
Servo Problems

Hi everyone..
i still need your help about my code in mikroC.

#define start porta.f4
#define right porta.f0
#define left porta.f1

void foward();

void main()
{
TRISA=0XFF;
TRISB=0;
TRISC=0;
PORTC=0;
TRISD=0;
PORTD=0;
ADCON1 = 10000000;

if (start==1)
{
foward();
}
}

void foward(void)
{

do{
portd.f0=1;
delay_ms(100);
portd.f0=0;
delay_ms(100);



portc.f0=1;
delay_ms(2);
portc.f0=0;

delay_ms(2000);
portc=0;

portc.f2=1;
delay_ms(1);
portc.f2=0;



delay_ms(2000);
portc=0;


portc.f0=1;
delay_ms(1);
portc.f0=0;

delay_ms(2000);
portc=0;

portc.f4=1;
delay_ms(2);
portc.f4=0;

delay_ms(2000);
portc=0;

portc.f0=1;
delay_us(1500);
portc.f0=0;

delay_ms(2000);
portc=0;

portc.f2=1;
delay_ms(2);
portc.f2=0;
portc.f4=1;
delay_ms(1);
portc.f4=0;

delay_ms(2000);
portc=0;

}while(1);

}


my problems is when i run the simulation using the ISIS ( Proteus),
1st servo automatically run.
in this code,
i declare the start button,
where i should activate the start button first,
and then the servo will start operate.


here i upload my hex code and the circuit.
hope anyone can solve my prob.
 

Re: Servo Problems

anyone..?
plz help me..
:( :( :(
 

Servo Problems

Put some comments in your code, i've got no idea what you are doing where...
 

Re: Servo Problems

ok..
this is my code with comment..
hope somebody can help me..

#define start porta.f4
#define right porta.f0
#define left porta.f1


void foward();


void main()
{
TRISA=0XFF;
PORTA=0;
TRISB=0;
TRISC=0;
PORTC=1;
TRISD=0;
PORTD=0;

do{
if (start==0)
{

foward();

}
}while(1);

}


!

void foward(void)
{


portd.f0=1; // D1 turn on
delay_ms(100); // delay for 1s
portd.f0=0; // D1 turn off
delay_ms(100); // delay for 1s

portc.f0=1; // servo 1 is high
delay_ms(2); // servo 1 turn 90
portc.f0=0; // servo 1 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low

portc.f2=1; // servo 2 is high
delay_ms(1); // servo 2 turn -90
portc.f2=0; // servo 2 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low

portc.f0=1; // servo 1 is high
delay_ms(1); // servo 1 turn -90
portc.f0=0; // servo 1 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low

portc.f4=1; // servo 3 is high
delay_ms(2); // servo 3 turn 90
portc.f4=0; // servo 3 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low

portc.f0=1; // servo 1 is high
delay_us(1500); // servo 2 turn to centre
portc.f0=0; // servo 1 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low

portc.f2=1; // servo 2 is high
delay_ms(2); // servo 2 turn 90
portc.f2=0; // servo 2 is low
portc.f4=1; // servo 3 is high
delay_ms(1); // servo 3 turn -90
portc.f4=0; // servo 3 is low

delay_ms(500); // delay for 0.5s
portc=0; // PORTC is low


}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top