/*------------------------------------------------------------------------------ * File: p1.c * Function: Prints out variables according to their Data Type with the size and the ranges of the variables * Description: * Input: None * Output: " * Author(s): Noah Woodlee * Lab Section: 09 * Date: Nov 1, 2021 *----------------------------------------------------------------------------*/ #include #define SW1_PRESSED ((BIT0&P1IFG)==0) // SW1 Status #define SW2_PRESSED ((BIT1&P1IFG)==0) // SW2 Status int Up =1; int main(void) { WDTCTL = WDT_MDLY_8; // 8 ms interval _EINT(); // Enable interrupts IE1 |= WDTIE; // Enable WDT interrupt P2DIR |= (BIT1 + BIT2); // P2.1 and P2.2 set up as output P2SEL &= ~BIT1; // Clear P2.1 P2OUT |= BIT1; // Turn on LED2 P2OUT &= ~BIT2; // Turn Off LED1 P2SEL |= BIT2; // P2.2 special function (TB0 output) TB0CTL = TBSSEL_2 | MC_1; // Upmode TB0CCTL1 |= (OUTMOD_2 + CCIE); // TB1 output is in Up mode and Interrupt TB0CCTL0 = CCIE; // TB0 count triggers interrupt TB0CCR0 = 750; // Set TB0 (and maximum) count value TB0CCR1 = Up; // Set TB1 count value P1IE |= BIT0; // P1.0 interrupt enabled P1IE |= BIT1; // P1.1 interrupt enabled P1IES |= BIT0; // P1.0 hi/low edge P1IFG &= ~BIT0; // P1.0 IFG cleared P1IES |= BIT1; // P1.1 hi/low edge P1IFG &= ~BIT1; // P1.1 IFG cleared _BIS_SR(LPM0_bits + GIE); // Enter Low Power Mode 3 } #pragma vector = TIMERB0_VECTOR __interrupt void timerISR(void) { P2OUT |= BIT1; // Turn off LED2 TB0CCTL0 &= ~CCIFG; // Clear interrupt flag } #pragma vector = TIMERB1_VECTOR __interrupt void timerISR2(void) { P2OUT &= ~BIT1; // Toggle LED2 TB0CCTL1 &= ~CCIFG; // Clear interrupt flag } // Watchdog Timer interrupt service routine #pragma vector=WDT_VECTOR __interrupt void watchdog_timer(void) { TB0CCR1 += Up; // Up=1, CCR1 will increase; Up = -1 CCR1 will decrease if(TB0CCR1 == 750){ // If CCR1 is upper-bound, Up becomes -1 Up = -1; } if(TB0CCR1 ==0 ){ // If CCR1 is upper-bound, Up becomes 1 Up = 1; } } // Port 1 interrupt service routine #pragma vector = PORT1_VECTOR __interrupt void Port1_ISR (void) { if(!SW1_PRESSED) WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer } else if(!SW2_PRESSED) WDTCTL = WDT_MDLY_8; // 8 ms interval P1IES |= BIT0; // P1.0 hi/low edge P1IFG &= ~BIT0; // P1.0 IFG cleared P1IES |= BIT1; // P1.1 hi/low edge P1IFG &= ~BIT1; // P1.1 IFG cleared }