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

I am programming a function for the MSP430G2 launchpad with a 20 pin microchip f

ID: 3708764 • Letter: I

Question

I am programming a function for the MSP430G2 launchpad with a 20 pin microchip from Texas Instruments and the answer to the problem would be a "CountDown" function. My teacher gave us the below "Countup" function. Any hints or tips for finding the inverse of this?

void CountUp(void)
{
    switch (currentstate) {

    case 0 :
            currentstate = 1;
            P1OUT |= BIT6;
            P1OUT &= ~(BIT0);
            break;

    case 1 :
            currentstate = 2;
            P1OUT &= ~(BIT6);
            P1OUT |= BIT0;
            break;

    case 2 :
            currentstate = 3;
            P1OUT |= BIT6;
            P1OUT |= BIT0;
            break;

    case 3 :
            currentstate = 0;
            P1OUT &= ~(BIT6);
            P1OUT &= ~(BIT0);
            break;
    }
}

Explanation / Answer

void CountDown (void)
{
    switch (currentstate) {

    case 0 :
            currentstate = 3;
            P1OUT |= BIT6;
            P1OUT &= ~(BIT0);
            break;

    case 1 :
            currentstate = 0;
            P1OUT &= ~(BIT6);
            P1OUT |= BIT0;
            break;

    case 2 :
            currentstate = 1;
            P1OUT |= BIT6;
            P1OUT |= BIT0;
            break;

    case 3 :
            currentstate = 2;
            P1OUT &= ~(BIT6);
            P1OUT &= ~(BIT0);
            break;
    }
}