Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Simple UART Code

2004-10-06 by JChavez@soboce.com

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..

Javier

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.