MSP-EXP430G2 LacunchPad口袋实验平台用户手册
Olimex MSP430-GBD开发板用户手册说明书
MSP430-GBD development boardUsers ManualAll boards produced by Olimex are ROHS compliantRev.A, November 2009Copyright(c) 2009, OLIMEX Ltd, All rights reservedINTRODUCTIONMSP430-GBD development board is example how digital signal processing may bedone with low cost and low power MSP430 microcontrooler, the design is based onTI Application notes: SLAA351 Simple Glasbreak detector and SLAA389 RobustGlasbreak detectorApplication software make it like simple glass break detector. There is led andbuzzer indication when glass break is detected. The board can be used as sensorevaluation, introduction to digital filtering basis. The sources are available and canbemodified by the user for their own further development.BOARD FEATURES-CPU: MSP430F2274 mixed signal microcontroller-JTAG connector-UEXT connector-Microphone-Buzzer- 3 V lithium battery connector-Status LED-PCB: FR-4, 1.5 mm (0,062"), solder mask, silkscreen component print-Dimensions: 41.9x40.6 mm ( 1.650x 1.599")ELECTROSTATIC WARNINGThe MSP430-GBD board is shipped in protective anti-static packaging. The boardmust not be subject to high electrostatic potentials. General practice for workingwith static sensitive devices should be applied when working with this board. BOARD USE REQUIREMENTSCables: The cable you will need depends on the programmer/debugger you use. Ifyou use MSP430-JTAG, you will need LPT cable, if you use MSP430-JTAG-TINY orMSP-JTAG-ISO, you will need 1.8m A-B USB cable, if you use MSP430-JTAG-RF,you can connect it to the USB port of your computer, or via USB cable type A –female.Note: If you use MSP430-JTAG-RF – be sure that your battery gives power supply 3V,because if it is lower – MSP430-JTAG-RF may not work.Hardware:Programmer/Debugger–one of our Programmers–MSP430-JTAG,MSP430-JTAG-TINY, MSP430-JTAG-ISO, or MSP430-JTAG-RF.Software: MSP430 KickStart software.PROCESSOR FEATURESMSP430-GBD board use ultralow-power mixed signal microcontroller with twobuilt-in 16-bit timers, a universal serial communication interface, 10-bit A/Dconverter with integrated reference and data transfer controller (DTC), two general-purpose operational amplifiers, 32 GPIO with these features:–32KB + 256B Flash Memory–1KB RAM–Low Supply Voltage Range: 1.8 V to 3.6 V–Ultralow Power Consumption–Active Mode: 270 µA at 1 MHz, 2.2 V–Standby Mode: 0.7 µA–Off Mode (RAM Retention): 0.1 µA–Ultrafast Wake-Up From Standby Mode in Less Than 1 µs–16-Bit RISC Architecture, 62.5-ns Instruction Cycle Time–Basic Clock Module Configurations:–Internal Frequencies up to 16 MHz With Four Calibrated Frequencies to±1%–Internal Very-Low-Power Low-Frequency Oscillator–32-kHz Crystal–High-Frequency Crystal 16 MHz–Resonator–External Digital Clock Source–External Resistor–16-Bit Timer_A With Three Capture/Compare Registers–16-Bit Timer_B With Three Capture/Compare Registers–Universal Serial Communication Interface–Enhanced UART Supporting Auto-Baudrate Detection (LIN)–IrDA Encoder and Decoder–Synchronous SPI–I2C TM–10-Bit 200-ksps Analog-to-Digital (A/D) Converter With Internal Reference,Sample-and-Hold, Autoscan, and Data Transfer Controller–Two Configurable Operational Amplifiers–Brownout Detector–Serial Onboard Programming, No External Programming Voltage Needed Programmable Code Protection by Security Fuse–Bootstrap Loader–On Chip Emulation ModuleBLOCK DIAGRAM MEMORY ORGANIZATIONSCHEMATICVBOARD LAYOUTPOWER SUPPLY CIRCUITMSP430-GBD can take power from two sources:–Battery, when jumper BAT/JTAG is in position BAT.–JTAG, when jumper BAT/JTAG is in position JTAG.RESET CIRCUITMSP430-GBD reset circuit includes JTAG connector pin 11, EXT pin 3,MSP430F2274 pin 7 (#RST/NMI/SBWTDIO).CLOCK CIRCUITThere is XTAL option for the customer. You can connect quartz crystal toMSP430F2274 pin 5 (XOUT/P2.7) and pin 6 (XIN/P2.6).JUMPER DESCRIPTIONSDA/P1.2Give user choice to select UEXT SDA connection between P1.2 or MOSI/SDA.Default state is P1.2.SCL/P1.1Give user choice to select UEXT SCL connection between P1.1 or MISO/SCL.Default state is P1.1.BAT/JTAGGive user opportunity to select between battery power supply or JTAG power supply.Default state is JTAG.E_MICGive user opportunity to connect external microphone instead on-board microphone.Default state is not connected.INPUT/OUTPUTStatus LED (red) with name LED - light indication for recognizing glass breakage,connected to MSP430F2274 pin 31 (P1.0).BUZZER – audio indication for glass breakage, connected to MSP430F2274 pin 28(P3.7)MIC - on-board microphone – sensor for recognizing glass breakage, connected toMSP430F2274 pin 17 (P4.0) - VCC_MIC, through R7(4.7k) and pin 10 (DA0I1),through C(1uF).CONNECTOR DESCRIPTIONSJTAGPin #Signal Name Pin #Signal Name1TDO2VCC_JTAG3TDI4VCC5TMS6NC7TCK8TEST/SWBTCK9GND10NC11#RST/SWBTDIO12NC13NC14NCEXTPin #Signal Name Pin #Signal Name1VCC2GND3#RST/SWBTDIO4P2.55P1.36P4.77P4.58P4.39P4.210P4.111P3.612P2.313VCC14GNDUEXTMECHANICAL DIMENSIONSAll measures are in inches.AVAILABLE DEMO SOFTWARE–MSP430-GBD_Blinking_Led–MSP430-GBD_Buzzer_Beep–MSP430-GBD_Glass_BreakORDER CODEMSP430-GBD – assembled and testedHow to order?You can order to us directly or by any of our distributors.Check our web /dev for more info.Revision history:REV.A- create November 2009Disclaimer:© 2009 Olimex Ltd. All rights reserved. Olimex®, logo and combinations thereof, are registered trademarks of Olimex Ltd. Other terms and product names may be trademarks of others.The information in this document is provided in connection with Olimex products. No license, express or implied or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Olimex products.Neither the whole nor any part of the information contained in or the product described in this document may be adapted or reproduced in any material from except with the prior written permission of the copyright holder. The product described in this document is subject to continuous development and improvements. All particulars of the product and its use contained in this document are given by OLIMEX in good faith. However all warranties implied or expressed including but not limited to implied warranties of merchantability or fitness for purpose are excluded.This document is intended only to assist the reader in the use of the product. OLIMEX Ltd. shall not be liable for any loss or damage arising from the use of any information in this document or any error or omission in such information or any incorrect use of the product.。
MSP430G2xx3设备的SMBus库用户指南说明书
SMBus Library for MSP430G2xx3Devices User’s GuideDOCNUM-1.10.00.00Copyright©2015T exas Instruments Incorporated.1 CopyrightCopyright©2015Texas Instruments Incorporated.All rights reserved.MSP430and MSP430Ware are trademarks of Texas Instruments Instruments. ARM and Thumb are registered trademarks and Cortex is a trademark of ARM Limited.Other names and brands may be claimed as the property ofbe aware that an important notice concerning availability,standard warranty,and use in critical applications of Texas Instruments semi-conductor products and disclaimers thereto appears at the end of this document.Texas Instruments13532N.Central Expressway MS3810Dallas,TX75243/Revision InformationThis is version1.10.00.00of this document,last updated on Fri Feb13201511:59:44.Table of Contents2Table of ContentsCopyright (1)Revision Information (1)1Introduction (3)1.1Introduction (3)1.2SMBus (3)1.3The MSP430™SMBus Library Package (4)2Introduction to the MSP430™SMBus API (5)2.1Overview (5)2.2Supported Device Families (5)2.3Supported Development Environments (5)2.4Stack Organization (5)2.5Usage of MCU Peripheral Resources (6)2.6Release Notes and Migration from Previous Versions (6)3SMBus API Usage (7)3.1Introduction (7)3.2Usage (7)3.3Examples (8)IMPORTANT NOTICE (9)1Introduction1.1IntroductionThs SMBus(Sytem Management Bus)API(application programming interface)stack forMSP430™microcontrollers is a turnkey API.It includes support for applications where theMSP430™microcontroller is acting as the master or a slave.The API is designed to minimize the SMBus knowledge required to write an application:All SMBus protocol is handled automatically by the APIThe data interface presented to the application is simple to use,abstracting the applicationfrom SMBus protocolThe user should not need to modify the API source.However,for experienced developers,thesource is open and available for editing.Accessing the API’s source can also be useful for systemdebug.Application examples are included in the MSP430™SMBus Library Package.1.2SMBusThe System Management Bus(SMBus)is a lightweight two-wire interface based on the principlesof I2C,commonly used as a control bus and for power management tasks in computing,mobilecomputing and battery operated applications.A device performing data transfers on the bus canbe considered a master,which is the device which initiates a transaction and drives the clock,or aslave,which is the target of a SMBus transaction driven by the master.Both the master and theslave can act as transmitters or as receivers.SMBus2.0shares a lot of similarities with I2C,but some of the most relevant differences include:Time-out detection when a device stretches the clock for too longPacket Error Checking(PEC)can be optionally appended at the end of each transaction,allowing the bus to automatically validate packetsI2C only defines a PHY and Data-Link layers,but SMBus defines a network layer withdifferent SMBus protocols which can be used to exchange data between devicesOptional use of additional lines such as SMBAlert#and SMBSUS#.For more information about SMBus,please refer to the SMBus2.0specification:/specs/.For more information about I2C,please refer to/documents/user manual/UM10204.pdf1.2.1Supported FeaturesThe following table details the SMBus features supported in the MSP430™SMBus library.SMBus Feature MSP430FR5xx6xx MSP430G2xx3Applicable SMBus2.0 Master Slave Master Slave specification sectionClock Timeout detection1Y es Y es Y es1Y es1 3.1.1.2Manual NACK on invalid address/data N/A Y es2N/A No 4.2Arbitration Y es N/A Y es N/A 4.3.2Clock stretching Y es Y es Y es Y es 4.3.3Multiple Slave address N/A No N/A No 5.2General Call address N/A No N/A No 5.2PEC Y es Y es Y es Y es 5.4Quick Command Partial3Partial3Parial3Partial3 5.5.1Send Byte Y es Y es Y es Y es 5.5.2Receive Byte Y es Y es Y es Y es 5.5.3Write Byte/Word Y es Y es Y es Y es 5.5.4Read Byte/Word Y es Y es Y es Y es 5.5.5Process Call Y es Y es Y es Y es 5.5.6Block Write/Read Y es Y es Y es Y es 5.5.7Block write-block read process call Y es Y es Y es Y es 5.5.8Host notify protocol No No No No 5.5.9ARP No No No No 5.6SMBAlert#No No No No Appendix ASMBSUS#No No No No Appendix ANotes:1.MSP430G2xx3USCI doesn’t have integrated timeout detection and requires a timer2.MSP430FR5x/6xx can optionally-use DMA to stretch SCL while deciding to ACK/NACK thecurrent byte3.Only QuickCommand Write is supported,not QuickCommand Read1.3The MSP430™SMBus Library PackageThis User’s Guide documents the SMBus API and examples.The contents of the package isdescribed below:smbuslib:T op level directory.Contains release notes and the manifestfile related to licensing.•docs:Contains the API and User’s Guides for the supported MSP430™devices•driverlib:Contains the standard MSP430™driverlib which is used in the libraryimplementation for device families that support driverlib(for example,MSP430FR5xx6xx)•examples:Contains the example projects for each of the supported MSP430™devices•src:Contains the source code for the SMBus Library stack2Introduction to the MSP430™SMBus API 2.1OverviewThe MSP430™SMBus API stack allows easy creation of MSP430™applications thatcommunicate with other system components over a SMBus interface.This API supports using the MSP430™microcontroller as the SMBus master or as a SMBusslave.2.2Supported Device FamiliesThe SMBus API stack is supported on the following MSP430™device families:MSP430FR5xx6xxMSP430G2xx32.3Supported Development EnvironmentsThe SMBus API stack and examples build and run on both the IAR and CCS environments forMSP430™microcontrollers.See the Release Notes HTMLfile in the SMBus Library Package forspecific IAR/CCS version information.IAR and CCS are both available in free,code-size-limited versions(8K and16K,respectively,ofobject code).Applications thatfit under8K of memory can be run on both free versions.Applications that are greater than8K cannot be built using the free IAR Kickstart tool.Instead,thefree version of CCS can be used;or a licensed version of either environment.See the Release Notes within the SMBus Library Package zipfile for additional informationspecific to a given release.2.4Stack OrganizationThe software stack is organized into three layers:The public API layer defines the API’s that should be called by application programs.Thesefunctions are defined in smbus.h.The network layer manages the SMBus protocol state machine and interfaces with thephysical layer.These functions are defined in smbus nwk.h and should not be called directlyfrom application programs.The physical layer contain all the device specific code to interact with the MSP430™microcontroller.These functions are defined in smbus phy.h and should not be called directlyfrom application programs.2.5Usage of MCU Peripheral ResourcesWithin the SMBus API,the resources shown below are considered owned by the API.If theapplication accesses them,it should be aware of how the API uses them.2.6Release Notes and Migration from Previous VersionsA Release Notes HTMLfile accompanies each release of the SMBus Library Package.Referencethisfile for any information specific to this release,including:All changes from the previous versionsInstructions for migration from previous versionsUpdated IDE configuration informationKnown issues3SMBus API Usage3.1IntroductionThis chapter contains the detailed documentation for the application API functions anddescriptions on using the API to create a SMBus master or slave application.3.2UsageThis section illustrates the basic application template for master and slave applications.See theexamples for complete applications,and the HTML API documentation for details on theindividual APIs.3.2.1Master Usage Outline//Declare master SMBus structureSMBus SMB;//Initialize GPIOs and clocks...//Initialize GPIO I2C pins...//Initialize SMBus Master always at100kbps per SMBus specSMBus masterInit(&SMB,NULL,(MCLK MHZ*1000000));//Initialize I2C and enable SMBus InterruptsSMBus masterEnableInt(&SMB);//Send SMBus Sendbyte command(0x33)uint8t ret=SMBus masterSendByte(&SMB,//SMB struct0x40,//Slave Addr0x33);//SMB Command...3.2.2Slave Usage Outlinemain(){//Declare slave SMBus structureSMBus SMB;//SMBus receive and transmit buffersuint8t au8RxBuff[SMB MAX PACKET SIZE];uint8t au8TxBuff[SMB MAX PACKET SIZE];//Initialize GPIOs and clocks...//Initialize GPIO I2C pins...//Initialize SMBus SlaveSMBus slaveInit(&SMB,NULL);//Set the slave’s addressSMBus slaveSetAddress(&SMB,0x40);//Set the RX and TX buffers for SMBusSMBus slaveSetRxBuffer(&SMB,au8RxBuff,sizeof(au8RxBuff));SMBus slaveSetTxBuffer(&SMB,au8TxBuff,sizeof(au8TxBuff));//Initialize I2C and enable SMBus InterruptsSMBus slaveEnableInt(&SMB);...while(1){disable interrupt();{BIS SR(LPM3bits+GIE);//Go to sleep}enable interrupt();}//While(1)}#pragma vector=USCIAB0TX VECTOR,USCIAB0RX VECTORinterrupt void USCI ISR(void){//Check the state of SMBusswitch(SMBus slaveProcessInt(&SMB)){case SMBus State Slave QCMD://If a Quick command was detected,execute function(if any)break;case SMBus State Slave CmdComplete://Get command using SMBus slaveGetCommand(&SMB)and process command//if command is not valid/supported//SMBus slaveReportError(&SMB,SMBUS ErrorCode Cmd);LPM3EXIT;//Exit to main loop if requiredbreak;default:break;}//Clear flags to be ready for next packetSMBus processDone(&SMB);}#pragma vector=TIMER1A0VECTORinterrupt void TIMER1A0ISR(void){//Call the SMBUS function to handle a timeout error and restart the SMBUSSMBus slaveProcessTimeoutInt(&SMB);}3.3ExamplesSeveral examples are provided with the release package that illustrate using the library toimplement both SMBus master and slave application.For each example,matching master and slave implementations are provided.ReadByte Echo-sends and echoes back a ReadByte commandWriteWord Dimmer-sends and echoes back a WriteWord commandAllProtocols-sequences through all the SMBus protocolsExamples are configured for the MSP-EXP430G2and MSP-EXP430FR5969launch pad boardsand CCS and IAR projects are provided.9 IMPORTANT NOTICET exas Instruments Incorporated and its subsidiaries(TI)reserve the right to make corrections,modifications,enhancements,improvements, and other changes to its products and services at any time and to discontinue any product or service without notice.Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete.All products are sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard warranty.T esting and other quality control techniques are used to the extent TI deems necessary to support this warranty.Except where mandated by government requirements,testing of all parameters of each product is not necessarily performed.TI assumes no liability for applications assistance or customer product design.Customers are responsible for their products and applications using TI components.T o minimize the risks associated with customer products and applications,customers should provide adequate design and operating safeguards.TI does not warrant or represent that any license,either express or implied,is granted under any TI patent right,copyright,mask work right,or other TI intellectual property right relating to any combination,machine,or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement e of such information may require a license from a third party under the patents or other intellectual property of the third party,or a license from TI under the patents or other intellectual property of TI.Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accom-panied by all associated warranties,conditions,limitations,and notices.Reproduction of this information with alteration is an unfair and deceptive business practice.TI is not responsible or liable for such altered rmation of third parties may be subject to additional restrictions.Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice.TI is not responsible or liable for any such statements.TI products are not authorized for use in safety-critical applications(such as life support)where a failure of the TI product would reasonably be expected to cause severe personal injury or death,unless officers of the parties have executed an agreement specifically governing such use.Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal,regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical applications,notwithstanding any applications-related information or support that may be provided by TI.Further,Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safety-critical applications.TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are specifically designated by TI as military-grade or“enhanced plastic.”Only products designated by TI as military-grade meet military spec-ifications.Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at the Buyer’s risk,and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are designated by TI as compliant with ISO/TS16949requirements.Buyers acknowledge and agree that,if they use any non-designated products in automotive applications,TI will not be responsible for any failure to meet such requirements.Following are URLs where you can obtain information on other Texas Instruments products and application solutions:ProductsAmplifiersData ConvertersDLP®ProductsDSPClocks and TimersInterfaceLogicPower Mgmt MicrocontrollersRFIDRF/IF and ZigBee®Solutions amplifi/clockswww.ti-rfi/lprfApplicationsAudioAutomotiveBroadbandDigital ControlMedicalMilitaryOptical NetworkingSecurityT elephonyVideo&ImagingWireless/audio/automotive/broadband/digitalcontrol/medical/military/opticalnetwork/security/telephony/video/wirelessMailing Address:T exas Instruments,Post Office Box655303,Dallas,T exas75265 Copyright©2015,T exas Instruments Incorporated。
MSP430G2553用户手册中文
时钟
LF,
1
DCO,
VLO
LF,
1
DCO,
VLO
LF,
1
DCO,
VLO
LF,
1
DCO,
VLO
LF,
1
DCO,
VLO
I/O 封装类型
24
32 引脚 QFN 封装
28 引脚 24 TSSOP 封
装
20 引脚 16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
时钟
I/O 封装类型
16
512 2x TA3
8
8
512 2x TA3
8
4
256 2x TA3
8
2
256 2x TA3
8
1
256 2x TA3
8
24
32 引脚 QFN 封装
28 引脚
24 TSSOP 封
LF,
装
-
1
DCO,Βιβλιοθήκη VLO20 引脚16 TSSOP 封
装
16
20 引脚 PDIP 封装
24
32 引脚 QFN 封装
典型应用包括低成本传感器系统,此类系统负责捕获模拟信号、将之转换为数字值、随后对数据进行处理以进行显 示或传送至主机系统。
1
Please be aware that an important notice concerning availability, standard warranty, and use in critical applications of Texas Instruments semiconductor products and disclaimers thereto appears at the end of this data sheet.
单片机430 2系列 用户指南1
2.1
Relaxation Oscillator (RO)
The relaxation oscillator method counts the number of relaxation oscillator cycles within a fixed period (gate time), as shown in Figure 1.
© 2011, ቤተ መጻሕፍቲ ባይዱexas Instruments Incorporated
SLAA490 – April 2011 Submit Documentation Feedback
Implementations
The naming convention for the RO method in the library identifies the relaxation oscillator mechanism, the timer used to measure or count oscillations, and the timer used to define the gate period (see Table 1). Table 1. Relaxation Oscillator Naming Convention
(1)
The software library described in this document can be downloaded from /docs/toolsw/folders/print/capsenselibrary.html.
2
Capacitive Touch Library
2
Implementations
For the implementations described in this document, the fundamental principle is that two independent timing domains are compared. One domain is fixed, and the other is variable as a function of the capacitance.
MSP-EXP430G2 LacunchPad口袋实验平台用户手册
II
序言
LaunchPad 口 袋 实 验 平 台 必 须 搭 配 MSP-EXP430G2 LaunchPad 实验板使用。注意,LaunchPad 实验板的盒子里有 一个晶振,请在实验前先焊接好。 口袋实验平台正式配套书籍《从零开启大学生电子设计之 路—基于 MSP430 LaunchPad 口袋实验平台》,由北京航空航 天大学出版社出版。该书内容涵盖单片机入门知识、编程方法、 片内外设知识和口袋实验平台例程的详细讲解。 口袋实验平台的全部例程代码可登陆 网站 进行下载。其他技术支持信息也将在该网站发布,恕不另行通 知。
1
口袋实验平台可以不借助其它测试仪器实现对单片机的内 部资源和外设的学习和实验。三个综合实验的录像中,使用了 部分仪器来丰富实验效果。 1) 在例程“20_Sin_Gen_and_Sample ”中可以使用示波器 观测 PWM 滤波波形,也可以利用仿真器间接观测波 形。 2) 例程 “21_1_DAC_AWG” 中使用了示波器,如无示波 器,可用例程“21_2_TF_Audio”替代学习 DAC 的使 用。 3) 例程“22_DCO_Calb_Test”录像中示波器和频率计的使 用是为了验证自校验 DCO 频率的精度,利用单片机 自制的频率计一样能满足要求,可自行编程实现频率 计功能。
除了tapwm这样的工具性质的库函数外将事件类函数xxxeventxxxglobal单列文件是十分有必要事件函数对于理解程序意图非常重要集中放置事件检测处理而不是跟着满世界乱蹦的中断去找事件函数是十分高全局变量的使用需要非常谨慎全局变量往往是联系各关键函数的纽带因此集中放置全局变量也是增加程序可读性的常用做法
4.11 I2C 扩展 IO .................................................................................. 31 4.12 LCD 显示自检 ............................................................................. 34 4.13 拨盘电位器 .................................................................................. 36 4.14 温度传感器采样及显示.............................................................. 38 4.15 SPWM 波形合成及采样 .............................................................. 40 4.16 任意波形发生器 AWG ............................................................... 43 4.17 基于 AWG 的音频播放器 .......................................................... 45 4.18 自校验 DCO ................................................................................ 47
MSP-EXP430G2开发板使用简单介绍
(5)、中断应用程序举例(外部中断):
void interrupt_initial() { P1DIR&=~BIT7; //P1.7为输入 P1IE|=0x80; //P1.7中断允许 P1IES|=0x00; //P1.7上升沿触发 P1IFG=0; //P1.7中断标志清除,对于多源中断必须先清中断标志再打开中断 _EINT(); //总中断允许 } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IFG&=~BIT7; //P1.7中断标志清除 /*在此写中断服务子程序*/ }
(4)、中断的嵌套:
当同时有多个中断来的时候才有优先级的考虑(优先级顺序可查看向量表)
实现中断嵌套需要注意以下几点: 1)430默认的是关闭中断嵌套的,一定要中断嵌套的话,就必须在中断服务程序中打开 总中断 msp430的指令中,_DINT()和_EINT()分别指关和开总中断。 2)当进入中断服务程序时,只要不在中断服务程序中再次开中断,则总中断是关闭的, 此时来中断不管是比当前中断的优先级高还是低都不执行; 3)若在中断服务程序A中开了总中断,则可以响应后来的中断B(不管B的优先级比A高 还是低),B执行完再继续执行A。注意:进入中断服务程序B后总中断同样也会关闭, 如 果B中断程序执行时需响应中断C,则此时也要开总中断,若不需响应中断,则不用 开中断,B执行完后跳出中断程序进入A程序时,总中断会自动打开; 4)若在中断服务程序中开了总中断,后来的中断同时有多个,则会按优先级来执行,即 中断优先级只有在多个中断同时到来时才起做用!中断服务不执行抢先原则。 5)对于单源中断,只要响应中断,系统硬件自动清中断标志位,对于TA/TB定时器的比较/捕 获中断,只要访问TAIV/TBIV,标志位倍被自动清除; 对于多源中断要手动清标志位,比如P1/P2口中断,要手工清除相应的标志,如果在这种中 断用"EINT();"开中断,而在打开中断前没有清标志,就会 有相同的中断不断嵌入,而导致 堆栈溢出引起复位,所以在这类中断中必须先清标志再打开中断开关.
MSP430 G2 LaunchPad使用入门
MSP430 G2 LaunchPad使用入门v1.0 2013.8.8xie_sx@目录目录 (1)1 G2 LaunchPad功能简介 (1)1.1 快速入门 (1)1.2 硬件电路 (3)1.3 片上资源 (4)1.4 自学资料 (5)1G2 LaunchPad功能简介1.1快速入门收到MSP430 LaunchPad G2板卡,完整包装盒如下所示:打开盒子,MSP-EXP430G2 套件盒包括下列物品:•MSP-EXP430G2板卡•USB线•两个10 脚单排孔(暂时用不上)•1个32.768kHz 时钟晶振(该晶振不焊接,单片机使用的是内部晶振,建议焊接上)•一张快速启动指南+两个LaunchPad 贴签•两个MSP430 单片机–MSP430G2553:具有8 通道10 位模数转换器(ADC)、片上比较器、触控式使能I/O、通用串行通信接口、16kB 闪存、和512 字节RAM 的低功耗16 位MSP430 微控制器(预加载有示例程序)–MSP430G2452:具有8 通道10 位ADC、片上比较器、触控式I/O、通用串行接口、8kB 闪存、和256 字节SRAM 的低功耗16 位MSP430 微控制器拆开包装,拿出G2板卡,电路板如下图所示:作为入门使用的电路板,在设计入门实验时,我们更多的是借助两个LED灯和一个按键,进行单片机功能模块的学习。
在电脑上安装CCS软件,接着用USB线连接电脑和G2板卡,简单两个步骤就可以开始单片机的实验了。
基本的实验环境搭建好之后,如下图所示。
在宿舍/教室/图书馆等地方,仅需外带一台电脑就可以做实验了。
1.2硬件电路在嵌入式的学习过程中,硬件知识是必不可少的。
对于初学者来说,仿真器部分的具体电路可以跳过,把精力放在单片机核心板卡上。
G2板卡硬件电路较为简单,将所有的IO口引出,并且配有两个LED知识灯+1个用户按键输入。
电源供电部分的电路如下所示,通过电脑的USB口获取5V的电源输入,经稳压芯片稳压后输出3.6V电压给单片机供电。
LaunchPad 实验板
LaunchPad实验板触摸感应子卡使用指南ZHCU011 – August 201011. 触摸感应子卡概述1.1 概述LaunchPad Touch的触摸感应子卡是一个基于Texas Instruments MSP430G2xx系列的完整的触摸感应应用开发方案.。
触摸感应子卡可以被插入现有的MSP-EXP430G2 LaunchPad实验板来实现一个触摸感应的应用。
进行简单的硬件配置和使用不同的软件,可以实现按键/滑条/拨号盘的不同应用。
在MSP-EXP430G2 LaunchPad实验板套件中采用了MSP430G2211微控制器;利用MSP430G2211的内置比较器来完成触摸感应, 同时利用计时器来控制LED闪烁频率以及LED的亮度作为反馈.强烈推荐您在使用触摸感应子卡前阅读MSP-EXP430G2 LaunchPad 实验版用户手册(SLAU318)相关代码和更多信息可在/xxx上下载.MSP-EXP430G2可以运用IAR Embedded workbench集成开发环境(IDE) 或Code Composer Studio (CCS) 来进行代码编写, 程序下载和调试。
调试程序非常简单易用,不需要任何额外的硬件资源,允许用户全速运行程序,设定硬件断点以及单步执行等。
触摸感应子卡特性:z实现触摸按键/滑块/拨号盘的功能z通过2个通用数字I/O口来驱动2颗LED用于视觉反馈z支持所有PDIP14封装的具有片内比较器模块的MSP430G2x11和MSP430F20x1型号z能轻松连接到MSP-EXP430G2 LaunchPad实验板用于调试图1. 触摸感应子卡外观图1.2 套件内容触摸感应子卡套件包含了以下一些配件:z触摸感应子卡另外, 套件附送的MSP430G2211芯片可以帮助您马上体验EXP430G2的各项功能。
MSP430G2211是超低功耗16位微控制器MSP430中的一员,拥有片内比较器,2k字节程序空间和128字节的SRAM。
MSP430G2553手册解读
MSP430G2XX外设
• 欠压复位
– 可在上电和断电期间提供正确的复位信号 – 功耗包含于MCU最低功耗时(LPM4)所消耗电流之中
• 串行通信
– 支持 I2C 和 SPI 的 USI – 支持 I2C、SPI 以及 UART 的 USCI
• Comparator_A+
– – – – 可设定反相和同相输入 可选的 RC 输出滤波器 可直接输出至 Timer_A2 捕获输入 具有中断能力
LaunchPad 开发板上各部分介绍
USB 仿真器接口
片上仿真器模块 6针 eZ430 连接器 外置晶体接口 芯片引出脚 MSP430器件和插座
P1.3 按钮
LED和跳线 P1.0 & P1.6
电源连接器 复位按钮
MSP430系列功能框图
MSP430G2XX 无Port3
低压、 电源复 位保护
VLO Min. Puls Filter ACLK Peripherals
32768Hz
OSC_Fault
辅助时钟
MCLK CPU
主系统时钟
16MHz Biblioteka CO SMCLK Peripherals
子系统时钟
上电后: MCLK 和 SMCLK 由DCOCLK 提 供(约1.1 MHz) ACLK 由 LFXT1CLK 提供(LF 模式,6pF内部负载电容)
• 。此外,其还可提供板上Flash 仿真工具, 以直接连接至PC 轻松进行编程、调试和评 估。 • MSP-EXP430G2 采用IAR Embedded Workbench 集成开发环境(IDE) 或Code Composer Studio (CCS)编写、下载和调试 应用。 • 可提供板上Flash 仿真工具,以直接连接至 PC 轻松进行编程、调试和评估。
MSP-EXP430G2入门
提纲:一.MSP-EXP430G2套件介绍1.包装清单unchPad简介(430文件夹_用户指南)(一)LaunchPad片上资源(1)开发板硬件简介(2)主要功能模块(二)LaunchPad特性(三)LaunchPad电路图(主要参考【LaunchPad】开发板介绍.pdf)3.MSP430G2553数据资料(技术资料汇总_G2553中文资料.pdf)4.安装MSP-EXP430G2 LaunchPad二.编译部分1.编译工具的选择2.编译工具的安装(根据安装提示便可)3.程序编译、烧录流程4.编程规则(MSP430 编程规则.pdf)三.基础程序部分1.功能模块程序(MSP430G2xx3 Code Examples文件夹)2.基础应用程序(例程代码)四.应用举例——MSP430G2452内置温度传感器温度检测五.LaunchPad扩展部分1.eZ430连接、编程要点2.与卫星板的连接3.与LaunchPad兼容的MSP430器件一.MSP-EXP430G2套件介绍1.包装清单:⏹LaunchPad目标板(附一个烧好测温实验例程的MPS430G2553)⏹MPS4302452一个——具有8通道10位ADC、片上比较器、触控式I/O、通用串行接口、8Kb闪存、256字节SRAM的低功耗16位MSP430微控制器⏹32.768KHz时钟晶振⏹0.5m长的USB-B线缆⏹插座式10引脚印刷板连接线两个⏹LaunchPad贴签两个⏹快速启动指南unchPad简介(一)LaunchPad片上资源(1)开发板硬件介绍:板上材料清单开发板指示图(2)主要功能模块:⏹复位模块⏹时钟模块⏹I/O端口模块;⏹WDT看门狗模块;⏹Timer A定时器模块⏹比较器A模块⏹ADC10数模转换模块⏹USART串行异步通讯模块⏹CPU模块(二)LaunchPad特性⏹实验班成本低、低功耗⏹USB调试与编程接口无需驱动即可安装使用,且具备高达9600波特的UART串行通信速度⏹支持所有采用PDIP14或PDIP20封装的MSP430G2XX和MSP430F20XX器件⏹分别连接至绿光和红光LED的两个通用数字I/O口引脚可提供视觉反馈⏹两个按钮可实现用户反馈和芯片复位⏹器件引脚可通过插座引出,既可以方便的用于调试,也可用来添加定制的扩展板⏹高质量的20引脚DIP插座,可轻松简便地插入目标器件或将其移除(三)LaunchPad电路图LaunchPad原理图见“【LaunchPad】开发板介绍.pdf”。
实验指导书MSP430G2实验指导书
MSP430G2 LanchPad 实验指导书实验一:基础GPIO实验实验目的:1、熟悉CCS的使用;2、掌握单片机编程思想;3、理解430单片机工作原理。
实验内容:1、点亮一盏LED;2、令LED闪烁;3、按键控制LED状态;实验步骤:内容一:点亮一盏LED1、打开CCS,选择workspace。
2、菜单,Project——New CCS Project——弹出如下界面。
3、需要修改红色标记。
即:文件名、文件位置、MCU系列型号、连接、工程类型,最后单击Finish。
4、在新窗口中输入如下代码:5、保存程序后Bulid(单击菜单中,或快捷键Ctrl+B)编译程序。
6、调试程序(单击菜单中)自动进入调试界面并下载程序。
7、运行程序(单击菜单中)进行程序的运行、暂停、停止、单步运行等操作。
8、观察实验现象,回顾操作步骤。
内容二:令LED闪烁1、关闭上一个工程(在Project Explorer窗口,右键Close Project)。
2、建立新工程,步骤同上。
3、根据要求编写相应程序。
4、编译,调试,运行程序。
5、部分函数参考代码。
延时函数:主函数部分:6、拓展:试着令LED2闪烁内容三:按键控制LED状态1、关闭上一个工程。
2、新建工程,步骤同上。
3、根据要求编写程序。
4、编译、调试、运行程序。
5、部分函数参考代码。
中断初始化:中断服务子程序:6、拓展,试着用非中断方式实现控制实验二:A/D实验实验目的:实验内容:实验步骤:实验三:定时器与看门狗实验实验目的:实验内容:实验步骤:实验四:Flash实验实验目的:实验内容:实验步骤:实验五:串行通信实验实验目的:实验内容:实验步骤:实验六:Flash实验实验目的:实验内容:实验步骤:实验七:比较器实验实验目的:实验内容:实验步骤:。
MSP430G2试验板使用
试验板引脚插线
试验板原理图及PCB图可以参考用户手册
MSP-EXP430G2LaunchPad特性:
• USB调试与编程接口无需驱动即可安装使用,且具备高达9600波 特率的UART串行通信速度 • 支持所有采用PDIP14或PDIP20封装的MSP430G2xx和 MSP430F20xx器件 • 两个通用数字I/O 引脚分别连接至绿光和红光LED • 两个按钮可实现反馈和器件复位
2.安装选定的IDE集成开发环境并将LaunchPad试验板连 接至PC
CCS已为在LaunchPad上开发基于MSP430G2xx的应用完成了所 有设置。当软件完成安装后,IDE 应该会发现作为USB:HID调试接
口的MSP-EXP430G2LaunchPad。
将附带USB线缆的MSP-EXP430G2LaunchPad插座电路板连接至 PC,将自动开始安装驱动。如果出现提示,要求提供软件,则允许 Windows自动安装该软件。
3. 利用IDE集成开发环境进行软件开发
主要步骤如下: (1)新建工程 (2)编辑程序文件并可以根据需要新建文件。 (3)进行程序调试 下面我们以LED流水灯程序为例进行讲解
1.建立LED流水灯工程
注意:器件类型和仿真器类型一定要选择正确
2.编辑程序文件并可以根据需要新建文件
在main.c里编辑LED流水灯程序 让P1.0和P1.6的LED1和LED2红 黄两色LED交替闪烁。
MSP-EXP430G2试验套件包括下列硬件:
• LaunchPad仿真器插座电路板(MSP-EXP430G2) • 0.5米长的小型USB-B线缆 • 两颗MSP430闪存器件 – MSP430G2553:具有8通道10位模数转换器(ADC)、片上比较器、 触控式使能I/O、通用串行通信接口、16kB闪存、和512字节RAM 的低功耗16位MSP430微控制器(预加载有示例程序) – MSP430G2452:具有8通道10位ADC、片上比较器、触控式I/O、 通用串行接口、8kB闪存、和256字节SRAM的低功耗16位 MSP430微控制器 • 两个插座式10引脚印刷电路板(PCB)连接器 • 由MicroCrystal公司()生产的 32.768kHz时钟晶振
MSP430 LaunchPad温度检测
MSP-EXP430G2 温度检测实验1.安装MSP-EXP430G2 LaunchPad安装MSP-EXP430G2 LaunchPad包含三个步骤:(1)下载所需软件:通常选IAR或者CCS。
(2)安装选定的IDE:下载一个集成开发环境(IDE),IAR或者CCS,安装(编译部分有详细介绍)。
(3)将LaunchPad连接至PC:将附带USB线缆的EXP430G2 LaunchPad目标板连接至PC。
如果出现提示,要求提供软件,则允许Windows自动安装该软件。
注意,仅当已经安装了IAR KickStart或Code Composer Studio后才能这样做。
2.温度检测程序基于MSP430G2452内置温度传感器的温度检测程序:include "msp430g2452.h”#define LED1 BIT0 //绿灯,BIT0,BIT6之类的是宏定义,请在头文件"msp430g2452.h"中查看#define LED2 BIT6 //红灯,参见MSP-EXP430G2 LaunchPad Experimenter Board User's Guide#define LED_DIR P1DIR#define LED_OUT P1OUT#define BUTTON BIT3 //P1.3为板上按键S2#define BUTTON_OUT P1OUT //端口输出寄存器#define BUTTON_DIR P1DIR //端口方向控制寄存器#define BUTTON_IN P1IN //端口输入寄存器#define BUTTON_IE P1IE //端口中断允许寄存器#define BUTTON_IES P1IES //端口中断触发沿控制寄存器#define BUTTON_IFG P1IFG //端口中断标志寄存器#define BUTTON_REN P1REN //端口上下拉电阻使能控制寄存器#define TXD BIT1 // TXD on P1.1#define RXD BIT2 // RXD on P1.2#define APP_STANDBY_MODE 0 //待机模式标志,也就是接上电源(或USB)后红绿灯交替闪的状态#define APP_APPLICATION_MODE 1 //应用模式标志,也就是待机模式时按按键后进入的状态,也就是测量温度#define TIMER_PWM_MODE 0#define TIMER_UART_MODE 1 //串口模式状态#define TIMER_PWM_PERIOD 2000#define TIMER_PWM_OFFSET 20#define TEMP_SAME 0#define TEMP_HOT 1#define TEMP_COLD 2#define TEMP_THRESHOLD 5// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz#define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment#define Bitime 13*4//0x0D#define UART_UPDATE_INTERVAL 1000 //主循环次数进行一次串口发送温度值unsigned char BitCnt;unsigned char applicationMode = APP_STANDBY_MODE; //功能模式标志,初始值为待机模式unsigned char timerMode = TIMER_PWM_MODE;unsigned char tempMode;unsigned char calibrateUpdate = 0;unsigned char tempPolarity = TEMP_SAME;unsigned int TXByte;/* Using an 8-value moving average filter on sampled ADC values */long tempMeasured[8]; //定义数组以计算8次10位ADC温度采样的平均值unsigned char tempMeasuredPosition=0; //温度测量值数组索引long tempAverage; //8次10位ADC温度采样的平均值long tempCalibrated, tempDifference;void InitializeLeds(void); //IO端口初始化,设置两颗LED对应的端口并两设置为熄灭初始状态void InitializeButton(void); //IO端口初始化,配置按键void PreApplicationMode(void); //进入待机模式,红绿灯交替闪,等待按键 Blinks LED, waits for button pressvoid ConfigureAdcTempSensor(void); //配置温度传感器模数转换void ConfigureTimerPwm(void); //配置定位器为PWM模式void ConfigureTimerUart(void); //配置定时器为Uart模式void Transmit(void); //串口发送子程序void InitializeClocks(void); //初始化时钟系统void main(void){unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL; //主循环次数进行一次串口发送温度值unsigned char i;WDTCTL = WDTPW + WDTHOLD; // 停止看门狗 Stop WDTInitializeClocks(); //初始化时钟系统InitializeButton(); //配置按键InitializeLeds(); //设置端口并两设置两颗LED对应为熄灭初始状态PreApplicationMode(); //进入待机模式,红绿灯交替闪,等待按键 Blinks LEDs, waits for button press//执行PreApplicationMode()将进入低功耗模式,程序停止在此,直到有按键按下/* 进入应用模式 Application Mode begins */applicationMode = APP_APPLICATION_MODE; //功能模式标志变成应用模式ConfigureAdcTempSensor(); //配置温度传感器模数转换ConfigureTimerPwm(); //配置定位器PWM模式__enable_interrupt(); //使能全局中断 Enable interrupts./* Main Application Loop */while(1){ADC10CTL0 |= ENC + ADC10SC; //ADC使能,ADC开始转换一次 Sampling and conversion start__bis_SR_register(CPUOFF + GIE); //进入省电模式LPM0,等待AD转换完成中断 LPM0 with interrupts enabled/* Moving average filter out of 8 values to somewhat stabilize sampled ADC */ tempMeasured[tempMeasuredPosition++] = ADC10MEM; //将温度采样值存入温度值数组下一位if (tempMeasuredPosition == 8)tempMeasuredPosition = 0; //复位温度采样值数组索引tempAverage = 0;for (i = 0; i < 8; i++)tempAverage += tempMeasured[i]; //累加温度采样值数组各值tempAverage >>= 3; //除以8得到平均值 Divide by 8 to get averageif ((--uartUpdateTimer == 0) || calibrateUpdate ) //如果主循环了UART_UPDATE_INTERVAL次或者参考温度按键按过{ConfigureTimerUart();if (calibrateUpdate){TXByte = 248; // A character with high value, outside of temp rangeTransmit(); //串口发送值248表示按键按下进行了校准参考calibrateUpdate = 0; //复位参考温度校准标志变量}TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 ); //计算温度华氏值Transmit(); //串口发送华氏温度值uartUpdateTimer = UART_UPDATE_INTERVAL; //复位循环计数变量ConfigureTimerPwm(); //配置定时器回PWM模式}tempDifference = tempAverage - tempCalibrated; //计算相对于参考温度的差值 if (tempDifference < -TEMP_THRESHOLD) //如果采样温度值低于参考温度值差值TEMP_THRESHOLD{tempDifference = -tempDifference; //差值取正tempPolarity = TEMP_COLD; //极性变量设为值TEMP_COLDLED_OUT &= ~ LED1; //LED1绿灯置灭}elseif (tempDifference > TEMP_THRESHOLD) //如果采样温度值高于参考温度值差值TEMP_THRESHOLD{tempPolarity = TEMP_HOT; //极性变量设为值TEMP_COLDLED_OUT &= ~ LED2; //LED2红灯置灭}else //如果相对于参考温度值偏差没有超过阈值TEMP_THRESHOLD{tempPolarity = TEMP_SAME; //性变量设为值TEMP_SAMETACCTL0 &= ~CCIE; //关TACCTL0中断使能TACCTL1 &= ~CCIE; //关TACCTL1中断使能LED_OUT &= ~(LED1 + LED2); //置两灯皆灭}if (tempPolarity != TEMP_SAME) //如果相对于参考温度值偏差超过阈值TEMP_THRESHOLD{tempDifference <<= 3; //温度偏差值乘以8tempDifference += TIMER_PWM_OFFSET; //加上一个偏置值TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) ); //置TACCR1,最大为TIMER_PWM_PERIOD-1。
MSP-EXP430Launchpad实验指南参考代码
MSP-EXP430Launchpad 实验指南参考代码附录本附录为MSP-EXP430Launchpad实验指南中各章节涉及示例程序的完整参考代码。
目录第三章 (1)3.5 (1)3.6 (4)第五章 (10)5.1.1 (10)5.1.2 (12)5.1.3 (13)5.1.4 (16)5.1.5 (17)5.1.6 (20)5.2.1 (21)5.2.2 (21)5.2.3 (24)5.2.4 (26)5.3.1 (28)5.3.2 (29)5.4.1 (29)5.4.2 (30)5.4.3 (33)5.5.1 (37)5.5.2 (41)5.5.3 (52)5.5.4 (52)5.5.5 (53)第六章 (57)6.1.3 (57)6.1.4 (58)6.2.3 (61)6.3.3 光照度检测模块程序设计 (64)6.4.3 (66)6.5.3 (72)6.6.3 (74)6.6.4 (76)第三章3.5Flash使用的代码样例#include "msp430g2553.h"/****************************************************g2553有4个数据段,每个数据段有64bytes,共256bytesD:0x1000 -- 0x003FC:0x1040 -- 0x107FB:0x1080 -- 0x10BFA:0x10C0 -- 0x10FF****************************************************/#define uint unsigned int#define uchar unsigned char#define SegA 0x010C0#define SegB 0x01080#define SegC 0x01040#define SegD 0x01000#define SegSize 64/********************Flash初始化********************/void FlashInit(){FCTL2=FWKEY+FSSEL_2+FN1; //选择SMLCK作为时钟源,二分频}/********************Flash检测忙********************/void FlashCheckBusy(){while(BUSY==(FCTL3&BUSY)); //检测是否忙}/********************Flash段擦除*******************/void FlashErase(int SegX){_DINT(); //关闭总中断FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+ERASE; //使能段擦除*((int *)SegX)=0x00; //段擦除--空写FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY|LOCK; //上锁return;}/********************Flash写字节********************/ void FlashWriteChar(uint addr,char wdata){_DINT(); //关闭总中断FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //写使能*((uchar *)addr)=wdata; //将wdata存入addr变量地址中 FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁return;}/********************Flash读字节********************/ char FlashReadChar(uint addr){char rdata;rdata=*(char*)addr; //读取addr所指地址的值return rdata;}/********************Flash写字********************/void FlashWriteWord(uint addr,uint wdata){_DINT(); //关闭总中断FlashCheckBusy(); //检测忙,若忙,则等待FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //写使能*((uint *)addr)=wdata; //向地址addr处写入wdataFCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁return;}/********************Flash读字********************/uint FlashReadWord(uint addr){uint rdata;rdata=*(uint *)addr; //读取变量addr地址的值return rdata;}/********************Flash修改字节********************/void FlashModifyChar(uint SegX,char AddrNum,char wdata){char i,TempArry[SegSize];for(i=0;i<SegSize;i++) //读入存{TempArry[i]=*(uint *)(SegX+i);}TempArry[AddrNum]= wdata; //在数组中的某一位置AddrNum写入wdata FlashErase(SegX); //段擦除FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //准备写for(i=0;i<SegSize;i++) //向段中重新写数组{*(uint *)(SegX+i)=TempArry[i];}FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁}/********************Flash批量写********************/void FlashBurstWrite(int SegX,int *pStr){int i;FlashErase(SegX); //段擦除FCTL3=FWKEY; //lock=0,开锁FCTL1=FWKEY+WRT; //写使能for(i=0;i<2*sizeof(pStr);i++) //将数组容写入段中{*(uchar *)(SegX+i)=*(pStr+i);}FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁}main(){char ReadChar;uint ReadWord;int p[]={'a','b','c','d'};WDTCTL=WDTPW+WDTHOLD; //关闭看门狗P1DIR=0xff; //P1口设为输出,闲置的I/O不悬空P2DIR=0xff; //P2口设为输出,闲置的I/O不悬空P1OUT=0xff; //P1口输出1P2OUT=0xff; //P2口输出1FlashInit(); //Flash初始化FlashErase(SegD);FlashWriteChar(0x01007,0x12); //向地址01008h写入12hReadChar=FlashReadChar(0x01007); //读取地址01008h的值FlashWriteWord(0x01008,0x3456); //向地址01009h和0100Ah依次写入56h和34hReadWord=FlashReadWord(0x01008); //读取从地址01009h起的一个字FlashWriteChar(0x01017,ReadChar); //向地址01018h写入12hFlashWriteWord(0x01018,ReadWord); //向地址01019h和0101Ah依次写入56h和34hFlashBurstWrite(SegC,p); //向SegD段从地址0110h依次写入a、b、c、dFlashModifyChar(SegB,0x02,0xef); //将地址0112h和0113h容改为e和f_BIS_SR(CPUOFF); //关闭CPU}3.61. USCI模块串行异步通信例程以MSP430G2553的USCI模块串行异步通信操作为例,介绍串口寄存器配置及收发程序处理过程。
MSP-EXP430Launchpad实验的指南参考代码
MSP-EXP430Launchpad 实验指南参考代码附录本附录为MSP-EXP430Launchpad实验指南中各章节涉与示例程序的完整参考代码。
目录第三章23.523.65第五章115.1.1115.1.2135.1.3145.1.4175.1.5185.1.6215.2.1225.2.2225.2.3255.2.4275.3.1295.3.2305.4.1305.4.2315.4.3355.5.1385.5.2425.5.3535.5.4545.5.555第六章586.1.3586.1.4596.2.3626.3.3 光照度检测模块程序设计666.4.3686.5.3736.6.3756.6.477第三章3.5Flash使用的代码样例#include "msp430g2553.h"/****************************************************g2553有4个数据段,每个数据段有64bytes,共256bytesD:0x1000 -- 0x003FC:0x1040 -- 0x107FB:0x1080 -- 0x10BFA:0x10C0 -- 0x10FF****************************************************/#define uint unsigned int#define uchar unsigned char#define SegA 0x010C0#define SegB 0x01080#define SegC 0x01040#define SegD 0x01000#define SegSize 64/********************Flash初始化********************/void FlashInit(){FCTL2=FWKEY+FSSEL_2+FN1; //选择SMLCK作为时钟源,二分频}/********************Flash检测忙********************/void FlashCheckBusy(){while(BUSY==(FCTL3&BUSY)); //检测是否忙}/********************Flash段擦除*******************/void FlashErase(int SegX){_DINT(); //关闭总中断FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+ERASE; //使能段擦除*((int *)SegX)=0x00; //段擦除--空写FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY|LOCK; //上锁return;}/********************Flash写字节********************/ void FlashWriteChar(uint addr,char wdata){_DINT(); //关闭总中断FlashCheckBusy(); //检测Flash是否处于忙状态FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //写使能*((uchar *)addr)=wdata; //将wdata存入addr变量地址中 FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁return;}/********************Flash读字节********************/ char FlashReadChar(uint addr){char rdata;rdata=*(char*)addr; //读取addr所指地址的值return rdata;}/********************Flash写字********************/void FlashWriteWord(uint addr,uint wdata){_DINT(); //关闭总中断FlashCheckBusy(); //检测忙,若忙,则等待FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //写使能*((uint *)addr)=wdata; //向地址addr处写入wdataFCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁return;}/********************Flash读字********************/uint FlashReadWord(uint addr){uint rdata;rdata=*(uint *)addr; //读取变量addr地址的值return rdata;}/********************Flash修改字节********************/void FlashModifyChar(uint SegX,char AddrNum,char wdata){char i,TempArry[SegSize];for(i=0;i<SegSize;i++) //读入存{TempArry[i]=*(uint *)(SegX+i);}TempArry[AddrNum]= wdata; //在数组中的某一位置AddrNum写入wdata FlashErase(SegX); //段擦除FCTL3=FWKEY; //lock=0开锁FCTL1=FWKEY+WRT; //准备写for(i=0;i<SegSize;i++) //向段中重新写数组{*(uint *)(SegX+i)=TempArry[i];}FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁}/********************Flash批量写********************/void FlashBurstWrite(int SegX,int *pStr){int i;FlashErase(SegX); //段擦除FCTL3=FWKEY; //lock=0,开锁FCTL1=FWKEY+WRT; //写使能for(i=0;i<2*sizeof(pStr);i++) //将数组容写入段中{*(uchar *)(SegX+i)=*(pStr+i);}FCTL1=FWKEY; //写关闭FCTL3=FWKEY+LOCK; //上锁}main(){char ReadChar;uint ReadWord;int p[]={'a','b','c','d'};WDTCTL=WDTPW+WDTHOLD; //关闭看门狗P1DIR=0xff; //P1口设为输出,闲置的I/O不悬空P2DIR=0xff; //P2口设为输出,闲置的I/O不悬空P1OUT=0xff; //P1口输出1P2OUT=0xff; //P2口输出1FlashInit(); //Flash初始化FlashErase(SegD);FlashWriteChar(0x01007,0x12); //向地址01008h写入12hReadChar=FlashReadChar(0x01007); //读取地址01008h的值FlashWriteWord(0x01008,0x3456); //向地址01009h和0100Ah依次写入56h和34hReadWord=FlashReadWord(0x01008); //读取从地址01009h起的一个字FlashWriteChar(0x01017,ReadChar); //向地址01018h写入12hFlashWriteWord(0x01018,ReadWord); //向地址01019h和0101Ah依次写入56h和34hFlashBurstWrite(SegC,p); //向SegD段从地址0110h依次写入a、b、c、dFlashModifyChar(SegB,0x02,0xef); //将地址0112h和0113h容改为e和f_BIS_SR(CPUOFF); //关闭CPU}3.61. USCI模块串行异步通信例程以MSP430G2553的USCI模块串行异步通信操作为例,介绍串口寄存器配置与收发程序处理过程。
MSP430单片机实验指导书
试验一一、实验目的进一步熟悉IAR for MSP430编程软件和PROTEUS仿真软件的使用。
了解并熟悉单片机I/O口和LED灯的电路结构,学会构建简单的流水灯电路。
掌握MSP430单片机I/O口的编程方法和使用I/O口进行输入输出的注意事项。
掌握PROTEUS仿真软件仿真MSP430单片机过程中的注意事项。
二、实验内容1、运用PROTEUS仿真软件绘制LED流水灯电路;2、运用IAR for MSP430编程软件编辑led流水灯程序,并且生成 .hex 或.d90文件,并且将生成的文件加载到单片机中,程序使用P1或其它端口来演示跑马灯,输出低电平驱动。
三、实验器材电脑一台四、实验原理及介绍LED流水灯实际上是一个带有发光二极管的单片机最小系统,即由led灯、电阻、电容器、电源等电路和必要的软件组成的单个的单片机;如果要让接在P1或其它端口的LED 灯亮起来,那么只需要将P1或其它端口的电平变为低电平就可以了。
同理,将该端口电平变为高电平,LED灯就会熄灭。
五、程序流程图六、实验步骤1、运用PROTEUS仿真软件绘制电路图;2、运用IAR for MSP430编写流水灯程序,并且生成‘’.hex’’或“.d90”文件3、将‘’.hex’’或“.d90”文件软件加载到PROTEUS仿真软件中;4、换一种流水灯的亮灭顺序,改变延时时间的大小,多次实验,灵活使用七、参考程序#include"msp430f249.h"#define uint unsigned int/******************** 主函数 **************************/ void main(void){Uint I;WDTCTL = WDTPW + WDTHOLD;P1DIR = ox0ff;while(1){PIOUT = 0x00;For(I = 0;I < 65565;I ++);PIOUT = 0x0ff;For(I = 0;I < 65565;I ++);}}八、心得体会(二页以上)实验二一、实验目的1.掌握IAR for MSP430软件与proteus软件仿真调试的方法;2.掌握LCD1602液晶模块显示西文的原理及使用方法;3.掌握用8位数据模式驱动LCM1602液晶的C语言编程方法;4.掌握用LCM1602液晶模块显示数字的C语言编程方法。
MSP-EXP430G2ET LaunchPad QuickStart Guide
IMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCESTexas Instruments Incorporated(‘TI”)technical,application or other design advice,services or information,including,but not limited to, reference designs and materials relating to evaluation modules,(collectively,“TI Resources”)are intended to assist designers who are developing applications that incorporate TI products;by downloading,accessing or using any particular TI Resource in any way,you (individually or,if you are acting on behalf of a company,your company)agree to use it solely for this purpose and subject to the terms of this Notice.TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI products,and no additional obligations or liabilities arise from TI providing such TI Resources.TI reserves the right to make corrections, enhancements,improvements and other changes to its TI Resources.You understand and agree that you remain responsible for using your independent analysis,evaluation and judgment in designing your applications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications (and of all TI products used in or for your applications)with all applicable regulations,laws and other applicable requirements.You represent that,with respect to your applications,you have all the necessary expertise to create and implement safeguards that(1) anticipate dangerous consequences of failures,(2)monitor failures and their consequences,and(3)lessen the likelihood of failures that might cause harm and take appropriate actions.You agree that prior to using or distributing any applications that include TI products,you will thoroughly test such applications and the functionality of such TI products as used in such applications.TI has not conducted any testing other than that specifically described in the published documentation for a particular TI Resource.You are authorized to use,copy and modify any individual TI Resource only in connection with the development of applications that include the TI product(s)identified in such TI Resource.NO OTHER LICENSE,EXPRESS OR IMPLIED,BY ESTOPPEL OR OTHERWISE TO ANY OTHER TI INTELLECTUAL PROPERTY RIGHT,AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTY RIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN,including but not limited to any patent right,copyright,mask work right,or other intellectual property right relating to any combination,machine,or process in which TI products or services are rmation regarding or referencing third-party products or services does not constitute a license to use such products or services,or a warranty or endorsement e of TI Resources may require a license from a third party under the patents or other intellectual property of the third party,or a license from TI under the patents or other intellectual property of TI.TI RESOURCES ARE PROVIDED“AS IS”AND WITH ALL FAULTS.TI DISCLAIMS ALL OTHER WARRANTIES OR REPRESENTATIONS,EXPRESS OR IMPLIED,REGARDING TI RESOURCES OR USE THEREOF,INCLUDING BUT NOT LIMITED TO ACCURACY OR COMPLETENESS,TITLE,ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE,AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHTS.TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM,INCLUDING BUT NOT LIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IF DESCRIBED IN TI RESOURCES OR OTHERWISE.IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL,DIRECT,SPECIAL, COLLATERAL,INDIRECT,PUNITIVE,INCIDENTAL,CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH OR ARISING OUT OF TI RESOURCES OR USE THEREOF,AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.You agree to fully indemnify TI and its representatives against any damages,costs,losses,and/or liabilities arising out of your non-compliance with the terms and provisions of this Notice.This Notice applies to TI Resources.Additional terms apply to the use and purchase of certain types of materials,TI products and services. These include;without limitation,TI’s standard terms for semiconductor products /sc/docs/stdterms.htm),evaluation modules,and samples(/sc/docs/sampterms.htm).Mailing Address:Texas Instruments,Post Office Box655303,Dallas,Texas75265Copyright©2018,Texas Instruments Incorporated。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
4
表2
口袋实验平台硬件功能单元
名称
元件
IO
P1.6/I2C SDA P1.7/I2C SCL
功能
利用 I2C 协议控制 TCA6416A 获得 16 个低速 IO IO00~IO07, IO10~IO17 4 个 I2C 扩展 IO 控制 HT1621 HT1621 控制段式液晶 4 个 I2C 扩展 IO 识别 机械按键 8 个 I2C 扩展 IO 控制 8 个 LED
对应书籍章节 4.8 5.6 6.7 7.8 7.10 7.12 7.12 8.5 8.6 10.8 11.5 13.3.2 12.7 13.4 14.8 17.6 19.4 20.5 21.5 22.3
Capactive touch USCI_UART USCI_SPI USCI_I2C Comparator_A ADC10 PWM DAC Self-Calibrate DCO Flash
IO 扩展
TCA6416A
显示 机械 按键 LED 灯 柱 触摸 按键 模拟 输出
HT1621 128 段 LCD 微动开关*4
IO14/扩展 IO;IO15/扩展 IO IO16/扩展 IO;IO17/扩展 IO IO10/扩展 IO;IO11/扩展 IO IO12/扩展 IO;IO13/扩展 IO IO00/扩展 IO;IO01/扩展 IO IO02/扩展 IO;IO03/扩展 IO IO04/扩展 IO;IO05/扩展 IO IO06/扩展 IO;IO07/扩展 IO P2.0 P2.5 P1.0/复用 P1.3/复用 P2.2/复用 P1.1/SPI SOMI P1.2/SPI SIMO P1.4/SPI CLK P2.4 P1.5/Comparator_A+ P1.3/复用 P2.2/复用 P2.1/TA1.1 P1.0/ADC10/复用
2
2 硬件
口袋实验室硬件原理框图如图 1 所示,参考图 1 和表 1:
图1
口袋实验室硬Biblioteka 原理框图1) 显示和输入单元:口袋实验平台利用 I2C 接口的 TCA6416A 扩展出 16 个低速双向 IO(IO00~IO07, IO10~IO17 )。 4 个扩展 IO 用于控制 LCD 驱动器 HT1621,4 个用于机械按键输入,8 个用于 LED 灯柱。 2) 触摸按键单元:两个触摸按键占用 P2.0 和 P2.5 两个 GPIO,MSP430G2 系列单片机的 P1 和 P2 全部具备振 荡功能。 3) 模拟输出单元:外部扩展了 12 位串行数模转换器 DAC7311,使用 P1.0/P1.3/P2.2 三个普通 GPIO 控制。 这三个 IO 同时被其他单元复用,但由于 DAC7311 都
II
序言
LaunchPad 口 袋 实 验 平 台 必 须 搭 配 MSP-EXP430G2 LaunchPad 实验板使用。注意,LaunchPad 实验板的盒子里有 一个晶振,请在实验前先焊接好。 口袋实验平台正式配套书籍《从零开启大学生电子设计之 路—基于 MSP430 LaunchPad 口袋实验平台》,由北京航空航 天大学出版社出版。该书内容涵盖单片机入门知识、编程方法、 片内外设知识和口袋实验平台例程的详细讲解。 口袋实验平台的全部例程代码可登陆 网站 进行下载。其他技术支持信息也将在该网站发布,恕不另行通 知。
4.11 I2C 扩展 IO .................................................................................. 31 4.12 LCD 显示自检 ............................................................................. 34 4.13 拨盘电位器 .................................................................................. 36 4.14 温度传感器采样及显示.............................................................. 38 4.15 SPWM 波形合成及采样 .............................................................. 40 4.16 任意波形发生器 AWG ............................................................... 43 4.17 基于 AWG 的音频播放器 .......................................................... 45 4.18 自校验 DCO ................................................................................ 47
3
是高阻输入口,所以无需跳线复用。音频功放 TPA301 可以将 DAC 输出进行电流放大,以便驱动喇 叭/蜂鸣器负载。 4) 扩展存储部分:由 SPI 协议控制 TF 卡,使用 P1.1/SPI SOMI、P1.2/SPI SIMO、P1.4/SPI CLK 三个 USCI 功 能 IO 和 1 个普通 P2.4 控制。 5) SLOPE ADC 单元:使用拨盘电位器作为待测电阻。 P1.5/Comparator_A+、P1.3、P2.2 三个 IO 进行控制。 P1.3、P2.2 复用,但同样无需跳线。 6) PWM 单元:P2.1/TA1.1 负责输出 SPWM;轨至轨运 放 TLV2372 负责将 SPWM 滤波为双极性模拟信号; TPS60400 提供运放所需负电源;三电阻网络负责将 双极性信号转变为单极性信号;P1.0/ADC10 负责对 单极性信号采样,P1.0 功能复用,同样无需跳线
1
口袋实验平台可以不借助其它测试仪器实现对单片机的内 部资源和外设的学习和实验。三个综合实验的录像中,使用了 部分仪器来丰富实验效果。 1) 在例程“20_Sin_Gen_and_Sample ”中可以使用示波器 观测 PWM 滤波波形,也可以利用仿真器间接观测波 形。 2) 例程 “21_1_DAC_AWG” 中使用了示波器,如无示波 器,可用例程“21_2_TF_Audio”替代学习 DAC 的使 用。 3) 例程“22_DCO_Calb_Test”录像中示波器和频率计的使 用是为了验证自校验 DCO 频率的精度,利用单片机 自制的频率计一样能满足要求,可自行编程实现频率 计功能。
1 口袋实验平台概述
口袋实验平台包含 MSP-EXP430G2 中配套的 MSP430G2553 单片机全部片内外设实验以及 3 个综合性实 验,如表 1 所示。
表1 实验例程列表
外设 System Clock GPIO Timer_A WDT
实验例程工程名 4_KEY_LED_Change_DCO 5_Interrupt_Key_LED 6_PWM_LED 7_1_Breath_Lamp 7_2_Timer_Key_LED 7_3_Key_Long_Short_Mealy 7_4_Key_Long_Short_Moore 8_1_TouchPad_LED 8_2_TouchPad_Long_Short_Mealy 10_UART_KeyBoard 11_SPI_SD 13_1_SD_Hard_or_Soft_SPI 12_I2C_LED_KEY 13_2_LED_KEY_I2C_Hard_or_Soft 14_LCD_SelfScan_Hard_or_Soft_I2C 17_Slope_ADC 19_ADC10_Temperature 20_Sin_Gen_and_Sample 21_1_DAC_AWG 21_2_TF_Audio 22_DCO_Calb_Test
MSP-EXP430G2 LacunchPad 口袋实验平台
用户手册
目录
序言............................................................................................................. 0 1 口袋实验平台概述 ................................................................................. 1 2 硬件......................................................................................................... 3 3 软件.......................................................................................................... 6 3.1 开发软件 ......................................................................................... 6 3.2 例程代码 ......................................................................................... 6 3.3 例程演示录像 ................................................................................. 8 3.4 快速培训演示文档 ......................................................................... 9 4 实验例程简介 ........................................................................................ 10 4.1 观测 DCO 频率变化 ...................................................................... 10 4.2 中断按键 ........................................................................................ 12 4.3 基于 PWM 的 LED 调光控制 ...................................................... 14 4.4 呼吸灯 ........................................................................................... 16 4.5 定时扫描非阻塞按键 ................................................................... 18 4.6 长短键识别 .................................................................................... 20 4.7 电容触摸按键 ................................................................................ 21 4.8 电容触摸长短键 ............................................................................ 24 4.9 超级终端人机交互 ....................................................................... 26 4.10 SD 卡读写扇区 ............................................................................ 28 I