0% found this document useful (0 votes)
66 views

AVR Program For Serial Interface

This program initializes the serial port for 9600 baud communication and configures PortC for output to LEDs. It then enters a loop that receives serial characters, displays them on the LEDs by inverting the character value, and echoes the characters back to the sending device. The program is designed to run on an ATmega163 microcontroller operating at 6MHz on a development board from PRLLC.

Uploaded by

aar9999
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

AVR Program For Serial Interface

This program initializes the serial port for 9600 baud communication and configures PortC for output to LEDs. It then enters a loop that receives serial characters, displays them on the LEDs by inverting the character value, and echoes the characters back to the sending device. The program is designed to run on an ATmega163 microcontroller operating at 6MHz on a development board from PRLLC.

Uploaded by

aar9999
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

/*

Serial.C

Written by Jeffrey J. Richardson Aug. 17, 2002

Simple program that first initializes the serial port for 9600, N, 8, 1.
Second, the program initializes PortC for output to the LEDs.
Third, the program enters an endless loop that...
Uses the standard library function to get a serial character
Display the character on the LEDs
Echo the character back to the sending device

Uses the MegaAVR-DEVelopment Board available from PRLLC


with an ATmega163 controller operating at 6MHz.

*/

#include<mega163.h> Constants used to calculate the


#include<stdio.h> UART configuration registers.
#define XTAL 6000000L
#define BAUD 9600

main()
{
unsigned char ch; // 8 bit variable to store the serial character
unsigned int UBR; // 16 bit variable to hold serial port calculations

UBR = XTAL / 16 / BAUD - 1; // calculate the load values


UBRR = (unsigned char)(UBR & 0xFF); // load the lower 8 bits
UBRRHI = (unsigned char)(UBR >> 8); // load the upper bits
UCSRB = 0x18; // enable transmit and receive

DDRC = 0xFF; // setup PortC for output


PORTC = 0x00;

while(1) // do forever...
{
ch = getchar(); // get a character from the serial port
PORTC = ~ch; // display the character on the LEDs
putchar(ch); // send the character back to the terminal
}
}

You might also like