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

Modify the program to accept port interrupt from a switch. Initially, the system

ID: 3860605 • Letter: M

Question

Modify the program to accept port interrupt from a switch. Initially, the system is toggling the two LEDs every 2 seconds. Whenever a port interrupt occurs, the LEDs will go to their original states for 5 seconds and then continue toggling every 2 seconds.

#include <msp430.h>

#define RedLED BIT0
#define GreenLED BIT6
#define BUTTON BIT3

#define RedLEDToggle (P1OUT ^= RedLED)
#define GreenLEDToggle (P1OUT ^= GreenLED)

// 10 seconds, assuming 32768 Hz ACLK source and divider 8
#define TIMER_PERIOD (10u*(32768/8))

void main(void)
{
    WDTCTL = WDTPW | WDTHOLD;

    P1DIR = RedLED | GreenLED;
    P1OUT = RedLED | GreenLED;

    // reset timer A config (not strictly needed)
    TACTL = TACLR;

    // ACLK as clock source, divider 8, continuous mode, interrupt enabled
    TACTL = TASSEL_1 | ID_3 | MC_2 | TAIE;

    // set the period
    TACCR1 = TIMER_PERIOD;

    // enable capture/compare interrupts for CCR1
    TACCTL1 = CCIE;

    _enable_interrupts();

    LPM1;
  
    if()
}

#pragma vector=TIMER0_A1_VECTOR

__interrupt void Timer_A(void)
{
    switch (TAIV) {
    case 0x02:
        // CCR1 interrupt
        RedLEDToggle;
        GreenLEDToggle;
        // set the time of the next interrupt
        TACCR1 += TIMER_PERIOD;
        break;
    }
}

Explanation / Answer

Even though the toggle can be done by 'millis' that I have handled previously in many cases here I have used a function called delay. Here I have made some modifications in the code. Do make some modifications if required.

#include <msp430.h>
#define RedLED BIT0
#define GreenLED BIT6
#define BUTTON BIT3
#define RedLEDToggle (P1OUT ^= RedLED)
#define GreenLEDToggle (P1OUT ^= GreenLED)
// 10 seconds, assuming 32768 Hz ACLK source and divider 8
#define TIMER_PERIOD (10u*(32768/8))

void Delay(unsigned short long time);

void main(void)
{
WDTCTL = WDTPW | WDTHOLD;
P1DIR = RedLED | GreenLED;
P1OUT = RedLED | GreenLED;
// reset timer A config (not strictly needed)
TACTL = TACLR;
// ACLK as clock source, divider 8, continuous mode, interrupt enabled
TACTL = TASSEL_1 | ID_3 | MC_2 | TAIE;
// set the period
TACCR1 = TIMER_PERIOD;
// enable capture/compare interrupts for CCR1
TACCTL1 = CCIE;
_enable_interrupts();
//Delay(50000);
LPM1
//Delay(20000);

}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
switch (TAIV) {
case 0x02:
// CCR1 interrupt
RedLEDToggle;
GreenLEDToggle;
Delay(20000);
// set the time of the next interrupt
TACCR1 += TIMER_PERIOD;
break;
case 0x05:
Delay(50000);
break;
}

void Delay(unsigned short long time)
{
unsigned short long c;
for(c=0; c<time; c++);
}
}

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