for Crosswork AVR 1.3
#define BAUD 57600 //Enable 2x speed 28800 x 2 = 57600
#define BAUDRATE FOSC/16/BAUD-1
void USART_Init(unsigned int baudrate)
{
UBRRH = (unsigned char)(baudrate>>
;
UBRRL = (unsigned char)baudrate;
// Enable 2x speed
UCSRA = (1<<U2X_BIT);
// Enable receiver and transmitter
UCSRB = (1<<RXEN_BIT)|(1<<TXEN_BIT)|(1<<RXCIE_BIT);
// Async. mode, 8N1
UCSRC = (1 << URSEL) | (3 << UCSZ0);
}
void TxSerialPort(unsigned char data)
{
while (!(UCSRA & (1<<UDRE_BIT)));
UDR = data;
}
unsigned char RxSerialPort(void)
{
while (!(UCSRA & (1<<RXC_BIT)));
return UDR;
}
void main()
{
unsigned char dat;
USART_Init(BAUDRATE);
while(1)
{
dat=RxSerialPort();
TxSerialPort(dat);
}
}