想通过查表的方式用单片机产生一个正弦波信号 通过按键中断调整 但是进不了按键中断 求解
#include
#define _DAC12_0DAT_ 0x01C8 // Physical address of
static int Sin_tab[32] = {
2048,
2447,
2831,
3185,
3495,
3750,
3939,
4056,
4095,
4056,
3939,
3750,
3495,
3185,
2831,
2447,
2048,
1648,
1264,
910,
600,
345,
156,
39,
0,
39,
156,
345,
600,
910,
1264,
1648
};
void key_init(void);
void delay(long int x)
{
long int i;
for(i=0;i
}
void InitSys()
{
unsigned int iq0;
BCSCTL1&=~XT2OFF; //打开XT2振荡器
do
{
IFG1 &= ~OFIFG; // 清除振荡器失效标志
for (iq0 = 0xFF; iq0 > 0; iq0--); // 延时,等待LFXT1起振
}
while ((IFG1 & OFIFG) != 0); // 判断LFXT1是否起振
BCSCTL2 |=SELM_2+SELS; //选择MCLK
}
int main(void)
{
int temp=0;
WDTCTL = WDTPW + WDTHOLD; //Disable the Watchdog
void InitSys();
key_init();
delay(240000);
ADC12CTL0 = REFON; // Internal ref
DMA0SA = (int) Sin_tab; // Source block address
DMA0DA = (unsigned int)&DAC12_0DAT; // Destination single address
DMA0SZ = 0x20; // Block size
DMACTL0 = DMA0TSEL_5; // DAC12IFG trigger
DMA0CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
DAC12_0CTL = DAC12LSEL_2 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC; // Config
CCTL1 = OUTMOD_3; // Set/reset
TACCR1 = 1; // PWM Duty Cycle
TA0CCR0 = 6; // 4M晶振:0x37,8M晶振:0x6f
TA0CCTL0 = CCIE; // TA0CCR0捕获/比较中断寄存器中断使能
_EINT();
}
}
//==============================================================================
void key_init(void)
{
P2DIR &=0xC3; //设置端口为输入
P2IES|=0x30; //下降沿触发
P2IE |=0x30; //P2.4 P2.5允许中断
}
//==============================================================================
#pragma vector =PORT2_VECTOR
__interrupt void Port_2(void)
{ unsigned char q0=0;
if ((P2IFG&BIT5)==BIT5)
{ P2IFG&=0x00;
temp++;
q0=1;
}
else if ((P2IFG&BIT4)==BIT4)
{ P2IFG&=0x00;
temp--;
q0=1;
}
else
{
P2IFG=0;
}
if (q0==1)
{
P2IE=~ 0x00;
}
_DINT();
}