launchpad 定时器问题
#include "msp430g2553.h"#define CS_1 P2OUT|=BIT0
#define CS_0 P2OUT&=~BIT0
#define SCLK_1 P2OUT|=BIT1
#define SCLK_0 P2OUT&=~BIT1
#define DIN_1 P2OUT|=BIT2
#define DIN_0 P2OUT&=~BIT2
unsignedint j=0;
unsigned int const dot={0x200,0x20c,0x219,0x225,0x232,0x23e,0x24b,0x257,0x263,0x270,0x27c,0x288,0x294,
0x2a0,0x2ac,0x2b8,0x2c3,0x2cf,0x2da,0x2e6,0x2f1,0x2fc,0x307,0x311,0x31c,0x326,0x330,0x33a,0x344,0x34e,
0x357,0x360,0x369,0x372,0x37b,0x383,0x38b,0x393,0x39b,0x3a2,0x3a9,0x3b0,0x3b7,0x3bd,0x3c3,0x3c9,0x3ce,
0x3d3,0x3d8,0x3dd,0x3e1,0x3e6,0x3e9,0x3ed,0x3f0,0x3f3,0x3f6,0x3f8,0x3fa,0x3fc,0x3fd,0x3fe,0x3ff,0x3ff,
0x3ff,0x3ff,0x3ff,0x3fe,0x3fd,0x3fc,0x3fa,0x3f8,0x3f6,0x3f3,0x3f0,0x3ed,0x3ea,0x3e6,0x3e2,0x3dd,0x3d9,
0x3d4,0x3cf,0x3c9,0x3c3,0x3bd,0x3b7,0x3b0,0x3aa,0x3a2,0x39b,0x393,0x38c,0x384,0x37b,0x373,0x36a,0x361,
0x358,0x34e,0x345,0x33b,0x331,0x327,0x31d,0x312,0x307,0x2fc,0x2f1,0x2e6,0x2db,0x2d0,0x2c4,0x2b8,0x2ad,
0x2a1,0x295,0x289,0x27d,0x270,0x264,0x258,0x24b,0x23f,0x232,0x226,0x219,0x20d,0x200,0x1f4,0x1e7,0x1db,
0x1ce,0x1c2,0x1b5,0x1a9,0x19c,0x190,0x184,0x178,0x16c,0x160,0x154,0x148,0x13c,0x131,0x125,0x11a,0x10f,
0x104,0xf9,0xee,0xe4,0xd9,0xcf,0xc5,0xbb,0xb2,0xa8,0x9f,0x96,0x8d,0x85,0x7c,0x74,0x6d,0x65,0x5e,0x56,
0x50,0x49,0x43,0x3c,0x37,0x31,0x2c,0x27,0x22,0x1e,0x1a,0x16,0x12,0xf,0xc,0xa,0x7,0x5,0x3,0x2,0x1,0x0,
0x0,0x0,0x0,0x0,0x1,0x2,0x3,0x5,0x7,0x9,0xc,0xf,0x12,0x15,0x19,0x1d,0x21,0x26,0x2b,0x30,0x36,0x3b,0x41,
0x48,0x4e,0x55,0x5c,0x63,0x6b,0x73,0x7b,0x83,0x8c,0x94,0x9d,0xa7,0xb0,0xba,0xc3,0xcd,0xd7,0xe2,0xec,0xf7,
0x102,0x10d,0x118,0x123,0x12f,0x13a,0x146,0x152,0x15d,0x169,0x175,0x182,0x18e,0x19a,0x1a6,0x1b3,0x1bf,
0x1cc,0x1d8,0x1e5,0x1f1
//本表由VsinTab生成 http://cinzy.com
};
void interuppt_init();
void port_init();
void sin(unsigned int date);
/*******************************中断初始化程序*******************************/
void interuppt_init()
{
/*******************************时钟源的配置********************************/
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG;
// BCSCTL1 |= DIVA_3; // ACLK = VLO/8
// BCSCTL2 |= SELM_3 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
/**************************定时器时钟源的选择*****************************/
TACTL = TASSEL_2 + MC_1+ TAIE; // 时钟源:SMCLK, 计数模式为MC_1
CCR0 = 78; //定时器计数 50000次,50000*1us=50ms
CCTL0 = CCIE; //中断使能
_BIS_SR(GIE);
}
/******************************端口初始化***********************************/
void port_init()
{
WDTCTL=WDTPW+WDTHOLD; //关看门狗
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased, trap CPU!!
}
P1DIR|=BIT0;
P1OUT&=~BIT0;
P2DIR|=BIT0+BIT1+BIT2;
P2OUT&=(~BIT0)+(~BIT1)+(~BIT2);
}
void sin(unsigned int date)
{
unsigned char i=0;
P2DIR|=BIT0+BIT1+BIT2;
CS_0;
SCLK_0;
date=(date<<6);
for(i=0;i<12;i++)
{
if(date&0x8000)
{
DIN_1;
}
else
DIN_0;
SCLK_1;
_delay_cycles(1);
SCLK_0;
date=date<<1;
_delay_cycles(1);
}
CS_1;
}
/*****************************主函数******************************************/
void main(void)
{
port_init();
interuppt_init();
while(1);
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
switch( TA0IV )
{
case10:
P1OUT^=BIT0;
/* sin(dot);
j++;
if(j>255)
j=0;*/
break;
}
}
上面是我产生正弦波的程序,在中断函数里屏蔽/* sin(dot); j++; if(j>255) j=0; */与不屏蔽,中断时间不一样,不知道为什么。求解决,在线等 怎么解决阿?好烦阿 有什么号烦的
页:
[1]