msp430g2553基本程序实例Word格式.docx
- 文档编号:20283745
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:25
- 大小:21.37KB
msp430g2553基本程序实例Word格式.docx
《msp430g2553基本程序实例Word格式.docx》由会员分享,可在线阅读,更多相关《msp430g2553基本程序实例Word格式.docx(25页珍藏版)》请在冰豆网上搜索。
DCOCTL=CALDCO_1MHZ;
//SetDCOstep+modulation
BCSCTL3|=LFXT1S_2;
//SetLFXT1
P1DIR=BIT6;
//P1.6output(greenLED)
P1OUT=0;
//LEDoff
IFG1&
=~OFIFG;
//ClearOSCFaultflag
BCSCTL2|=SELM_1+DIVM_0;
//SetMCLK
for(;
;
)
P1OUT=BIT6;
//P1.6on(greenLED)
_delay_cycles(100);
P1OUT=0;
//greenLEDoff
_delay_cycles(5000);
}
2.
//LaunchPadLab3-SoftwarePortInterruptService
///|\||
//--o--|P1.3P1.0|-->
//\|/
P1DIR|=BIT0;
//SetP1.0tooutputdirection
P1IES|=BIT3;
//P1.3Hi/loedge
P1IFG&
=~BIT3;
//P1.3IFGcleared
P1IE|=BIT3;
//P1.3interruptenabled
_BIS_SR(LPM4_bits+GIE);
//EnterLPM4w/interrupt
//Port1interruptserviceroutine
#pragmavector=PORT1_VECTOR
__interruptvoidPort_1(void)
if(P1IFG&
BIT3)
P1OUT^=BIT0;
//P1.0=toggle
P1IFG&
3.
//LaunchPadLab5-ADC10,SampleA10TempandConverttooCandoF
//MSP430G2452
//|A10|
#include"
msp430g2553.h"
longtemp;
longIntDegF;
longIntDegC;
//StopWDT
//ConfigureADC10
ADC10CTL1=INCH_10+ADC10DIV_3;
//ChooseADCChannelasTempSensor
ADC10CTL0=SREF_1+ADC10SHT_3+REFON+ADC10ON+ADC10IE;
//ChooseADCRefsource
__enable_interrupt();
//Enableinterrupts.
TACCR0=30;
//DelaytoallowReftosettle
TACCTL0|=CCIE;
//Compare-modeinterrupt.
TACTL=TASSEL_2|MC_1;
//TACLK=SMCLK,Upmode.
LPM0;
//Waitfordelay.
TACCTL0&
=~CCIE;
//DisabletimerInterrupt
__disable_interrupt();
while
(1)
ADC10CTL0|=ENC+ADC10SC;
//Samplingandconversionstart
__bis_SR_register(LPM0_bits+GIE);
//LPM0withinterruptsenabled
//oF=((A10/1024)*1500mV)-923mV)*1/1.97mV=A10*761/1024-468
temp=ADC10MEM;
IntDegF=((temp-630)*761)/1024;
//oC=((A10/1024)*1500mV)-986mV)*1/3.55mV=A10*423/1024-278
IntDegC=((temp-673)*423)/1024;
__no_operation();
//SETBREAKPOINTHERE
//ADC10interruptserviceroutine
#pragmavector=ADC10_VECTOR
__interruptvoidADC10_ISR(void)
__bic_SR_register_on_exit(LPM0_bits);
//ClearCPUOFFbitfrom0(SR)
#pragmavector=TIMER0_A0_VECTOR
__interruptvoidta0_isr(void)
TACTL=0;
4.
//MSP430F20xxDemo-BasicClock,OutputBufferedSMCLK,ACLKandMCLK/10
//Description:
BufferACLKonP2.0,defaultSMCLK(DCO)onP1.4andMCLK/10on
//P1.5.
//ACLK=LFXT1=VLO,MCLK=SMCLK=defaultDCO
////*ExternalwatchcrystalinstalledonXINXOUTisrequiredforACLK*//
//MSP430F20xx
//|||
//|P1.4/SMCLK|-->
SMCLK=DefaultDCO
//|P1.5|-->
MCLK/10=DCO/10
//|P1.0/ACLK|-->
ACLK=VLO
//M.Buccini/L.Westlund
//TexasInstrumentsInc.
//October2005
//BuiltwithIAREmbeddedWorkbenchVersion:
3.40A
msp430x20x3.h>
unsignedchars;
WDTCTL=WDTPW+WDTHOLD;
//StopWatchdogTimer
//LFXT1=VLO
//DCOCTL=0;
//BCSCTL1=CALBC1_16MHZ;
//DCOCTL=CALBC1_16MHZ;
P1DIR|=0x31;
//P1.0,5andP1.4outputs
P1SEL|=0x11;
//P1.0,4ACLK/VLO,SMCLK/DCOoutput
//SMCLKSub-SystemMainClk,ACLK和SMCLK可以通过复用引脚输出,MCLK不能直接输出体现,MCLK可以配置为VLO或者DCO
P1OUT|=0x20;
//P1.5=1,通过开关P1.5来体现MCLK,这两条指令的周期大概为SMCLK的1/10
P1OUT&
=~0x20;
//20;
5.
//MSP430xG46xDemo-FLL+,RunsInternalDCOat8MHz
ThisprogramdemonstratessettingtheinternalDCOtorunat
//8MHzwithauto-calibrationbytheFLL+.
//ACLK=LFXT1=32768Hz,MCLK=SMCLK=DCO=(121+1)x2xACLK=7995392Hz
////*AnexternalwatchcrystalbetweenXIN&
XOUTisrequiredforACLK*//
//MSP430xG461x
//|||32kHz
//|P1.1|-->
MCLK=8MHz
ACLK=32kHz
//K.Quiring/M.Mitchell
//October2006
3.41A
//*****************************************************************************
msp430xG46x.h>
FLL_CTL0|=DCOPLUS+XCAP18PF;
//DCO+set,freq=xtalxDxN+1
SCFI0|=FN_4;
//x2DCOfreq,8MHznominalDCO
SCFQCTL=121;
//(121+1)x32768x2=7.99MHz
P1DIR=0x22;
//P1.1&
P1.5tooutputdirection
P1SEL=0x22;
P1.5tooutputMCLK&
ACLK
while
(1);
//Loopinplace
6.
//****************************************************************************
//MSP430xG46xDemo-FlashIn-SystemProgramming,CopySegAtoSegB
ThisprogramfirsterasesflashsegA,thenitincrementsall
//valuesinsegA,theniterasessegB,thencopiessegAtosegB.
//AssumedMCLK550kHz-900kHz.
////*SetBreakpointonNOPintheMainlooptoavoidStressingFlash*//
//M.Mitchell
//Feb2005
3.21A
charvalue;
//8-bitvaluetowritetosegmentA
//Functionprototypes
voidwrite_SegA(charvalue);
voidcopy_A2B(void);
FCTL2=FWKEY+FSSEL0+FN0;
//MCLK/2forFlashTimingGenerator
value=0;
//Initializevalue
while
(1)//Repeatforever
write_SegA(value++);
//WritesegmentA,incrementvalue
copy_A2B();
//CopysegmentAtoB
_NOP();
voidwrite_SegA(charvalue)
char*Flash_ptr;
//Flashpointer
unsignedinti;
Flash_ptr=(char*)0x1080;
//InitializeFlashpointer
FCTL1=FWKEY+ERASE;
//SetErasebit
FCTL3=FWKEY;
//ClearLockbit
*Flash_ptr=0;
//DummywritetoeraseFlashsegment
FCTL1=FWKEY+WRT;
//SetWRTbitforwriteoperation
for(i=0;
i<
128;
i++)
*Flash_ptr++=value;
//Writevaluetoflash
FCTL1=FWKEY;
//ClearWRTbit
FCTL3=FWKEY+LOCK;
//SetLOCKbit
voidcopy_A2B(void)
char*Flash_ptrA;
//SegmentApointer
char*Flash_ptrB;
//SegmentBpointer
Flash_ptrA=(char*)0x1080;
//InitializeFlashsegmentApointer
Flash_ptrB=(char*)0x1000;
//InitializeFlashsegmentBpointer
*Flash_ptrB=0;
//DummywritetoeraseFlashsegmentB
*Flash_ptrB++=*Flash_ptrA++;
//CopyvaluesegmentAtosegmentB
7.
//MSP430xG46xDemo-SoftwarePortInterruptonP1.0fromLPM4
Ahi/lowtransitiononP1.0willtriggerP1_ISRwhich,
//togglesP2.1.NormalmodeisLPM4~0.1uA.LPM4currentcanbemeasured
//withtheLEDremoved,allunusedP1.x/P2.xconfiguredasoutputorinputs
//pulledhighorlow,andensuretheP2.0interruptinputdoesnotfloat.
//ACLK=32.768kHz,MCLK=SMCLK=defaultDCO
///|\||
//--|RST|
//--o--|P1.0P2.1|-->
FLL_CTL0|=XCAP14PF;
//Configureloadcaps
P2DIR=BIT1;
//SetP2.1tooutputdirection
P1IES=BIT0;
//H-Ltransition
P1IE=BIT0;
//Enableinterrupt
//LPM4,enableinterrupts
__interruptvoidPort1_ISR(void)
unsignedvolatileinti;
for(i=10000;
i>
0;
i--);
//Debouncedelay
=~BIT0;
//ClearP1IFG
if((P1IN&
0x01)==0)
P2OUT^=0x02;
//ToggleP2.1usingexclusive-OR
8.
//************************
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- msp430g2553 基本 程序 实例