avr 2560 串口输出


/*
* GccApplication1.cpp
*
* Created: 2013/8/21 星期三 13:32:34
* Author: zyl
*/


#include
#include
#include

#define fosc 8000000
#define baud 115200

void uart0_init(void)

{

UCSR0B = 0x00;

UCSR0A = 0x00;

UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);

UBRR0L = (fosc / 16 / (baud + 1)) % 256;

UBRR0H = (fosc / 16 / (baud + 1)) / 256;

UCSR0B = (1 << RXEN0) | (1 << TXEN0);

}

void putchar0(unsigned char c)

{

while (!(UCSR0A & (1 << UDRE0)))
;

UDR0 = c;

}

unsigned char getchar0(void)

{

while (!(UCSR0A & (1 << RXC0)))
;

return UDR0;

}

void puts0(char *s)

{

while (*s)

{

putchar0(*s);

s++;

}

putchar0(0x0a);

putchar0(0x0d);

}

int main(void)

{

unsigned char i;

uart0_init();

puts0("HELLO!");

while (1)

{

puts0("test ok!");
_delay_ms(1000);

}
return 0;
}


你可能感兴趣的:(avr 2560 串口输出)