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;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.