#include <msp430x14x.h> void int_clk();
void delay(int i);
void main()
{
WDTCTL = WDTPW + WDTHOLD;
int_clk();
P6DIR = 0XFF;
P6OUT = 0Xff;
while()
{
P6OUT = 0XFF;
delay();
P6OUT = 0x00;
delay();
}
} void int_clk()
{
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM_1 + SELS;
do
{
IFG1 &= ~OFIFG;
for(int i=;i<;i++)
_NOP();
}while((IFG1 & OFIFG)!=);
IFG1 &= ~OFIFG;
} void delay(int i)
{
while(i--);
}
提示:IAR的配置要正确
升级版本:
/***********************************************
程序功能:实现流水灯以三种流动方式和四种流动速度
的不同组合而进行点亮"流动"
------------------------------------------------*/
#include <msp430x14x.h>
int flag=,i=,j=,dir=,speed=;
void int_clk();
void delay(int i);
void main()
{
WDTCTL = WDTPW + WDTHOLD;
int_clk();
P6DIR = 0XFF;
P6OUT = 0XFF; TACCTL0 = CCIE; //使能CCR0中断
TACCR0 = ;
TACTL = TASSEL_2 + MC_1 + ID_3; //定时器A选择SMCLK,增计数,8分频 _EINT();
LPM0;
}
/*******************************************
函数名称:Timer_A
功 能:定时器A的中断服务函数,在这里通过标志
控制流水灯的流动方向和流动速度
参 数:无
返回值 :无
********************************************/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
if(flag == )
{
P6OUT = ~(0x80>>(i++)); //灯的点亮顺序D8 -> D1
}
else if(flag == )
{
P6OUT = ~(0x01<<(i++)); //灯的点亮顺序D1 -> D8
}
else
{
if(dir) //灯的点亮顺序 D8 -> D1,D1 -> D8,循环绕圈
P6OUT = ~(0x80>>(i++));
else
P6OUT = ~(0x01<<(i++));
} if(i == )
{
i = ;
dir = ~dir;
}
delay();
j++;
if(j == )
{
i = ;
j = ;
flag++;
if(flag == ) flag = ;
switch(speed)
{
case :
// TACTL &=~ (ID0 + ID1);
TACTL |= ID_3;
break;
case :
// TACTL &=~ (ID0 + ID1);
TACTL |= ID_2;
break;
case :
// TACTL &=~ (ID0 + ID1);
TACTL |= ID_1;
break;
case :
// TACTL &=~ (ID0 + ID1);
TACTL |= ID_0;
break;
default:
break;
}
if(flag != ) speed++;
if(speed == ) speed = ;
}
}
void int_clk()
{
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM_1 + SELS; //DCO在800KHZ左右
do
{
IFG1 &= ~OFIFG;
for(int i=;i<;i++)
_NOP();
}while((IFG1 & OFIFG)!=);
IFG1 &= ~OFIFG;
} void delay(int i)
{
while(i--);
}