Spring Model Electronics Co.Ltd
TEL
:
+86-755-2974-9810 FAX
:
+86-755-2974-9779 www.springrc.com
(
v
:
1.0
)
Page 36 of 49
PORTA |= _BV(PA0);
// (Set the bus to host transmit state)
UCSR0A |= (1<<TXC0);
// (Clear written flag of UART0)
SendUart0Byte(0xFF);
// (Send the start byte 0xff)
SendUart0Byte(0xFF);
SendUart0Byte(id);
// (Send the servo’s ID)
SendUart0Byte(7);
// Send data length is parameter 2,parameter
length is 3
// (Send the length of frame)
SendUart0Byte(0x03);
// (Send command “WRITE DATA”)
SendUart0Byte(0x1E);
// (Send the start address of control register)
SendUart0Byte(temp_position_l);
// (Send the low byte of velocity)
SendUart0Byte(temp_position_h);
// (Send the high byte of velocity)
SendUart0Byte(temp_velocity_l);
// (Send the low byte of position)
SendUart0Byte(temp_velocity_h);
// (Send the high byte of position)
temp_sum = id + 7 + 0x03 + 0x1E + temp_posi temp_posi temp_velo
temp_velocity_h;
temp_sum = ~temp_sum;
// (calculate the checksum)
SendUart0Byte(temp_sum);
// (Send the checksum)
while ( !( UCSR0A & (1<<TXC0)) )
{
//
(Waiting for finishing sending)
;
}
PORTA |= _BV(PA1);
PORTA &= ~_BV(PA0);
// (Set the UART bus to host receiving state)
_delay_ms(2);
// (The bus will be overrode by slave after finishing sending
// to receive the answer, so here delays 2 ms.)
}
Duplicate & paste the above code to main.c documents,click
keep main.c
,
then
click
recompile procedure
,
u can see the compilation result in“Console“child window as
below
。