#include "avr/io.h"
static void io_init(void)
{
PORTA = 0x0;
DDRA = 0x0;
// PortB
PORTB = 0xff;
DDRB = 0xff;
// PortC
PORTC = 0x0;
DDRC = 0x0;
// PortD
PORTD = 0x0;
DDRD = 0x0;
}
void uart_init(void)
{
// Baud Rate: 19200
// Character Size: 8-bit
// Mode: Asynchronous
// Parity: Disabled
// Stop Bit: 1-bit
UBRRL = 0x23;
UBRRH = 0x00;
UCSRA = 0x00;
UCSRC = 0x86;
UCSRB = 0x10;
}
unsigned char USART_Receive( void )
{
/* 等待接收数据*/
while ( !(UCSRA & (1<
;
/* 从缓冲器中获取并返回数据*/
return UDR;
}
int main(void)
{ uint8_t tmp;
io_init();
uart_init();
while(1)
{ tmp=USART_Receive();
PORTB=tmp; //收到的数据送到PORTB
}
}
|