Dynamixel rx-28 – Robotis RX-28 User Manual

Page 37

Advertising
background image

DYNAMIXEL

RX-28

}

/*

Print value of Baud Rate.

/*

*/

TXD81() send data to USART 1.

void PrintBaudrate(void)

*/

{

void TxD81(byte bTxdData)

TxDString("\r\n

RS232:");TxD32Dec((16000000L/8L)/((long)UBRR1L+1
L) ); TxDString(" BPS,");

{
while(!TXD1_READY);
TXD1_DATA = bTxdData;

TxDString(" RS485:");TxD32Dec((16000000L/8L)/((long)UBRR0L+1L) );

TxDString(" BPS");

}

}

/*

TXD32Dex() change data to decimal number system

*/

/*Hardware Dependent Item*/

void TxD32Dec(long lLong)

#define TXD1_READY

bit_is_set(UCSR1A,5)

//(UCSR1A_Bit5)

{
byte bCount, bPrinted;

#define TXD1_DATA

(UDR1)

long lTmp,lDigit;

#define RXD1_READY

bit_is_set(UCSR1A,7)

bPrinted = 0;

#define RXD1_DATA

(UDR1)

if(lLong < 0)

{

#define TXD0_READY

bit_is_set(UCSR0A,5)

lLong = -lLong;

#define TXD0_DATA

(UDR0)

TxD8('-');

#define RXD0_READY

bit_is_set(UCSR0A,7)

}

#define RXD0_DATA

(UDR0)

lDigit = 1000000000L;

for(bCount = 0; bCount < 9; bCount++)

/*

{

SerialInitialize() set Serial Port to initial state.

lTmp = (byte)(lLong/lDigit);

Vide Mega128 Data sheet about Setting bit of register.

if(lTmp)

SerialInitialize() needs port, Baud rate, Interrupt value.

{

TxD8(((byte)lTmp)+'0');

*/

bPrinted = 1;

void SerialInitialize(byte bPort, byte bBaudrate, byte bInterrupt)

}

{

else if(bPrinted) TxD8(((byte)lTmp)+'0');

if(bPort == SERIAL_PORT0)

lLong -= ((long)lTmp)*lDigit;

{

lDigit = lDigit/10;

UBRR0H = 0; UBRR0L = bBaudrate;

}

UCSR0A = 0x02; UCSR0B = 0x18;

lTmp = (byte)(lLong/lDigit);

if(bInterrupt&RX_INTERRUPT) sbi(UCSR0B,7); // RxD interrupt enable

/*if(lTmp)*/ TxD8(((byte)lTmp)+'0');

UCSR0C = 0x06; UDR0 = 0xFF;

}

sbi(UCSR0A,6);//SET_TXD0_FINISH; // Note. set 1, then 0 is read

}

/*

else if(bPort == SERIAL_PORT1)

TxDString() prints data in ACSII code.

{

*/

UBRR1H = 0; UBRR1L = bBaudrate;

void TxDString(byte *bData)

UCSR1A = 0x02; UCSR1B = 0x18;

{

if(bInterrupt&RX_INTERRUPT) sbi(UCSR1B,7); // RxD interrupt enable

while(*bData)

UCSR1C = 0x06; UDR1 = 0xFF;

{

sbi(UCSR1A,6);//SET_TXD1_FINISH; // Note. set 1, then 0 is read

TxD8(*bData++);

}

}

}

}

/*

/*

TxD8Hex() print data seperatly.

RxD81() read data from UART1.

ex> 0x1a -> '1' 'a'.

RxD81() return Read data.

*/

*/

void TxD8Hex(byte bSentData)

byte RxD81(void)

{

{

byte bTmp;

while(!RXD1_READY);

return(RXD1_DATA);

bTmp =((byte)(bSentData>>4)&0x0f) + (byte)'0';

}

if(bTmp > '9') bTmp += 7;

TxD8(bTmp);

/*

bTmp =(byte)(bSentData & 0x0f) + (byte)'0';

SIGNAL() UART0 Rx Interrupt - write data to buffer

if(bTmp > '9') bTmp += 7;

*/

TxD8(bTmp);

SIGNAL (SIG_UART0_RECV)

}

{

gbpRxInterruptBuffer[(gbRxBufferWritePointer++)] = RXD0_DATA;

/*

}

TxD80() send data to USART 0.

*/

void TxD80(byte bTxdData)

{

while(!TXD0_READY);


TXD0_DATA = bTxdData;

36

Advertising