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

Please solve ALL parts of this ONE question. I dont have any more questions left

ID: 3599504 • Letter: P

Question

Please solve ALL parts of this ONE question.  I dont have any more questions left on chegg so please answer them correctly in details. Thank you.

Programming Language: C

Write all code required to: a. enable continuouse monitoring of bits 4 and 5 of port B b. turn on the led attached to bit 1 of port B when bit 4 is low and bit 5 is high C. turn on led attached to bit 2 of port B when bit 4 is high and bit 5 is low. d. flash both LEDs on and off with ¼ second on-time and 1/5 second off-time when bits 4 and 5 are low e. turn off both LEDs when bits 4 and 5 are high. Hint: All checks should be inside of a single while loop. Hint: You will use no while-loops inside of the single while loop. Hint: for part d, turn on the leds for prescribed time and off for prescribed time only once each while-loop cycle. This will recurr each time through the loop as long as the input bits are unchanged resulting in the flashing pattern. Hint: each time the input pattern changes, you will need to be sure that both LEDs are placed in the correct state, so you will have to set the output correctly for both LEDs for each condition (b through e) above each cycle.

Explanation / Answer

#include <avr/io.h>
#include <avr/delay.h>
void sleep(uint8_t millisec)
{
while(millisec)
{
delay_ms(1);
millisec--;
}
}
main()
{
DDRC |=1<<PC5; //enable pin 28 red1
DDRC |=1<<PC4; //enable pin 27 yellow1
DDRC |=1<<PC3; //enable pin 26 green1
DDRC |=1<<PC2; //enable pin 25 red2
DDRC |=1<<PC1; //enable pin 24 yellow2
DDRC |=1<<PC0; //enable pin 23 green2
while(1)
{
PORTC &= ~(1<<PC5); //on red1 pin28
PORTC |=(1<<PC0); //off green2 pin23
PORTC |=(1<<PC4); //off yellow1 pin27
PORTC |=(1<<PC3); //off green1 pin26
PORTC |=(1<<PC2); //off red2 pin32
PORTC |=(1<<PC1); //off yellow2 pin24
sleep(50);
PORTC |=(1<<PC5); //off red1 pin28
PORTC &= ~(1<<PC4); //on yellow1 pin27
sleep(50);
PORTC |=(1<<PC4); //off yellow1 pin27
PORTC &= ~(1<<PC3); //on green1 pin26
sleep(50);
PORTC |=(1<<PC3); //off green1 pin26
PORTC &= ~(1<<PC2); //on red2 pin32
sleep(50);
PORTC |=(1<<PC2); //off red2 pin32
PORTC &= ~(1<<PC1); //on yellow2 pin24
sleep(50);
PORTC |=(1<<PC1); //off yellow2 pin24
PORTC &= ~(1<<PC0); //on green2 pin 23
sleep(50);
PORTC |=(1<<PC0); //off green2 pin23
PORTC &= ~(1<<PC1); //on yellow2 pin24
sleep(50);
PORTC |=(1<<PC1); //off yellow2 pin24
PORTC &= ~(1<<PC2); //on red2 pin32
sleep(50);
PORTC |=(1<<PC2); //off red2 pin32
PORTC &= ~(1<<PC3); //on green1 pin26
sleep(50);
PORTC |=(1<<PC3); //off green1 pin26
PORTC &= ~(1<<PC4); //on yellow1 pin27
sleep(50);
}
}