Sonsivri

Electronics => AVR, 8051 Family and ARM Area => Topic started by: edi14_10 on December 06, 2007, 03:50:15 15:50



Title: Serial Port Example AVR using Crosswork AVR
Post by: edi14_10 on December 06, 2007, 03:50:15 15:50
does anyone have an example using serial port in avr using crosswork AVR compiler?


Title: Re: Serial Port Example AVR using Crosswork AVR
Post by: zetd on December 06, 2007, 04:35:48 16:35
Hire is my test on Rowley Crosswork for AVR

credit is for [email protected]
http://www.holger-klabunde.de/index.html

i just mod his code and port from winavr (GNU) syntact to Rowley Crosswork for AVR (Actually GNU variant too)


hey edi14_10, try to port this library http://hubbard.engr.scu.edu/embedded/ , i have done with it


use for your reference



Title: Re: Serial Port Example AVR using Crosswork AVR
Post by: preecha on December 10, 2007, 08:54:25 08:54
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>>8);
    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);
  }
 
}


Title: Re: Serial Port Example AVR using Crosswork AVR
Post by: edi14_10 on December 11, 2007, 12:14:14 00:14
How about delay in crosswork? i didnt find delay.h. do we have to make the library by ourself?


Title: Re: Serial Port Example AVR using Crosswork AVR
Post by: metal on December 11, 2007, 02:01:44 14:01
delay cycles should work for you