Microcontroller › AVR › I have ATMEGA 16 i want to serial communication to pc terminal. › Hi..check this functions
February 25, 2013 at 6:52 am
#9179
Participant
Hi..
check this functions once….
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600(0.2%)
// char size: 8 bit
// parity: Disabled
void UART_Init(void)
{
// At 4MHz oscillator
int baud = 25;
/* Set baud rate */
UBRRH = (unsigned char)(baud>>
;

UBRRL = (unsigned char)baud;
/* Enable Receiver and Transmitter */
//RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8
UCSRB = 0;
UCSRB = (1<<RXCIE)| (1<<RXEN) | (1<<TXEN);
/* Set frame format: 8data, 1stop bit */
//URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL
UCSRC = 0;
UCSRC = (1<<URSEL)| (1<<UCSZ1)| (1<<UCSZ0);
}
void UART_TransmitByte( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) );
/* Put data into buffer, sends the data */
UDR = data;
}