简单呼吸灯源码~~LAUNCHPAD直接下载即可
[复制链接]
环境 IAR5.50
#include "msp430g2553.h"
int dir=0;
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TA_overflow(void)
{
if (dir==0)
{
if (TACCR1<49998)
{
TACCR1+=1;
}
else
{
dir=1;
}
}
if (dir==1)
{
if (TACCR1>1002)
{
TACCR1-=1;
}
else
{
dir=0;
}
}
}
void main( void )
{
WDTCTL = WDTPW + WDTHOLD; //WDT STOP
P1OUT|=BIT6;
P1DIR|=BIT6; //Port setting
P1SEL|=BIT6;
DCOCTL|=0xe0; //Clock Setting
BCSCTL1=0x80;
BCSCTL1|=0x08;
TACTL|=TASSEL_2+MC_1+ID_0+TAIE; //TimerA setting
TACCTL1&=~CAP;
TACCTL1 |= OUTMOD_3;
TACCR0=50000;
TACCR1=1000;
_EINT();
while(1)
{
_NOP();
}
}
复制进去直接下载就能看到效果
可以根据自己喜好改变参数,改变时钟频率,分频或者是 TACCR0, TACCR1.
要是能加个电容那就更好
|