我们需要下面这些软件
这个看word
步骤1:在桌面上新建一个文件夹,这个文件夹不要有中文或特殊符号,最好是全英文
/* --COPYRIGHT--,BSD_EX * Copyright (c) 2012, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT--*///******************************************************************************// 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|<------------////// M. Buccini// Texas Instruments Inc.// Feb 2005// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A//******************************************************************************#include <msp430.h>int main(void){ volatile unsigned int i; WDTCTL = WDTPW WDTHOLD; // Stop WDT P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD BCSCTL1 &= ~XT2OFF; // XT2on do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } 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 = 0x45; // 8MHz 115200 UBR10 = 0x00; // 8MHz 115200 UMCTL0 = 0x00; // 8MHz 115200 modulation UCTL0 &= ~SWRST; // Initialize USART state machine IE1 |= URXIE0; // Enable USART0 RX interrupt __bis_SR_register(LPM0_bits GIE); // Enter LPM0 w/ interrupt}#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)#pragma vector=USART0RX_VECTOR__interrupt void usart0_rx (void)#elif defined(__GNUC__)void __attribute__ ((interrupt(USART0RX_VECTOR))) usart0_rx (void)#else#error Compiler not supported!#endif{ while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready? TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0}
完成后效果:
步骤6 设置IAR使其能够编译输出hex文件
改成release模式
步骤6 点击编译,第一次编译会让保存工作空间名字,随便取个名字保存即可。
打开这个软件
首先得看硬件,P34和P35引脚就是串口引脚。确保用一个USB转TTL模块,链接到这里,然后插入电脑。
联系客服