Docsity

AVR Microcontroller USART Communication Program, Exercises of Microprocessors

Toggle sidebar
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