Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program code to complete the task below. arduino receives external dat

ID: 2266071 • Letter: W

Question

Write a C program code to complete the task below.

arduino receives external data (keyboard input data) from USART port. only decimal number 0-9 can be use. Accumulate every data received until the sum of them exceed 30. Then stop receiving data and turn on the led light which is connected with pin 13 on the Arduino Uno Board ( the light should be off at the beginning).

for example: if the data input sequence is: 9, 5, 1, 6, 9, 2, .....

9+5+1+6+9+2 = 32>30, so at this time, disable receiving data and turn on the led. The transmission requires: 8 bits data; 1 stop bit; disable parity: 9600 baud rate.

you must design your own USART functions ( you cannot use any "serial.XXXXX")

Hint: You can think about using USART receive interrupt.

n 1] 120 uino rd points receiv Accumulae rite ecelved until the sum of them exceed 30 The th s co cected with pin 13 ont For example: if the data 9+5+1 +6+9+2 The transmission requires: 8 bits datas top bi; Disabl Paity 960 You must design your own USART funcetions (You cannot use any"Serial. r Hint: You can think about using USART reerie nterap. the Arduino input 32> 30, So at this time, disabl ASCII TABLE Decimal Hex Char Decimal Decimal Hex Char 0 NULL 32 ISTART OF HEADIN

Explanation / Answer

#include <avr/interrupt.h>
#include <avr/io.h>

#define USART_BAUDRATE 9600
void setup()
{
pinMode(13, OUTPUT);

UBRR0L = USART_BAUDRATE & 0xff;
UBRR0H = USART_BAUDRATE >> 8;
UCSR0C |= (1 << UCSZ00) | (1 << USBS0); // Use 8-bit character sizes
UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); // Turn on the transmission, reception, and Receive interrupt   
interrupts();
}

void loop()
{

}

ISR(USART0_RXC)
{  

if(UDR0 > 0 && UDR0 <= 10)

{

count = count + UDR0;

}

if(count >= 30)

{
digitalWrite(13, HIGH); // set the LED on

  UCSR0B &= ~(1 << RXEN0) // Making Receive bit 0 to stop receiving;

delay(1000); // wait for a second

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote