// show the use of math operators (+, - , *, /, %) #include <avr/io.h> // standa
ID: 2085589 • Letter: #
Question
// show the use of math operators (+, - , *, /, %)
#include <avr/io.h> // standard AVR header file for IO ports
int main ()
{
init();
unsigned char a = 2; // can hold 0-255
unsigned char b = 4; //
DDRB = 0xFF; // PORTB is output (B5...B0)
while( 1) // loop forever
{
// addition
PORTB = a + b; // show result on portB
delay (5000); // show result for 5 sec
// subtraction b> a
PORTB = b-a;
delay(5000);
// subtraction b < a
PORTB = a -b;
delay(5000);
// multiplication
PORTB = a * b;
delay(5000);
// division
PORTB = a/b;
delay(5000);
// division
PORTB = b/a;
delay(5000);
// modulo
PORTB = b % a;
delay(5000);
// modulo
PORTB = a%b; // show result on portB
delay(5000); // show result for 5 sec
}
}
Explanation / Answer
At port B it shows addition of a &b for 5secs and later checks for a>b or not.If greater calculate a-b or b-a and for 5secs.similarly multiplication of a&b for 5 secs and division (quotient for 5 secs) and remainder for 5 secs.
please specify exact question.It is not clear
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.