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

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

#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; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!