TA的每日心情 | 奋斗 2014-7-27 19:32 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
|
楼主 |
发表于 2014-7-27 19:28:38
|
显示全部楼层
heelary 发表于 2014-7-27 17:18
先输出一个50%占空比的PWM脉冲,然后低通滤波。
嗯嗯 谢谢你了 我用下面这个程序时编译时出现了错误,我不知道怎么改,还希望你指点指点
#include "msp430.h"
short
temp[200]={2500,2578,2656,2735,2813,2891,2968,3045,3121,3197,3272,3346,3420,
3492,3564,3634,3704,3772,3839,3904,3969,4031,4093,4152,4211,4267,4322,4374,
4425,4474,4522,4567,4610,4651,4690,4727,4761,4793,4823,4851,4877,4900,4920,
4939,4955,4968,4979,4988,4994,4998,4999,4998,4994,4988,4979,4968,4955,4939,
4920,4900,4877,4851,4823,4793,4761,4727,4690,4651,4610,4567,4522,4474,4425,
4374,4322,4267,4211,4152,4093,4031,3969,3904,3839,3772,3704,3634,3564,3492,
3420,3346,3272,3197,3121,3045,2968,2891,2813,2735,2656,2578,2500,2421,2343,
2264,2186,2108,2031,1954,1878,1802,1727,1653,1579,1507,1435,1365,1295,1227,
1160,1095,1030,968,906,847,788,732,677,625,574,525,477,432,389,348,309,272,
238,206,176,148,122,99,79,60,44,31,20,11,5,1,0,1,5,11,20,31,44,60,79,99,122,
148,176,206,238,272,309,348,389,432,477,525,574,625,677,732,788,847,906,968,
1030,1095,1160,1227,1295,1365,1435,1507,1579,1653,1727,1802,1878,1954,2031,
2108,2186,2264,2343,2421};
int i=0;
int main(void)
{ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{ while(1); // If calibration constants erased, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
P1DIR = 0x40; // P1.6 output (green LED)
P1OUT = 0; // LED off
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL1 |= DIVA_0; // ACLK = VLO
BCSCTL2 |= SELM_0 + DIVM_0 + DIVS_0; // MCLK = DCO, SMCLK = DCO // Configure TimerA
TACTL = TASSEL1 +MC_1; // Source: ACLK, UP mode
CCR0 = 5000; //Timer count 5100
CCR1 = 2500; //Timer count 100
CCTL0 = CCIE; //CCR0 interrupt enabled
CCTL1 = CCIE; //CCR1 interrupt enabled
_BIS_SR(GIE);
for(;;);
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{ P1OUT |= BIT6; // P1.6 output High
if(i==199)
{ i=0; }
else
{ i++; }
if(temp==4999)
{ CCR1=4998; }
else
{ CCR1=temp; }
}
// Timer A1 Interrupt Vector (TA0IV) handler
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1(void)
{
switch( TA0IV )
{
case 2: P1OUT &= ~BIT6; // P1.6 output Low
break;
case 10:
break;
}
}
|
|