
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 1
This page cannot be seen from the preview
Don't miss anything!

// 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(); } }