If it will help you that's my control programm in picBASIC
works for 877a @ 20mhz
raw code, it's many ways to speed it up
a var byte
b var word
s0 var word
s1 var word 's0-s5 variables for servo position, usually 50-250, but can be 0-255
s2 var word ' for fast control chip must run at 20mhz, but command PULSOUT
s3 var word 'adjusted for 4mhz xtal, so we need to multiply a value by 5.
s4 var word 'that's why we need a WORD variable (0-65535)
s5 var word
DEFINE OSC 20 'xtal at 20mhz, have effect for HSERIN, but not pulsout
DEFINE HSER_RCSTA 90h 'Enable transmit register
DEFINE HSER_TXSTA 24h 'high baudrate, 115.2kbps
DEFINE HSER_CLOERR 1 'automatically clear overrun buffer
DEFINE HSER_BAUD 115200
s0 = 1250: s1 = 715: s2 = 750: s3 = 750: s4 = 750: s5 = 750 'start values of servo positions (*5!!!)
low portc.0
low portc.1
low portc.2 'all of it can be 'portc = 0'
low portc.3
low portc.4
low portc.5
au: 'START
pulsout portc.0, s0'*5 'pulse on pin C.0 for s0 time (already multiplied by 5)
pulsout portc.1, s1'*5
pulsout portc.2, s2'*5
pulsout portc.3, s3'*5 'on all of them... with it's value
pulsout portc.4, s4'*5
pulsout portc.5, s5'*5
auNEW:
hserin 50, au, [a,b] 'receive two characters serially, place them in a and b variables
'if not received within 50msec, goto AU
rcsta.4 = 0 'turn off receiver
rcsta.4 = 1 'then turn it back on, like clearing the buffer
b = b * 5 'a - number of servo, b position (0-255!), for our purpose we have to multiply it
if a = "1" then s0 = b: pulsout portc.0, s0 'you need to send serially just two characters, first, number of
if a = "2" then s1 = b: pulsout portc.1, s1 'servo, second, position
if a = "3" then s2 = b: pulsout portc.2, s2 'example, send "2" then send "150", then "1" and "50" and go on
if a = "4" then s3 = b: pulsout portc.3, s3 '
if a = "5" then s4 = b: pulsout portc.4, s4
if a = "6" then s5 = b: pulsout portc.5, s5
goto auNEW
it's much time to send programm again to AU
for every pulsout again, possibly a new values of
a and b already in the buffer, we need to get them
fast, preventing buffer overflow
------------------------------------------------------------
here is the whole device at work
https://uk.youtube.com/watch?v=8sWki9Y8S8Y