#define F_CPU 16000000 //Clock frequency
#include <avr/io.h>
void USART_Init()
{
unsigned int ubrr = 103; // 9600 for 16MHz
// Set baud rate
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
// Enable receiver and transmitter
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
// Set frame format: 8N1
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
}
void USART_putc( unsigned char data )
{
// Wait for empty transmit buffer
while( !( UCSR0A & (1<<UDRE0)) ) ;
// Put data into buffer, sends the data
UDR0 = data;
}
unsigned char USART_getc( void )
{
// Wait for data to be received
while( !(UCSR0A & (1<<RXC0)) ) ;
// Get and return received data from buffer
return UDR0;
}
int main(void)
{
unsigned char c;
// Setup USART
USART_Init();
while(1)
{
c = USART_getc();
USART_putc(c);
}
return 0;
}
AVRStudio 4 컴파일하고
Tera Term 이용하고 있는데
1을 입력하면 다시 1을 입력받는 코드인데
계속 돌아가지가 않네요.
어느 부분이 잘못됐는지 알수있을까요?
proteus 에서는 되는 것을 봤습니다.^^