-
Notifications
You must be signed in to change notification settings - Fork 3
/
RCServo.c
94 lines (85 loc) · 1.67 KB
/
RCServo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifdef __XC__
#include <xc.h>
#else
#include <htc.h>
//#include <stddef.h>
#endif
#include "IOCycle.h"
#include "DHT22.h"
#include "IOConfig.h"
#include "RCServo.h"
unsigned char ServoIndex;
unsigned short ServoTimer[INPUT_COUNT];
short ServoIdleTime=16000;
near unsigned char ServoMask;
void DoRCServo(void)
{
unsigned char BMask;
unsigned short _temp;
if(!TMR1ON)
{
// ServoIndex++;
{
#asm
incf _ServoIndex,f
#endasm
}
if(ServoIndex>INPUT_COUNT)
{
ServoIndex=0;
ServoIdleTime=20000;
}
// if(Setting.IOConfig[CurrentIOPin]!=IOCONFIG_SERVO)
// {
// ServoMask=0xff;
// return;
// }
ServoMask=NOT_IOMASK[ServoIndex];
if(ServoIndex==INPUT_COUNT)
{
if(ServoIdleTime<0)
return;
TMR1= (~((unsigned short)ServoIdleTime))+1;
}
else
{
_temp = ServoTimer[ServoIndex];
ServoIdleTime-= _temp;
if(_temp==0)
return;
TMR1= (~_temp)+1;
}
TMR1IF=0;
TMR1IE=1;
BMask = IOMASK[ServoIndex];
di();
if(ServoIndex<5)
{
#ifndef USEASM
PORTB |= BMask;
#else
{
#asm
movf DoRCServo@BMask,w
iorwf 13,f
#endasm
}
#endif
}
else
{
#ifndef USEASM
PORTA |= BMask;
#else
{
#asm
movf DoRCServo@BMask,w
iorwf 12,f
#endasm
}
#endif
}
TMR1ON=1;
ei();
}
}