LaunchPad(MSP430G2553) - 官方例程(3)

2019-08-31 17:51

// MSP430xG461x // ----------------- // /|\\| | // | | | // --|RST | // /|\\ | | // --o--|P1.0 P2.1|-->LED // \\|/ //

// K. Quiring/ M. Mitchell // Texas Instruments Inc. // October 2006

// Built with IAR Embedded Workbench Version: 3.41A

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

#include

void main(void) {

WDTCTL = WDTPW + WDTHOLD; // Stop WDT FLL_CTL0 |= XCAP14PF; // Configure load caps P2DIR = BIT1; // Set P2.1 to output direction P1IES = BIT0; // H-L transition P1IE = BIT0; // Enable interrupt

_BIS_SR(LPM4_bits + GIE); // LPM4, enable interrupts }

// Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port1_ISR (void) {

unsigned volatile int i;

for (i=10000; i>0; i--); // Debounce delay P1IFG &= ~BIT0; // Clear P1IFG

if ((P1IN & 0x01) == 0)

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR }

8.

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

// MSP430xG46x Demo - Software Port Interrupt on P1.0 from LPM4 //

// Description: A hi/low transition on P1.0 will trigger P1_ISR which,

// toggles P2.1. Normal mode is LPM4 ~ 0.1uA. LPM4 current can be measured // with the LED removed, all unused P1.x/P2.x configured as output or inputs // pulled high or low, and ensure the P2.0 interrupt input does not float. // ACLK = 32.768kHz, MCLK = SMCLK = default DCO //

// MSP430xG461x // ----------------- // /|\\| | // | | | // --|RST | // /|\\ | | // --o--|P1.0 P2.1|-->LED // \\|/ //

// K. Quiring/ M. Mitchell // Texas Instruments Inc. // October 2006

// Built with IAR Embedded Workbench Version: 3.41A

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

#include

void main(void) {

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

FLL_CTL0 |= XCAP14PF; // Configure load caps P2DIR = BIT1; // Set P2.1 to output direction P1IES = BIT0; // H-L transition P1IE = BIT0; // Enable interrupt

_BIS_SR(LPM4_bits + GIE); // LPM4, enable interrupts }

// Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port1_ISR (void) {

unsigned volatile int i;

for (i=10000; i>0; i--); // Debounce delay P1IFG &= ~BIT0; // Clear P1IFG if ((P1IN & 0x01) == 0)

P2OUT ^= 0x02; // Toggle P2.1 using exclusive-OR }

9.

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

// MSP430xG46x Demo - USCI_A0, 115200 UART Echo ISR, DCO SMCLK // (modified code example \//

// Description: Echo a received character, RX ISR used. Normal mode is LPM0. // USCI_A0 RX interrupt triggers TX Echo.

// Baud rate divider with 1048576hz = 1048576/115200 = ~9.1 (009h|01h)

// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz

// //* An external watch crystal between XIN & XOUT is required for ACLK *// //

// MSP430FG4619

// ----------------- // /|\\| XIN|- // | | | 32kHz // --|RST XOUT|- // | |

// | P2.5/UCA0RXD|<------------ // | | 115200 - 8N1 // | P2.4/UCA0TXD|------------> //

// Texas Instruments Inc. // October 2006

// Built with IAR Embedded Workbench Version: 3.41A

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

#include \

void main(void) {

volatile unsigned int i;

WDTCTL = WDTPW+WDTHOLD; // Stop WDT FLL_CTL0 |= XCAP14PF; // Configure load caps do {

IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0x47FF; i > 0; i--); // Time for flag to set }

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

P2SEL |= 0x030; // P2.4,5 = USCI_A0 RXD/TXD UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 18;0x09; // 1MHz 115200 UCA0BR1 = 0;0x00; // 1MHz 115200 UCA0MCTL = 0;0x02; // Modulation

UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

_BIS_SR(LPM0_bits + GIE); // Enter LPM0, interrupts enabled }

// Echo back RXed character, confirm TX buffer is ready first #pragma vector=USCIAB0RX_VECTOR __interrupt void USCIA0RX_ISR (void) {

while(!(IFG2&UCA0TXIFG));

UCA0TXBUF = UCA0RXBUF; // TX -> RXed character }

10.

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

* MSP-EXP430G2-LaunchPad User Experience Application *

* 1. Device starts up in LPM3 + blinking LED to indicate device is alive * + Upon first button press, device transitions to application mode * 2. Application Mode

* + Continuously sample ADC Temp Sensor channel, compare result against * initial value

* + Set PWM based on measured ADC offset: Red LED for positive offset, Green * LED for negative offset

* + Transmit temperature value via TimerA UART to PC * + Button Press --> Calibrate using current temperature * Send character '? via UART, notifying PC

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

#include \

#define LED0 BIT0 #define LED1 BIT6


LaunchPad(MSP430G2553) - 官方例程(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:泰山版五年级下册品社第三单元检测题

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

马上注册会员

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