msp430实用程序汇总(6)

2019-03-10 13:34

}

while ((IFG1 & OFIFG)); // OSCFault flag still set?

BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)

ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD UCTL0 |= CHAR; // 8-bit character UTCTL0 |= SSEL1; // UCLK = SMCLK UBR00 = 0xA0; // 8Mhz/19200 ~ 417 UBR10 = 0x01; //

UMCTL0 = 0x00; // no modulation

UCTL0 &= ~SWRST; // Initialize USART state machine IE1 |= URXIE0; // Enable USART0 RX interrupt

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }

#pragma vector=UART0RX_VECTOR __interrupt void usart0_rx (void) {

while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready? TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0 }

//****************************************************************************** // MSP-FET430P140 Demo - USART0, UART 115200 Echo ISR, XT2 HF XTAL ACLK //

// Description: Echo a received character, RX ISR used. Normal mode is LPM0, // USART0 RX interrupt triggers TX Echo. Though not required, MCLK= XT2. // ACLK = n/a, MCLK = SMCLK = UCLK0 = XT2 = 8MHz

// Baud rate divider with 8Mhz XTAL = 8000000/115200 = 0069 (0045h) // //* An external 8MHz XTAL on X2IN X2OUT is required for XT2CLK *// // //* Min Vcc required varies with MCLK frequency - refer to datasheet *// // //

// MSP430F149 // -----------------

// /|\\| XT2IN|-

// | | | 8Mhz // --|RST XT2OUT|- // | |

// | P3.4|------------> // | | 115200 - 8N1 // | P3.5|<------------ // //

26

// M. Buccini

// Texas Instruments Inc. // Feb 2005

// Built with IAR Embedded Workbench Version: 3.21A

//******************************************************************************

#include #include \

void main(void) {

volatile unsigned int i;

BoardConfig(0xb8);

WDTCTL = WDTPW + WDTHOLD; P3SEL |= 0x30;

BCSCTL1 &= ~XT2OFF; do {

IFG1 &= ~OFIFG; for (i = 0xFF; i > 0; i--); }

while ((IFG1 & OFIFG));

BCSCTL2 |= SELM_2 + SELS; ME1 |= UTXE0 + URXE0; UCTL0 |= CHAR; UTCTL0 |= SSEL1; UBR00 = 0x45; UBR10 = 0x00; UMCTL0 = 0x00; UCTL0 &= ~SWRST; IE1 |= URXIE0;

_BIS_SR(LPM0_bits + GIE); }

#pragma vector=UART0RX_VECTOR __interrupt void usart0_rx (void) {

while (!(IFG1 & UTXIFG0)); TXBUF0 = RXBUF0;

// Stop WDT

// P3.4,5 = USART0 TXD/RXD // XT2on // Clear OSCFault flag // Time for flag to set // OSCFault flag still set? // MCLK = SMCLK = XT2 (safe) // Enable USART0 TXD/RXD // 8-bit character // UCLK = SMCLK // 8MHz 115200 // 8MHz 115200

// 8MHz 115200 modulation

// Initialize USART state machine // Enable USART0 RX interrupt // Enter LPM0 w/ interrupt // USART0 TX buffer ready? // RXBUF0 to TXBUF0

27

}

//****************************************************************************** // MSP-FET430P140 Demo - ADC12, Sample A0, Set P3.4 if A0 > 0.5*AVcc //

// Description: A single sample is made on A0 with reference to AVcc. // Software sets ADC10SC to start sample and conversion - ADC12SC

// automatically cleared at EOC. ADC12 internal oscillator times sample (16x)

// and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12 // conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on // reti. If A0 > 0.5*AVcc, P3.4 set, else reset. //

// MSP430F149 // -----------------

// /|\\| XIN|- // | | | // --|RST XOUT|- // | |

// Vin-->|P6.0/A0 P3.4|--> LED //

// Dasheng

// LiTian Electronic Inc. // Feb 2008

// Built with IAR Embedded Workbench Version: 3.42A

//******************************************************************************

#include #include \

void main(void) {

WDTCTL = WDTPW + WDTHOLD; // Stop WDT BoardConfig(0xb8);

ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12 ADC12CTL1 = SHP; // Use sampling timer ADC12IE = 0x01; // Enable interrupt

ADC12CTL0 |= ENC; // Conversion enabled P6SEL |= 0x01; // P6.0 ADC option select P3DIR |= BIT4; // P3.4 output

for (;;) {

ADC12CTL0 |= ADC12SC; // Sampling open

_BIS_SR(CPUOFF + GIE); // LPM0, ADC12_ISR will force exit }

28

}

// ADC12 interrupt service routine #pragma vector=ADC_VECTOR __interrupt void ADC12_ISR (void) {

if (ADC12MEM0 < 0x7FF)

P3OUT &= ~BIT4; // Clear P3.4 LED off else

P3OUT |= BIT4; // Set P3.4 LED on

_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from 0(SR) }

//****************************************************************************** // MSP-FET430P140 Demo - ADC12, Using the Internal Reference //

// Description: This example shows how to use the internal reference of the ADC12. // It uses the internal 2.5V reference and performs a single conversion

// on channel A0. The conversion results are stored in ADC12MEM0. Test by // applying a voltage to channel A0, then setting and running to a break point // at the \// register window in debugger and view the contents of ADC12MEM0. // //

// MSP430F149 // ---------------

// | | // Vin -->|P6.0/A0 | // | | // //

// M. Mitchell

// Texas Instruments Inc. // Feb 2005

// Built with IAR Embedded Workbench Version: 3.21A

//******************************************************************************

#include #include \

void main(void) {

volatile unsigned int i;

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer BoardConfig(0xb8);

P6SEL |= 0x01; // Enable A/D channel A0

29

ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V; // Turn on and set up ADC12 ADC12CTL1 = SHP; // Use sampling timer ADC12MCTL0 = SREF_1; // Vr+=Vref+

for ( i=0; i<0x3600; i++) // Delay for reference start-up { }

ADC12CTL0 |= ENC; // Enable conversions

while (1) {

ADC12CTL0 |= ADC12SC; // Start conversion while ((ADC12IFG & BIT0)==0);

_NOP(); // SET BREAKPOINT HERE } }

//***************************************************************************** // MSP-FET430P140 Demo - ADC12, Sample A10 Temp, Set P1.0 if Temp ++ ~2C //

// Description: Use ADC12 and the integrated temperature sensor to detect // temperature gradients. The temperature sensor output voltage is sampled // ~ every 80ms and compared with the defined delta values using an ISR. // (ADC12OSC/256)/ determines sample time which needs to be greater than // 30us for temperature sensor.

// ADC12 is operated in repeat-single channel mode with the sample and

// convert trigger sourced from Timer_A CCR1. The ADC12MEM0_IFG at the end // of each converstion will trigger an ISR.

// ACLK = n/a, MCLK = SMCLK = default DCO ~ 800k, ADC12CLK = ADC12OSC //

// MSP430F149 // -----------------

// /|\\| XIN|- // | | | // --|RST XOUT|- // | |

// |A10 P3.4|-->LED //

// A. Dannenberg

// Texas Instruments Inc. // Feb 2005

// Built with IAR Embedded Workbench Version: 3.21A

//******************************************************************************

#include

30


msp430实用程序汇总(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:酒店管理信息系统设计方案介绍

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: