#include "msp430x14x.h"
#define uchar unsigned char
#define uint unsigned int
uchar num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar n=0,i=0;
void main( void )
{
uint a;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//IE1|=WDTIE;
//WDTCTL=WDT_ADLY_1_9;
P4DIR=0xff;
P6DIR|=0x18;
P4OUT=0x00;
BCSCTL1&=~XT2OFF; //设置XT2CLK有效
do
{
IFG1&=~OFIFG; //清除失效标志
for(a=0xff;a>0;a--);//稳定时间
}
while((IFG1&OFIFG)!=0); //如果失效标志仍存在则继续循环清除
BCSCTL2|=SELS; // 选择XT2CLK为SMCLK的时钟源
CCTL0=CCIE; //CCR0中断允许
CCR0=20000;
TACTL=TASSEL_2+TACLR+MC_1;//定时器A时钟源为SMCLK,计数器清零,增计数模式
_EINT();
}
#pragma vector=TIMERA0_VECTOR
__interrupt void timer_A(void)
{
P6OUT=0x08;
P4OUT=0x00;
P4OUT=wei[i++];
P6OUT=0x10;
P4OUT=num[n++];
P6OUT=0x00;
if(i==8)i=0;
if(n==8)n=0;
}
这是我自己写的数码管动态扫描程序,为什么不要红色一段代码,XT2也能工作啊?
|