SC08A with P18F4580
Posted: Thu Feb 28, 2013 7:48 pm
I've been trying to program the servo controller with the microcontroller 18F4580 but can't seem to get it to work. I'm using MikroC to work this around. I hope you could help point out where my mistake is in doing this,
- CODE: SELECT_ALL_CODE
void main() {
TRISB = 0X0F;
UART1_Init(9600);
// for activating servo channel
UART1_Write(192); //select all servo
UART1_Write(1); //activate all servo
UART1_Write(129); //select all servo
UART1_Write(62); //activate all servo
UART1_Write(32); //select all servo
while (UART1_Read() !=0x04){
}
//for position and speed command
while(1){
if (PORTB.F0 == 0){
Delay_ms(40);
// for activating servo channel
UART1_Write(225); //position & speed command servo 1
UART1_Write(62); //higher byte position
UART1_Write(32); //lower byte position
UART1_Write(0); //servo speed
}
//for position and speed command
if (PORTB.F1 == 0){
Delay_ms(40);
// for activating servo channel
UART1_Write(225); //position & speed command servo 1
UART1_Write(31); //higher byte position
UART1_Write(16); //lower byte position
UART1_Write(0); //servo speed
}
//for position and speed command
if(PORTB.F2 == 0){
Delay_ms(40);
// for activating servo channel
UART1_Write(225); //position & speed command servo 1
UART1_Write(93); //higher byte position
UART1_Write(48); //lower byte position
UART1_Write(0); //servo speed
}
}
}