[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Help setting up USART on ATmega32 in C
From: |
Helix |
Subject: |
Re: [avr-gcc-list] Help setting up USART on ATmega32 in C |
Date: |
Sat, 14 Feb 2004 08:44:22 +0100 |
> Any ideas?
I use this code with my __AVR_AT90S8515__
HTH
/* Run the UART at 9600 baud */
// XTAL=7.3728 Baud=9600 UBRR=47
#define BAUD9600 47 /* @4MHz internal RC-osc. */
/* Initialize UART */
void InitUART( unsigned char baudrate )
{
UBRR = baudrate; /* Set the baud rate */
UCR = ( (1<<RXEN) | (1<<TXEN) ); /* Enable UART receiver and transmitter
*/
}
/* Read and write functions */
unsigned char ReceiveByte( void )
{
while ( !(USR & (1<<RXC)) ) /* Wait for incomming data */
; /* Return the data */
return UDR;
}
void TransmitByte( unsigned char data )
{
while ( !(USR & (1<<UDRE)) )
; /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}
int main()
{
InitUART( BAUD9600 ) ;
while (1) {
// primitive test of 'uart_putchar'
TransmitByte('H');
TransmitByte('e');
TransmitByte('l');
TransmitByte('l');
TransmitByte('o');
TransmitByte('\r');
TransmitByte('\n');
}
return 0;
}