avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] simple USART (RS232) example for ATmega48


From: Parthasaradhi Nayani
Subject: Re: [avr-gcc-list] simple USART (RS232) example for ATmega48
Date: Tue, 19 Jul 2005 16:16:32 -0700 (PDT)

--- address@hidden wrote:

> Hi all,
> 
> i'm looking for a simple c (AVR-GCC) example program
> demonstrating the use of the 
> USART0 (as RS232) of my ATmega48.

Hello,

Here are some program snippets. The following
functions are written for Mega8. Please change the
name of registers if need be.


 
void USART_Init(void)
   { 
    UBRRH = 0x00;
    UBRRL= 47;          // 9600 baud rate for external
7.6 MHz crystal
    
    UCSRB=0x98; 
        UCSRC=0x86;     
   }

// send one byte converted to ASCII
 void sendbyte(unsigned char dat) //function to send
0x38 as '3' and '8' onto serial port
   {
    unsigned char ftmp;
        
    ftmp = (dat >> 4);
        ftmp += (ftmp > 9 ? 0x37 : 0x30);
        
        sendchar(ftmp);  // transmit the character to
hyperterminal
        
        ftmp=dat & 0x0f;
        ftmp += (ftmp > 9 ? 0x37 : 0x30);
        sendchar(ftmp);
   }

// send one ASCII character to serial port
  void sendchar(unsigned char dat)
  {
   UDR=dat;
   while(!(UCSRA & 0x40));
    UCSRA|= 0x40;
  }

// send a string to serial port
  void USART_TRANS(unsigned char *ptr)  
   {       
   while(*ptr)
    {
         UDR=*ptr++;
         while (!(UCSRA & 0x40));   //Wait for transmission
complete 
           UCSRA = 0x40;          
        }
   } 

HTH

Nayani P



                
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]