void main(void)
{
BoardConfig(0xb8);
BCSCTL1 |= DIVA_2; // ACLK/4
WDTCTL = WDT_ADLY_1000; // WDT 1s/4 interval timer IE1 |= WDTIE; // Enable WDT interrupt
P1DIR = 0xFF; // All P1.x outputs P1OUT = 0; // All P1.x reset P2DIR = 0xFF; // All P2.x outputs P2OUT = 0; // All P2.x reset P3DIR = 0xFF; // All P3.x outputs P3OUT = 0x30; // All P3.x reset P4DIR = 0xFF; // All P4.x outputs P4OUT = 0; // All P4.x reset P5DIR = 0xFF; // All P5.x outputs P5OUT = 0; // All P5.x reset P6DIR = 0xFF; // All P6.x outputs P6OUT = 0x80; // All P6.x reset
while(1)
{
uint i;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3
P3OUT &= ~BIT5; // Set P3.5 LED on for (i = 18000; i>0; i--); // Delay
P3OUT |= BIT5; // Clear P3.5 LED off } }
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) }
//******************************************************************************* // MSP-FET430P140 Demo - Software Toggle P3.4 //
// Description: Toggle P3.4 by xor'ing P3.4 inside of a software loop. // ACLK= n/a, MCLK= SMCLK= default DCO ~800k //
// MSP430F149 // ----------------- // /|\\| XIN|-
11
// | | | // --|RST XOUT|- // | |
// | P3.4|-->LED //
// Dasheng
// LiTian Electronic Inc.
// Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include
void main(void) {
BoardConfig(0xb8);
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P3DIR |= BIT4; // Set P3.4 to output direction for (;;)
{
volatile unsigned int i;
P3OUT ^= BIT4; // Toggle P3.4 using exclusive-OR
i = 50000; // Delay do (i--);
while (i != 0); } }
//****************************************************************************** // MSP-FET430P140 Demo - WDT, Toggle P3.4, Interval Overflow ISR, DCO SMCLK //
// Description: Toggle P3.4 using software timed by the WDT ISR. Toggle rate // is approximately 30ms based on default ~ 800khz DCO/SMCLK clock source // used in this example for the WDT.
// ACLK= n/a, MCLK= SMCLK= default DCO~ 800k // //
MSP430F149
// -----------------
// /|\\| XIN|- // | | | // --|RST XOUT|-
12
// | | // | P3.4|-->LED //
// Dasheng
// LiTian Electronic Inc. // Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//****************************************************************************** #include
void main(void)
{
BoardConfig(0xbf); //关闭数码管、流水灯和电平转换
WDTCTL = WDT_MDLY_32; // Set Watchdog Timer interval to ~30ms IE1 |= WDTIE; // Enable WDT interrupt P3DIR |= BIT4; // Set P3.4 to output direction
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }
// Watchdog Timer interrupt service routine #pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void) {
P3OUT ^= BIT4; // Toggle P3.4 using exclusive-OR } //****************************************************************************** // MSP-FET430P140 Demo - WDT, Toggle P3.4, Interval Overflow ISR, 32kHz ACLK //
// Description: Toggle P3.4 using software timed by WDT ISR. Toggle rate is
// exactly 250ms based on 32kHz ACLK WDT clock source. In this example the // WDT is configured to divide 32768 watch-crystal(2^15) by 2^13 with an ISR // triggered @ 4Hz.
// ACLK= LFXT1= 32768, MCLK= SMCLK= DCO~ 800kHz
// //* External watch crystal installed on XIN XOUT is required for ACLK *// //
// MSP430F149
// -----------------
// /|\\| XIN|-
// | | | 32kHz // --|RST XOUT|- // | | // | P3.4|-->LED //
13
// Dasheng
// LiTian Electronic Inc. // Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include
void main(void)
{
BoardConfig(0xb8);
WDTCTL = WDT_ADLY_250; // WDT 250ms, ACLK, interval timer IE1 |= WDTIE; // Enable WDT interrupt P3DIR |= BIT4; // Set P3.4 to output direction
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt }
// Watchdog Timer interrupt service routine #pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void) {
P3OUT ^= BIT4; // Toggle P3.4 using exclusive-OR } //****************************************************************************** // MSP-FET430P140 Demo - Timer_A, Toggle P3.4, CCR0 Cont. Mode ISR, DCO SMCLK // // // // //
Description: Toggle P3.4 using software and TA_0 ISR. Toggles every 50000 SMCLK cycles. SMCLK provides clock source for TACLK.
During the TA_0 ISR, P3.4 is toggled and 50000 clock cycles are added to CCR0. TA_0 ISR is triggered every 50000 cycles. CPU is normally off and
// used only during TA_ISR.
// ACLK = n/a, MCLK = SMCLK = TACLK = default DCO ~800kHz //
// MSP430F149 // --------------- // /|\\| XIN|- // | | | // --|RST XOUT|- // | | // | P3.4|-->LED //
// Dasheng
// LiTian Electronic Inc.
14
// Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BoardConfig(0xb8); //关闭数码管、流水灯和电平转换 P3DIR |= BIT4; // P3.4 output
CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 50000;
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }
// Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void) {
P3OUT ^= BIT4; // Toggle P3.4
CCR0 += 50000; // Add Offset to CCR0 } //****************************************************************************** // MSP-FET430P140 Demo - Timer_A, Toggle P3.4, CCR0 Up Mode ISR, DCO SMCLK //
// Description: Toggle P3.4 using software and TA_0 ISR. Timer_A is // configured for up mode, thus the timer overflows when TAR counts // to CCR0. In this example, CCR0 is loaded with 20000.
// ACLK = n/a, MCLK = SMCLK = TACLK = default DCO ~800kHz //
// MSP430F149 // ---------------
// /|\\| XIN|- // | | | // --|RST XOUT|- // | |
// | P3.4|-->LED //
// Dasheng
// LiTian Electronic Inc. // Feb 2008
15