- #include <msp430x16x.h>
- //------------------------------------------------------------------------------
- // 12-bit Sine Lookup table with 32 steps
- //------------------------------------------------------------------------------
- static int Sin_tab[32] = { 0x7FF,0xA78,0xCB2,0xE77,0xF9A,0xFFE,0xF9A,0xE77,0xCB2,0xA78,0x7FF,0x586,0x34C,0x187,0x064,0x000
- ,0x064,0x187,0x34C,0x586};
- static int Cos_tab[32] = { 0xFFE,0xF9A,0xE77,0xCB2,0xA78,0x7FF,0x586,0x34C,0x187,0x064,0x000
- ,0x064,0x187,0x34C,0x586,0x7FF,0xA78,0xCB2,0xE77,0xF9A};
-
- void main(void)
- {
- volatile unsigned int i;
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- //==========================选择高频振荡器=======================================
- BCSCTL1 &= ~XT2OFF; // XT2= HF XTAL
- do
- {
- IFG1 &= ~OFIFG; // Clear OSCFault flag
- for (i = 0xFF; i > 0; i--); // Time for flag to set
- }
- while ((IFG1 & OFIFG)); //查看8M的震荡是否稳定 // OSCFault flag still set?
- BCSCTL2 |= SELM_2 + SELS; //MCLK和SMCLK选择XT2// MCLK= SMCLK= XT2 (safe)
- //================================================================================
- ADC12CTL0 = REF2_5V + REFON;//内部基准电压 // Internal 2.5V ref
- //================================================================================
- DMACTL0 = DMA0TSEL_5 + DMA1TSEL_5; // DAC12IFG trigger触发器
- DMA0SA = (int) Sin_tab;//首地址 // Source block address
- DMA0DA = (int)&DAC12_0DAT; //目的地址 // Destination single address
- DMA0SZ = 0x14; //长度 // Block size
- DMA0CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
-
- DMA1SA = (int) Cos_tab; //首地址 // Source block address
- DMA1DA = (int)&DAC12_1DAT; //目的地址 // Destination single address
- DMA1SZ = 0x14; //长度 // Block size
- DMA1CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
-
- DAC12_0CTL = DAC12LSEL_2 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC + DAC12GRP;
- DAC12_1CTL = DAC12LSEL_2 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC;
-
- CCTL1 = OUTMOD_3;//置位复位模式 // CCR1 set/reset
- CCR1 = 1; //设置占空比 // CCR1 PWM Duty Cycle
- CCR0 = 1; //设置周期 // Clock period of CCR0
- TACTL = TASSEL_2 + MC_1; //定时器A的时钟源为SMCLK=8M,增计数模式 // SMCLK, upmode
-
- _BIS_SR(CPUOFF); // CPU off
- }
复制代码 |