Dynamixel rx-64 – Robotis Dynamixel RX-64 User Manual
Page 36
35
DYNAMIXEL
RX-64
 
/* 
Print value of Baud Rate. 
*/ 
void PrintBaudrate(void) 
{ 
 TxDString("\r\n 
RS232:");TxD32Dec((16000000L/8L)/((long)UBRR1L+1
L) ); TxDString(" BPS,"); 
TxDString(" RS485:");TxD32Dec((16000000L/8L)/((long)UBRR0L+1L) );
TxDString(" BPS");
} 
 
 
/*Hardware Dependent Item*/ 
#define TXD1_READY 
bit_is_set(UCSR1A,5)
//(UCSR1A_Bit5)
#define TXD1_DATA
(UDR1)
#define RXD1_READY
bit_is_set(UCSR1A,7)
#define RXD1_DATA
(UDR1)
 
#define TXD0_READY 
bit_is_set(UCSR0A,5)
#define TXD0_DATA
(UDR0)
#define RXD0_READY
bit_is_set(UCSR0A,7)
#define RXD0_DATA
(UDR0)
 
/* 
SerialInitialize() set Serial Port to initial state. 
Vide Mega128 Data sheet about Setting bit of register. 
SerialInitialize() needs port, Baud rate, Interrupt value. 
 
*/ 
void SerialInitialize(byte bPort, byte bBaudrate, byte bInterrupt) 
{ 
 if(bPort == SERIAL_PORT0) 
 { 
 UBRR0H = 0; UBRR0L = bBaudrate; 
 UCSR0A = 0x02; UCSR0B = 0x18; 
 if(bInterrupt&RX_INTERRUPT) sbi(UCSR0B,7); // RxD interrupt enable 
 UCSR0C = 0x06; UDR0 = 0xFF; 
 sbi(UCSR0A,6);//SET_TXD0_FINISH; // Note. set 1, then 0 is read 
 } 
 else if(bPort == SERIAL_PORT1) 
 { 
 UBRR1H = 0; UBRR1L = bBaudrate; 
 UCSR1A = 0x02; UCSR1B = 0x18; 
 if(bInterrupt&RX_INTERRUPT) sbi(UCSR1B,7); // RxD interrupt enable 
 UCSR1C = 0x06; UDR1 = 0xFF; 
 sbi(UCSR1A,6);//SET_TXD1_FINISH; // Note. set 1, then 0 is read 
 } 
} 
 
/* 
TxD8Hex() print data seperatly. 
ex> 0x1a -> '1' 'a'. 
*/ 
void TxD8Hex(byte bSentData) 
{ 
 byte bTmp; 
 
 bTmp =((byte)(bSentData>>4)&0x0f) + (byte)'0'; 
 if(bTmp > '9') bTmp += 7; 
 TxD8(bTmp); 
 bTmp =(byte)(bSentData & 0x0f) + (byte)'0'; 
 if(bTmp > '9') bTmp += 7; 
 TxD8(bTmp); 
} 
 
/* 
TxD80() send data to USART 0. 
*/ 
void TxD80(byte bTxdData) 
{ 
 while(!TXD0_READY); 
 TXD0_DATA = bTxdData; 
} 
 
/* 
TXD81() send data to USART 1. 
*/ 
void TxD81(byte bTxdData) 
{ 
 while(!TXD1_READY); 
 TXD1_DATA = bTxdData; 
} 
 
/* 
TXD32Dex() change data to decimal number system 
*/ 
void TxD32Dec(long lLong) 
{ 
 byte bCount, bPrinted; 
 long lTmp,lDigit; 
 bPrinted = 0; 
 if(lLong < 0) 
 { 
 lLong = -lLong; 
 TxD8('-'); 
 } 
 lDigit = 1000000000L; 
 for(bCount = 0; bCount < 9; bCount++) 
 { 
 lTmp = (byte)(lLong/lDigit); 
 if(lTmp) 
 { 
 TxD8(((byte)lTmp)+'0'); 
 bPrinted = 1; 
 } 
 else if(bPrinted) TxD8(((byte)lTmp)+'0'); 
 lLong -= ((long)lTmp)*lDigit; 
 lDigit = lDigit/10; 
 } 
 lTmp = (byte)(lLong/lDigit); 
 /*if(lTmp)*/ TxD8(((byte)lTmp)+'0'); 
} 
 
/* 
TxDString() prints data in ACSII code. 
*/ 
void TxDString(byte *bData) 
{ 
 while(*bData) 
 { 
 TxD8(*bData++); 
 } 
} 
 
/* 
RxD81() read data from UART1. 
RxD81() return Read data. 
*/ 
byte RxD81(void) 
{ 
 while(!RXD1_READY); 
 return(RXD1_DATA); 
} 
 
/* 
SIGNAL() UART0 Rx Interrupt - write data to buffer 
*/ 
SIGNAL (SIG_UART0_RECV) 
{ 
 gbpRxInterruptBuffer[(gbRxBufferWritePointer++)] = RXD0_DATA; 
}