Add serial input to the AVR: input characters from the PC using terminal emulato
ID: 671442 • Letter: A
Question
Add serial input to the AVR: input characters from the PC using terminal emulator USB/serial interface that will echo characters typed by the user, that will change ONLY lower case alpha characters to upper case before transmitting them on the serial.
#include <avr/io.h>
#define FOSC 16000000 //CLOCK SPEED
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
unsigned char USART_Receive(void)
{
/* Wait for data to be received */
while (!(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) )
;
/* Put data into buffer, sends the data */
UDR0 = data;
}
void USART_Init(unsigned int ubrr)
{
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char) ubrr;
UCSR0B =(1<<RXEN0) | (1<<TXEN0);
UCSR0C = (3<<UCSZ00);
}
int main(void)
{
USART_Init(MYUBRR);
while (1)
{
for ()
{
USART_Transmit();
}
}
}
Explanation / Answer
Use the following library functions along with the code in the question:
toupper()
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
int main() {
char c, uc;
cout << " Enter the input characters for the serial AVR";
cin >> c;
uc = toupper(c);
cout << " You entered " << c << " Uppercased " << uc ;
// call the USART_Transmit function to feed the AVR serial
USART_Transmit(uc);
return 0;
} // end main - Siva
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.