테스트 환경

AVR Studio 4.14

ATmega128 (16MHz) [뉴티씨 AB-M128Pro-A]


UART에서 printf()함수 사용.

#include <avr/io.h>

#include <stdlib.h>
#include <stdio.h>

void UartTx(char message) {
	while ((UCSR0A&0x20) == 0); 
	UDR0 = message;
	UCSR0A |= 0x20;
}

static int Putchar(char c, FILE *stream) {
	UartTx(c);
	return 0;
}

void Uart_Init(void) {
	UCSR0B = 0x08;
	UBRR0H = 0x00;
	UBRR0L = 0x67;
}
void Device_Init(void) {
	Uart_Init();
	
	fdevopen(Putchar,0);
}

int main(void) {

	Device_Init();

	printf("Hello World!!\n\r");

	while(1);

	return 0;
}