Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | AVRclub | [AVR club] Configuring the UART


Advertise Here

Atmel AVR Microcontroller discussion group.

[AVR club] Configuring the UART - esam aljonaid - Jun 13 13:14:41 2008

/*
Configuring the UART and using the Standard Library for serial communicatio=
n=20
=A0Serial.C
=A0
=A0Written by Jeffrey J. Richardson=A0Aug. 17, 2002
=A0
=A0Simple program that first initializes the serial port for 9600, N, 8, 1.
=A0Second, the program initializes PortC for output to the LEDs.
=A0Third, the program enters an endless loop that...
=A0=A0Uses the standard library function to get a serial character
=A0=A0Display the character on the LEDs
=A0=A0Echo the character back to the sending device
=A0
=A0Uses the MegaAVR-DEVelopment Board available from PRLLC
=A0=A0with an ATmega163 controller operating at 6MHz.
*/
#include
#include
#define XTAL 6000000L
#define BAUD 9600
main()
=A0{
=A0unsigned char ch;=A0=A0=A0=A0// 8 bit variable to store the serial chara=
cter
=A0unsigned int UBR;=A0=A0=A0=A0// 16 bit variable to hold serial port calc=
ulations
=A0UBR =3D XTAL / 16 / BAUD - 1;=A0=A0=A0// calculate the load values
=A0UBRR =3D (unsigned char)(UBR & 0xFF);=A0=A0// load the lower 8 bits
=A0UBRRHI =3D (unsigned char)(UBR >> 8);=A0=A0// load the upper bits
=A0UCSRB =3D 0x18;=A0=A0=A0=A0=A0// enable transmit and receive
=A0
=A0DDRC =3D 0xFF;=A0=A0=A0=A0=A0// setup PortC for output
=A0PORTC =3D 0x00;=20
=A0
=A0while(1)=A0=A0=A0=A0=A0// do forever...
=A0=A0{
=A0=A0ch =3D getchar();=A0=A0=A0=A0// get a character from the serial port
=A0=A0PORTC =3D ~ch;=A0=A0=A0=A0// display the character on the LEDs
=A0=A0putchar(ch);=A0=A0=A0=A0// send the character back to the terminal
=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0
B.R
=20=20=20=20=20=20

[Non-text portions of this message have been removed]
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )