/*******************************************************
程序功能:单色流水灯测试
开发环境:IAR For MSP430 5.30
硬件环境:EESKILL多功能开发学习板/实验箱(2017版),MSP430F149核心板
接线说明:核心板P4口接底板JP15,具体为:P40-I1,P41-I2,P42-I3,P43-I4,P44-I5,P45-I6,P46-I7,P47-I8
跳线说明:无
实验现象:8个流水灯依次点亮
技术网站:http://www.eeskill.com
淘宝店铺:http://cepark.taobao.com
作者:eeskill
*******************************************************/
#include
unsigned int timer;
unsigned char jishu1,i;
unsigned char code[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(unsigned int timer);
void Clock_init()
{
unsigned char iq0;
BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on, max RSEL
BCSCTL1&=~XT2OFF; //打开XT2振荡器
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (iq0 = 255; iq0 > 0; iq0--); // 延时,等待XT2起振
}
while ((IFG1 & OFIFG) != 0); // 判断XT2是否起振
BCSCTL2 |= SELS+SELM_2; // SMCLK = XT2
}
void timerA_init()
{
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 8000; // 晶振8M
TACTL = TASSEL_2 + MC_1+TACLR; // SMCLK, upmode
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
Clock_init();
P4DIR |= 0xff; // P4output
timerA_init();
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
for(i=0;i<8;i++)
{
P4OUT=~(code[i]);
for( jishu1=0; jishu1<100; jishu1++)
{
delay(5000);
}
}
}
void delay(unsigned int timer)
{
unsigned int i;
for(i=0;i<10000;i--)
for(;timer>0;timer--)
;
}