AVR Microcontroller USART Communication Program, Exercises of Microprocessors

The code for a usart communication program using the avr microcontroller. The program includes the definition of global static variables, the implementation of usart_receive and usart_transmit functions, and the initialization and infinite loop of the main program.

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

parmila
parmila 🇮🇳

4.4

(9)

78 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
// ***********************************************************
// Project:
// Author:
// Module description:
// ***********************************************************
#include <avr\io.h> // Most basic include files
#include <avr\interrupt.h> // Add the necessary ones
#include <avr\signal.h> // here
// Define here the global static variables
//
unsigned char data;
void USART_receive()
{
while((UCSRA & 0x80)==0x00) //wait for RXC flag
{ ; }
data = UDR; //retrieve data from UDR
}
void USART_transmit()
{
while((UCSRA & 0x20)==0x00) //wait for UDRE flag
{ ; }
UDR = data; //load data to UDR for transmission
}
// Main program
//
int main(void)
{
UCSRA = 0x00; //control register initialization
UCSRB = 0x18; //enable transmitter and receiver
UCSRC = 0xBE; //async, odd parity, 2 stop bit,
//9 data bits
UBRRH = 0x00;
UBRRL = 0x33; //Baud Rate initialization
while(1)
{ // Infinite loop; define here the
USART_receive();
USART_transmit();
}
}
docsity.com

Partial preview of the text

Download AVR Microcontroller USART Communication Program and more Exercises Microprocessors in PDF only on Docsity!

// Project: // Author: // Module description: // *********************************************************** #include <avr\io.h> // Most basic include files #include <avr\interrupt.h> // Add the necessary ones #include <avr\signal.h> // here // Define here the global static variables // unsigned char data; void USART_receive() { while((UCSRA & 0x80)==0x00) //wait for RXC flag { ; } data = UDR; //retrieve data from UDR } void USART_transmit() { while((UCSRA & 0x20)==0x00) //wait for UDRE flag { ; } UDR = data; //load data to UDR for transmission } // Main program // int main(void) { UCSRA = 0x00; //control register initialization UCSRB = 0x18; //enable transmitter and receiver UCSRC = 0xBE; //async, odd parity, 2 stop bit, //9 data bits UBRRH = 0x00; UBRRL = 0x33; //Baud Rate initialization while(1) { // Infinite loop; define here the USART_receive(); USART_transmit(); } }

docsity.com