#define F_CPU 3333333UL #define BAUD_9600 ((4UL*F_CPU)/9600) #include #include #include /* In this exercise we will set up and use UART communication. The embedded debugger has a virtual com port that we will use to communicate with the computer. */ void uart_init(unsigned long baud){ //In this function, we want to initialize the UART. //Chapter 24.3 in datasheet tells us how this is done: //Set TX pin as output //Set the TX pin high //Fill in the baud rate in the 2 BAUD registers. (High and Low, you will need to do some bit shifting here) //We are going to use "async" mode, 1 stop bit and 8 bit character size. //Enable RX and TX //Enable interrupt on incoming data } // function to transmit data void uart_transmit(unsigned char data){ //In this function we will be send data. //First we should check that there isn't already data being sent // -if there is, we should probably wait for it to finish first //Put our new data into se sending register } int main(void) { //Initialize the UART with our function. //We will be using a baudrate of 9600 (defined as BAUD_9600 at the top of the file) sei(); //Enable global interrupt, important for anything here to work while (1) { //We don't really need to do anything here. //the ISR will handle receiving. } } //Interrupt service routine for the receiver. ISR(USART0_RXC_vect){ //Read out the received data to a variable //Do things with data. Perhaps send something back? }