#include
void Delay(unsigned int dly);
void main( void )
{
//unsigned char i;
WDTCTL = WDTPW + WDTHOLD;
P7SEL |= BIT0 + BIT1; // 启动XT1
UCSCTL1 = DCORSEL_2;// DCO 范围配置 0.35到0.75Mhz
while (SFRIFG1 & OFIFG) // 等待时钟系统正常工作
{
UCSCTL7 &= ~( XT1LFOFFG + DCOFFG ); //清除错误标志位
SFRIFG1 &= ~OFIFG; //清除错误标志位
for(unsigned int i = 0; i <10000; i--);
}
//UCSCTL4 = SELM__DCOCLK + SELA__XT1CLK + SELS__VLOCLK;// 设置时钟源
UCSCTL4 = SELM__XT1CLK + SELA__XT1CLK + SELS__VLOCLK;
P1DIR |= BIT0; // LED指示灯P1.0,需要短接JP2
P11SEL |= BIT0 + BIT1 + BIT2;
P11DIR |= BIT0 + BIT1 + BIT2;
while(1)
{
Delay(5333);
P1OUT ^= BIT0; // LED闪烁
}
}
void Delay(unsigned int dly)
{
while(dly--);
}
它汇编的Delay有5条语句,外界XT1是32768,按理说如果延时1s的话应该是32768/5=6553.6,这里写的是5333,把他们扩大10倍发现5333才是精确的1s,求高手 |