#include
void main(void) {
BoardConfig(0xb8);
WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer DCOCTL = DCO0 + DCO1 + DCO2; // Max DCO
BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on, max RSEL BCSCTL2 |= SELS; // SMCLK = XT2 P5DIR |= 0x70; // P5.6,5,4 outputs P5SEL |= 0x70; // P5.6,5,5 options
while(1) { } }
//****************************************************************************** // MSP-FET430P140 Demo - Basic Clock, LPM3 Using WDT ISR, 32kHz ACLK //
// Description: This program operates MSP430 normally in LPM3, pulsing P3.4 // at 4 second intervals. WDT ISR used to wake-up system. All I/O configured // as low outputs to eliminate floating inputs. Current consumption does
// increase when LED is powered on P3.4. Demo for measuring LPM3 current. // ACLK= LFXT1/4= 32768/4, MCLK= SMCLK= default DCO // //* External watch crystal on XIN XOUT is required for ACLK *// // //
// MSP430F149 // ---------------
// /|\\| XIN|-
// | | | 32kHz // --|RST XOUT|- // | |
// | P3.5|-->LED //
// Dasheng
// LiTian Electronic Inc. // Feb 2008
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include
11
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|-
12
// | | | // --|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|-
13
// | |
// | 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 //
14
// 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.
15