官方代码
#include <msp430.h>int main(void)
{WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog TimerDCOCTL = DCO0 + DCO1 + DCO2; // Max DCOBCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on, max RSELBCSCTL2 |= SELS; // SMCLK = XT2P5DIR |= 0x70; // P5.6,5,4 outputsP5SEL |= 0x70; // P5.6,5,5 optionswhile(1){}
}
自己写
#include "MSP430x14x.h"int main( void )
{// Stop watchdog timer to prevent time out resetWDTCTL = WDTPW + WDTHOLD;/*DCO frequency select. */DCOCTL |=(BIT5+BIT6+BIT7);//=7;BCSCTL1 |= (RSEL0+RSEL1+RSEL2);//DCO MAX;/*ACLK*///BCSCTL1 &= ~XTS; //因为默认是0,所以可以不用设置;//BCSCTL1 &= ~(DIVA0+DIVA1);/*SMCLK*/BCSCTL1 &= ~XT2OFF; //因为默认是1<关闭>,所以置1;BCSCTL2 &= ~SELS; //1:外部时钟;0:DCOBCSCTL2 |= DIVS_1; //2分频/*MCLK*/BCSCTL2 |= SELM_0; //选择主系统的时钟源BCSCTL2 |= DIVM_0; //1分频/*Oscillator fault interrupt enable*/__enable_interrupt(); //开启中断;
// IE1 |= OFIE; //中断使能;这个不能置一,不知道为啥,置一就有问题,官方提供的例子也没有使OFIE置一,感觉好奇怪do{IFG1 &= ~OFIFG; //中断标志位清零/*DELAY*/__no_operation();}while(IFG1&OFIFG); //没有振荡器置位则跳出循环P5DIR |= 0x70; // P5.6,5,4 outputsP5SEL |= 0x70; // P5.6,5,5 options for(;;);}