It depends on what AVR you are using however this shoul help..
void RS232_init(void)
{
outp(0x18, UCR);
//outp((char)UBR, UBRR);
outp(8, UBRR); // 12=38400 8=57600 3=115200
sbi(USR, TXC); // UART Trnsmt complete (clear TXC flag but logical
1)
cbi(DDRD, PD0); // RXD (UART input line)
sbi(DDRD, PD1); // TXD (UART ouput line)
}
uint8_t cin(void)
{
loop_until_bit_is_set(USR,RXC);
return(inp(UDR ));
}
void cout(uint8_t a)
{
outp(a, UDR);
loop_until_bit_is_set(USR,TXC);
sbi(USR, TXC); // UART Trnsmt complete (clear TXC flag but logical
1)
}
then in main ..
cout((cin());
Hope this helps..
JavierMessage
Re: [AVR-Chat] Simple UART Code
2004-10-06 by JChavez@soboce.com
Attachments
- No local attachments were found for this message.