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

21.(10 pts) Write two programs stored separately in two files. a) Main: 1) Defin

ID: 3349747 • Letter: 2

Question

21.(10 pts) Write two programs stored separately in two files. a) Main: 1) Defines an 8-bit global variable COUNTER. 2) Inializes the IRQ interrupt vector in the interrupt vector table. The name of the interrupt service routine is IRQ ISR 3) Sends the value of COUNTER every 10ms to an output port at address SD6. b) Write an interrupt service routine that counts the number of times itself is executed The name of the ISR is IRQ ISR. Every time the interrupt occurs, the 8-bit global variable COUNTER is incremented by one in this interrupt service routine.

Explanation / Answer

#define SET_HIGH(x) (x |= (unsigned char)(1 << 7))

#define MASK_HIGH(x) (x & (unsigned char)~(1 << 7))

#define TEST_HIGH(x) (x & (unsigned char)(1 << 7))

int foo (unsigned char n = 0) {

    static unsigned char i;

    if (n == 0) {

        SET_HIGH(n);

  }

    if (MASK_HIGH(i) >= 20) {

        return 0;

    }

    for (i = n; MASK_HIGH(i) < 20; ++i) {

        n = i;

        foo(MASK_HIGH(i) + 1);

        i = n;

    }

     return TEST_HIGH(i) != 0;

}

int main () {

    int r1 = foo();

    int r2 = foo();

  int r3 = foo();

    return 0;

}

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