28 static BIT servosStartedFlag = 0;
32 static volatile BIT servosMovingFlag = 0;
38 static uint8 XDATA servoAssignment[MAX_SERVOS];
56 static volatile uint8 servoPinsOnPort0;
57 static volatile uint8 servoPinsOnPort1;
63 switch(servoCounter++)
67 P0SEL |= servoPinsOnPort0;
75 P1SEL |= servoPinsOnPort1;
84 T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
89 P0SEL &= ~servoPinsOnPort0;
94 P1SEL &= ~servoPinsOnPort1;
110 servosMovingFlag = 0;
112 for(i = 0; i < MAX_SERVOS; i++)
114 volatile struct SERVO_DATA XDATA * d = servoData + i;
128 servosMovingFlag = 1;
140 servosMovingFlag = 1;
156 static uint8 pinToInternalChannelNumber(
uint8 pin)
174 if (servosStartedFlag)
186 servoPinsOnPort0 = servoPinsOnPort1 = 0;
187 for (i = 0; i < MAX_SERVOS; i++)
192 servoData[i].
speed = 0;
196 uint8 internalChannelNumber = pinToInternalChannelNumber(pins[i]);
198 servoAssignment[i] = internalChannelNumber;
200 switch(internalChannelNumber)
202 case 0: P0_2 = 0; servoPinsOnPort0 |= (1<<2);
break;
203 case 1: P0_3 = 0; servoPinsOnPort0 |= (1<<3);
break;
204 case 2: P0_4 = 0; servoPinsOnPort0 |= (1<<4);
break;
205 case 3: P1_2 = 0; servoPinsOnPort1 |= (1<<2);
break;
206 case 4: P1_1 = 0; servoPinsOnPort1 |= (1<<1);
break;
207 case 5: P1_0 = 0; servoPinsOnPort1 |= (1<<0);
break;
213 P0SEL &= ~servoPinsOnPort0;
214 P0DIR |= servoPinsOnPort0;
215 P1SEL &= ~servoPinsOnPort1;
216 P1DIR |= servoPinsOnPort1;
218 if (servoPinsOnPort0)
239 T1CCTL0 = T1CCTL1 = T1CCTL2 = 0b00011100;
242 T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
253 servosStartedFlag = 1;
258 if (!servosStartedFlag)
273 P0SEL &= ~servoPinsOnPort0;
274 P1SEL &= ~servoPinsOnPort1;
279 servosStartedFlag = 0;
284 return servosStartedFlag;
289 return servosMovingFlag;
300 volatile struct SERVO_DATA XDATA * d = servoData + servoAssignment[servoNum];
307 if (d->
speed == 0 || d->
target == 0 || target == 0)
314 servosMovingFlag = 1;
319 T1IE = servosStartedFlag;
334 return servoData[servoAssignment[servoNum]].
target;
341 position = servoData[servoAssignment[servoNum]].
position;
342 T1IE = servosStartedFlag;
349 servoData[servoAssignment[servoNum]].
speed =
speed;
350 T1IE = servosStartedFlag;
355 return servoData[servoAssignment[servoNum]].
speed;
void servosStart(uint8 XDATA *pins, uint8 numPins)
void servoSetSpeed(uint8 servoNum, uint16 speed)
void servoSetTarget(uint8 servoNum, uint16 targetMicroseconds)
uint16 servoGetSpeed(uint8 servoNum)
void servoSetTargetHighRes(uint8 servoNum, uint16 target)
uint16 servoGetTargetHighRes(uint8 servoNum)
uint16 servoGetPosition(uint8 servoNum)
#define ISR(source, bank)
uint16 servoGetTarget(uint8 servoNum)
uint16 servoGetPositionHighRes(uint8 servoNum)
#define SERVO_TICKS_PER_MICROSECOND