Page 1 of 1

SC08A with P18F4580

PostPosted: Thu Feb 28, 2013 7:48 pm
by twinsleong
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
     }
  }
}

Re: SC08A with P18F4580

PostPosted: Fri Mar 01, 2013 9:40 am
by gadgetng
First i am not familiar with mikroC. Anyway, i used SC08A before. Maybe you can try to start with simple code which just activate the servo. The servo will hold at its position to make sure all the hardware set up is correct before going further to programming.

Re: SC08A with P18F4580

PostPosted: Thu Mar 07, 2013 12:35 am
by twinsleong
Thanks. Found out that the problem was actually due to the board I was using. :oops: