#include "msp430.h"
typedef unsigned char uchar;
typedef unsigned int uint;
uchar flag;
uchar table[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,
44,45,46,47,48,49,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,
33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,
10,9,8,7,6,5,4,3,2,1,0};//呼吸的效果
void main(void)
{
uchar i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 &= ~XT2OFF; //打开xt2晶振
do
{
IFG1 &= ~OFIFG;
for(i = 0xff; i > 0; i--);
}
while((IFG1 & OFIFG)); //等待起振,消除晶体失败标志
BCSCTL2 |= SELM_2 + SELS; //mclk.smclk选择高频晶振
TACTL |= TASSEL_2 + ID_3 + MC_1; //计数时钟选测smclk,8分频,增计数模式 1mhz
//TBCTL |= TBSSEL_2 + ID_3+ MC_1 ;
TBCTL|= TBSSEL_2 + TBCLGRP_0 + ID_3 + MC_1 + CNTL_0;
P2SEL|=BIT3;
P2DIR|=BIT3;
TBCCR0 = 50; // 50us de 周期
TBCCTL1 = OUTMOD_3+CLLD_0;
TACCR0 =5000;
TBCCTL0 = CCIE; // 开中断使能
_EINT(); // Enter LPM0 w/ interrupt
//LPM0; //低功耗
while(1); //应该不会进入此句
}
#pragma vector = TIMERB0_VECTOR
__interrupt void timeA()
{
static uchar i = 0;
flag++;
if(flag == 4) //大概20 ms时 较为理想
{
flag = 0;
TBCCR1 = table[i++];
if(i > 100)
i = 0;
}
}
此帖出自
小平头技术问答
#include "msp430.h"
typedef unsigned char uchar;
typedef unsigned int uint;
unsigned int flag;
uchar table[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,
44,45,46,47,48,49,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,
33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,
10,9,8,7,6,5,4,3,2,1,0};//呼吸的效果
void main(void)
{
uchar i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 &= ~XT2OFF; //打开xt2晶振
do
{
IFG1 &= ~OFIFG;
for(i = 0xff; i > 0; i--);
}
while((IFG1 & OFIFG)); //等待起振,消除晶体失败标志
BCSCTL2 |= SELM_2 + SELS; //mclk.smclk选择高频晶振
//TACTL |= TASSEL_2 + ID_3 + MC_1; //计数时钟选测smclk,8分频,增计数模式 1mhz
TBCTL |= TBSSEL_2 + ID_3+ MC_1 ;
P2DIR |= BIT4 + BIT3; // P2.3 .4输出
P2SEL |= BIT4 + BIT3 ; // P2.3 .4特殊功能ta1
TBCCR0 = 50; // 50us de 周期
TBCCTL0 = CCIE; // 开中断使能
TBCCTL2 = OUTMOD_3 ; // 输出方式3
TBCCTL1 = OUTMOD_3;
_EINT(); // Enter LPM0 w/ interrupt
LPM0; //低功耗
while(1); //应该不会进入此句
}
#pragma vector = TIMERB0_VECTOR
__interrupt void timeB()
{
static uchar i = 0,j = 0;
flag++;
if(flag == 400) //大概20 ms时 较为理想
{
flag = 0;
TACCR2 = table[i++];
TACCR1 = table[j++];
if(i > 100)
i = 0;
if(j > 100)
j = 0;
}
}
这是我的程序,求大神指导 啊 , 用的msp430f149
一周热门 更多>