CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Servos.c

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
the_nes@hotmail.com
Guest







Servos.c
PostPosted: Tue Dec 04, 2007 2:13 pm     Reply with quote

here is an example for Servos.c Library, I named it as Servo Server Very Happy

NOTE: u can control a delay, sending parameters from other pic

///////////////////// SServo.c /////////////////////
Code:

#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>

int1 side;       //side  { LEFT , RIGHT }
int8 speed;      //speed { 0, 1, 2, 3, 4 }
int1 servo;      //servo { servo 1, servo 2 }

void main()
{
init_servos();   //initialize servos


while(1)                                 // RUN ALWAYS
  {
      speed = 0;
      if(pin_B0)                          //if pin_B0 = 0, Servos on
      {
         if(pin_B4) {speed += 4;}
         if(pin_B3) {speed += 2;}         //   pinB4, pinB3, pin_b2    determine the speed, 0b_ _ _
         if(pin_B2) {speed += 1;}
         if(pin_B1) {side = 1;}
            else {side = 0;}              //   pin_B1, determine the direction, LEFT or RIGHT
         if(pin_B5) {servo = 1;}
            else {servo = 0;}             //   pin_B5, pin out, B7 or B6

         set_servo(servo, side, speed);   //send instruction to servo
      }
      else
      {
         stop_servos();                  //if pin_B0 = 0, Servos off
      }
   }
}



//////////// SServo.h /////////////////////


Code:

#include <16F874A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(CLOCK = 4000000)

the_nes@hotmail.com
Guest







PostPosted: Tue Dec 04, 2007 4:07 pm     Reply with quote

sorry
Code:

#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>

int1 side;       //side  { LEFT , RIGHT }
int8 speed;      //speed { 0, 1, 2, 3, 4 }
int1 servo;      //servo { servo 1, servo 2 }


void main()
{

set_tris_b(0b00111111);
init_servos();   //initialize servos

while(1)                                 // RUN ALWAYS
  {
      speed = 0;
      if(pin_B0)                          //if pin_B0 = 0, Servos on
      {
         if(input(pin_B4)) {speed += 4;}
         if(input(pin_B3)) {speed += 2;}         //   pinB4, pinB3, pin_b2    determine the speed, 0b_ _ _
         if(input(pin_B2)) {speed += 1;}
         if(input(pin_B1)) {side = 1;}
            else {side = 0;}              //   pin_B1, determine the direction, LEFT or RIGHT
         if(input(pin_B5)) {servo = 1;}
            else {servo = 0;}             //   pin_B5, pin out, B7 or B6

         set_servo(servo, side, speed);   //send instruction to servo
         delay_ms(500);
      }
      else
      {
         stop_servos();                  //if pin_B0 = 0, Servos off
      }
   }
}
the_nes@hotmail.com
Guest







ss
PostPosted: Tue Dec 04, 2007 4:08 pm     Reply with quote

Code:

#include "C:\Program Files\PICC\Projects\SServo\SServo.h"
#include <servos.c>

int1 side;       //side  { LEFT , RIGHT }
int8 speed;      //speed { 0, 1, 2, 3, 4 }
int1 servo;      //servo { servo 1, servo 2 }


void main()
{

set_tris_b(0b00111111);
init_servos();   //initialize servos

while(1)                                 // RUN ALWAYS
  {
      speed = 0;
      if(input(pin_B0))                          //if pin_B0 = 0, Servos on
      {
         if(input(pin_B4)) {speed += 4;}
         if(input(pin_B3)) {speed += 2;}         //   pinB4, pinB3, pin_b2    determine the speed, 0b_ _ _
         if(input(pin_B2)) {speed += 1;}
         if(input(pin_B1)) {side = 1;}
            else {side = 0;}              //   pin_B1, determine the direction, LEFT or RIGHT
         if(input(pin_B5)) {servo = 1;}
            else {servo = 0;}             //   pin_B5, pin out, B7 or B6

         set_servo(servo, side, speed);   //send instruction to servo
         delay_ms(500);
      }
      else
      {
         stop_servos();                  //if pin_B0 = 0, Servos off
      }
   }
}

arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 4:04 am     Reply with quote

hi..

i want to ask u a question please...

about servo.c library... which 2 pins i have connect to give signal to my 2 servos and i am using PIC16f877a 20Mhz..

and if i want to control more than 2 servo with speed control, can i use this servo.c library?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 9:56 am     Reply with quote

Quote:
which 2 pins i have connect to give signal to my 2 servos

See this example. It may help.
http://www.ccsinfo.com/forum/viewtopic.php?t=34560&start=22
davemaster2000



Joined: 18 Dec 2005
Posts: 2
Location: Peru

View user's profile Send private message

PostPosted: Thu Jul 28, 2011 10:43 am     Reply with quote

arawana wrote:
hi..

i want to ask u a question please...

about servo.c library... which 2 pins i have connect to give signal to my 2 servos and i am using PIC16f877a 20Mhz..

and if i want to control more than 2 servo with speed control, can i use this servo.c library?


Greetings,

As default in servos.c file, you have the following:

#ifndef LEFT_SERVO_PIN
#define LEFT_SERVO_PIN PIN_D6
#define RIGHT_SERVO_PIN PIN_D7
#endif

But, you can change it in your code...

Best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group