59 lines
1.9 KiB
C
59 lines
1.9 KiB
C
|
#include <msp430.h>
|
||
|
|
||
|
|
||
|
/**
|
||
|
* main.c
|
||
|
*/
|
||
|
|
||
|
int freq[4] = {0, 128, 256, 512}; // off, 1KHz, 2 KHz, 4 Khz
|
||
|
int main(void)
|
||
|
{
|
||
|
WDTCTL = WDT_ADLY_1000; // 1 s interval
|
||
|
_EINT(); // Enable interrupts
|
||
|
IE1 |= WDTIE; // Enable WDT interrupt
|
||
|
P2SEL |= BIT2; // P2.2 special function (TB0 output)
|
||
|
P2SEL &= ~BIT1; // Clear P2.1
|
||
|
P2OUT &= ~(BIT1+BIT2); // Turn Off LED1
|
||
|
TB0CTL = TBSSEL_1 + MC_1; // Upmode
|
||
|
P3SEL |= 0x20; // P3.5 as special function
|
||
|
P3DIR |= 0x20; // P3.5 as digital output
|
||
|
TB0CCTL4 = OUTMOD_4; // TB4 output is in toggle mode
|
||
|
TB0CCTL0 = freq[0];
|
||
|
_BIS_SR(LPM3_bits + GIE); // Enter Low Power Mode 3
|
||
|
}
|
||
|
|
||
|
|
||
|
// Watchdog Timer interrupt service routine
|
||
|
#pragma vector=WDT_VECTOR
|
||
|
__interrupt void watchdog_timer(void)
|
||
|
{
|
||
|
static int i =0;
|
||
|
i++;
|
||
|
|
||
|
if(i == 1){
|
||
|
TB0CCTL0= freq[0]; // f = 4 MHz
|
||
|
P2OUT &=~ BIT1; // Turn on LED2
|
||
|
P2OUT &= ~BIT2; // Turn Off LED1
|
||
|
}
|
||
|
else if(i == 2){
|
||
|
TB0CCTL0= freq[2]; // f = 2 MHz
|
||
|
P2OUT &= BIT1; // Turn on LED2
|
||
|
P2OUT |= BIT2; // Turn Off LED1
|
||
|
}
|
||
|
else if(i == 3){
|
||
|
TB0CCTL0= freq[3]; // f = 4 MHz
|
||
|
P2OUT |= BIT1; // Turn on LED2
|
||
|
P2OUT |= BIT2; // Turn Off LED1
|
||
|
}
|
||
|
else if(i == 4){
|
||
|
TB0CCTL0= freq[1]; // f = 4 MHz
|
||
|
P2OUT &=~ BIT1; // Turn on LED2
|
||
|
P2OUT &= ~BIT2; // Turn Off LED1
|
||
|
}
|
||
|
else if(i == 5){
|
||
|
TB0CCTL0= freq[3]; // f = 4 MHz
|
||
|
P2OUT &=~ BIT1; // Turn on LED2
|
||
|
P2OUT |= BIT2; // Turn Off LED1
|
||
|
}
|
||
|
}
|