</pre><p>I can't use chinese in my archlinux, so....</p><p>This is my source code:</p><pre name="code" class="cpp">#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdio.h>
#define BAUDR0ATE 9600
#define BIT(bit) (1 << bit)
#define SET(ctl, bits) (ctl |= bits)
#define CLR(ctl, bits) (ctl &= ~bits)
#define WAIT_USART() while ( !( UCSR0A & BIT(UDRE0) ) )
int fputc(int data,FILE *f)
{
WAIT_USART();
UDR0 = (data=='\r') ? '\n' : data;
return data;
}
void USART_config()
{
// 设置波特率UBRR
UBRR0L = F_CPU/16/BAUDR0ATE -1;
UBRR0H = (F_CPU/16/BAUDR0ATE -1)>>8;
// 设置USART
SET(UCSR0B, BIT(RXEN0)+BIT(TXEN0)+BIT(RXCIE0) );
sei(); // 开启中断
}
int main()
{
fdevopen((int (*)(char, FILE*))fputc,0);
USART_config();
printf("Hello World!\n");
while (1);
}
ISR(USART_RX_vect)
{
putchar(UDR0);
}
Welcome to minicom 2.7
OPTIONS: I18n
Compiled on Sep 6 2015, 19:49:19.
Port /dev/ttyUSB0, 15:06:00
Press CTRL-A Z for help on special keys
Hello World!
That's all!