- #include <msp430f6638.h>
- #include <stdint.h>
- #include<stdio.h>
- #include "HAL_PMM.h"
- #include "HAL_UCS.h"
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- void Up_ClockFor_20MHZ(void){
- SetVCore(PMMCOREV_3); // Set Vcore to accomodate for max. allowed system speed
- UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
- UCSCTL4 |= SELA_2; // Set ACLK = REFO
- Init_FLL_Settle(20000, 630); // Set system clock to max (20MHz)
- }
- /*******************************************************************************
- * Function name : init_clk
- * Description : set SMCLK=XT2=4Mhz ACLK=REFO=32.768k
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void init_clk()
- {
- // P3DIR |= BIT4; // SMCLK set out to pins
- // P3SEL |= BIT4;
- P7SEL |= BIT2+BIT3; // Port select XT2
- while(BAKCTL & LOCKIO) // Unlock XT1 pins for operation
- BAKCTL &= ~(LOCKIO);
- UCSCTL6 &= ~XT2OFF; // Enable XT2
- UCSCTL3 |= SELREF_2; // FLLref = REFO
- // Since LFXT1 is not used,
- // sourcing FLL with LFXT1 can cause
- // XT1OFFG flag to set
- UCSCTL4 |= SELA_2; // ACLK=REFO,SMCLK=DCO,MCLK=DCO
- // Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles
- do
- {
- UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
- // Clear XT2,XT1,DCO fault flags
- SFRIFG1 &= ~OFIFG; // Clear fault flags
- }while (SFRIFG1&OFIFG); // Test oscillator fault flag
- UCSCTL6 &= ~XT2DRIVE1; // Decrease XT2 Drive according to
- // expected frequency
- UCSCTL4 |= SELS_5 + SELM_5; // SMCLK=MCLK=XT2 // Loop in place
- }
- void Mic_ad_init()
- {
- P4DIR |= BIT0;
- P4DS |= BIT0;
- P4OUT |= BIT0; //power source
- P6SEL |=BIT5; //P6.5-->A5
- P5DIR |=BIT1; //
- P5OUT&=~BIT1;
- ADC12CTL0 = ADC12ON+ADC12SHT0_5+ADC12MSC;
- ADC12CTL1 = ADC12CSTARTADD_5+ADC12SHP+ADC12SSEL_0+ADC12CONSEQ_2; // Use sampling timer
- ADC12MCTL5 = ADC12INCH_5;
- ADC12CTL0 |= ADC12ENC;
- DAC12_0CTL0 = DAC12IR+DAC12SREF_1 + DAC12AMP_7 + DAC12ENC + DAC12CALON+ DAC12OPS;
- DMACTL0 |= DMA0TSEL3 + DMA0TSEL4;
- __data16_write_addr((unsigned short) &DMA0SA,(unsigned long) 0x072Au);
- __data16_write_addr((unsigned short) &DMA0DA,(unsigned long) 0x0784u);
- DMA0SZ = 1;
- DMA0CTL |= DMADT2 + DMAEN;
- ADC12CTL0 |= ADC12SC;
- _EINT();
- while(1);
- _DINT();
- DMA0CTL &= ~DMAEN;
- ADC12CTL0 &= ~ADC12ENC;
- DAC12_0CTL0 &= DAC12ENC;
- P4OUT &= ~BIT0; //power source
- P4DS &= ~BIT0;
- P4DIR &= ~BIT0;
- P6SEL &= ~BIT5; //P6.5-->A5
- P5OUT |= BIT1;
- P5DIR &= ~BIT1; //
- }
- void main(void)
- {
- WDTCTL = WDTPW+WDTHOLD; // Stop WDT
- SetVCore(PMMCOREV_3);
- init_clk();
- Up_ClockFor_20MHZ();
- Mic_ad_init();
- while(1);
- }
复制代码如何写这个程序流程图?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>