Atmega128

AX-12A


tx만 물려서 돌려봄


빨랑빨랑 배워야할듯






#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>


void SetCheckSum(unsigned char *pc)
{
	int i;

	pc[8] = 0;

	for(i=2; i<8; i++) {
		pc[8] += pc[i];
	}

	pc[8] = ~pc[8];
}

void SendData(unsigned char address, unsigned short value)
{
	unsigned char TxData[9] = {0xff, 0xff, 0x01, 0x05, 0x03}; // ID, Length, Instruction
	int i;

	TxData[5] = address;
	TxData[6] = (unsigned char)((unsigned int)value & 0xff);
	TxData[7] = (unsigned char)((unsigned int)value >> 8);
	SetCheckSum(TxData);

	for(i=0; i<9; i++) {
		UCSR0A |= 0x40;
		while(!(UCSR0A & 0x20));
		UDR0 = TxData[i];
	}
	while(!(UCSR0A & 0x40));
}


int main()
{
	UCSR0A = 0x02;
	UCSR0B = 0x08;
	UCSR0C = 0x06;
	UBRR0H = 0x00;
	UBRR0L = 0x01; // Baudrate: 1Mbps

	_delay_ms(200);

	// speed
	SendData(0x20, 100);

	_delay_ms(1000);


	while (1) {
		SendData(0x1e, 100);
		_delay_ms(1000);

		SendData(0x1e, 1000);
		_delay_ms(1000);
	}

	return 0;
}


저작자 표시 비영리 변경 금지

'Project/ > Humanoid' 카테고리의 다른 글

휴머노이드 01) AX-12  (0) 2013/12/15
휴머노이드 00) 메모  (0) 2013/11/01
Posted by Gogil
TAG

댓글을 달아 주세요