Exemplo n.º 1
0
/*
 *  ======== CSL_init =========
 *  Initialize all configured CSL peripherals
 */
void CSL_init(void)
{
    /* Stop watchdog timer from timing out during initial start-up. */
    WDTCTL = WDTPW + WDTHOLD;

    /* initialize Config for the MSP430 GPIO */
    GPIO_init();

    /* initialize Config for the MSP430 2xx family clock systems (BCS) */
    BCSplus_init();

    /* initialize Config for the MSP430 10-bit Analog to Digital Converter (ADC) */
    ADC10_init();

    /* initialize Config for the MSP430 USCI_A0 */
    USCI_A0_init();

    /* initialize Config for the MSP430 A3 Timer0 */
    Timer0_A3_init();

    /* initialize Config for the MSP430 System Registers */
    System_init();

    /* initialize Config for the MSP430 A3 Timer0 */
    Timer1_A3_init();

    /* initialize Config for the MSP430 WDT+ */
    WDTplus_init();

}
Exemplo n.º 2
0
void main()
{
	WDTCTL=WDTPW+WDTHOLD;
	ADC10_init();
	LCD_Init();
    while(1)
    {
      ADC10CTL0 |= ENC + ADC10SC;            // Sampling and conversion start
 //     _bis_SR_register(CPUOFF + GIE);       	 // LPM0 with interrupts enabled
      __delay_cycles(1000);
      //-----ADC转换完成中断唤醒CPU后才执行以下代码-----
      temp = ADC10MEM;							//读取AD采样值
      IntDeg= temp*4225/1024 - 2777;		//转换为摄氏度,并10倍处理
 //  IntDeg=-123;									//由于难以获得负温,直接给负值以测试LCD显示
      LCD_Display();										//调用LCD显示函数
    }
}
void main (void)
{
	unsigned int ADC_Result[64];
	volatile unsigned int ADC_Result_Average;
    unsigned char i;
    unsigned int ADC_Result_sum;

    //Stop Watchdog Timer
    WDT_hold(__MSP430_BASEADDRESS_WDT_A__);

    //Initialize the ADC10 Module
    /*
     * Base Address for the ADC10 Module
     * Use internal ADC10 bit as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    ADC10_init(__MSP430_BASEADDRESS_ADC10_A__,
        ADC10_SAMPLEHOLDSOURCE_SC,
        ADC10_CLOCKSOURCE_ADC10OSC,
        ADC10_CLOCKDIVIDER_1);
    
    ADC10_enable(__MSP430_BASEADDRESS_ADC10_A__);
    
    /*
     * Base Address for the ADC10 Module
     * Sample/hold for 16 clock cycles
     * Enable Multiple Sampling
     */
    ADC10_setupSamplingTimer(__MSP430_BASEADDRESS_ADC10_A__,
        ADC10_CYCLEHOLD_16_CYCLES,
        ADC10_MULTIPLESAMPLESENABLE);

    //Configure Memory Buffer
    /*
     * Base Address for the ADC10 Module
     * Use input A1
     * Use positive reference of AVcc
     * Use negative reference of AVss
     */
    ADC10_memoryConfigure(__MSP430_BASEADDRESS_ADC10_A__,
        ADC10_INPUT_A1,
        ADC10_VREFPOS_AVCC,
        ADC10_VREFNEG_AVSS);

    //Initialize and Setup DMA Channel 0
    /*
     * Base Address for the DMA Module
     * Configure DMA channel 0
     * Configure channel for repeated single transfer
     * DMA interrupt flag will be set after every 64 transfers
     * Use DMA Trigger Source 24 (ADC10IFG)
     * Transfer Word-to-Word
     * Trigger upon Rising Edge of Trigger Source Signal
     */
    DMA_init(__MSP430_BASEADDRESS_DMAX_3__,
        DMA_CHANNEL_0,
        DMA_TRANSFER_REPEATED_SINGLE,
        64,
        DMA_TRIGGERSOURCE_24,
        DMA_SIZE_SRCWORD_DSTWORD,
        DMA_TRIGGER_RISINGEDGE);
    /*
     * Base Address for the DMA Module
     * Configure DMA channel 0
     * Use ADC10 Memory Buffer as source
     * Increment destination address after every transfer
     */
    DMA_setSrcAddress(__MSP430_BASEADDRESS_DMAX_3__,
        DMA_CHANNEL_0,
        ADC10_getMemoryAddressForDMA(__MSP430_BASEADDRESS_ADC10_A__),
        DMA_DIRECTION_UNCHANGED);
    /*
     * Base Address for the DMA Module
     * Configure DMA channel 0
     * Use ADC_Result[0] as destination
     * Increment destination address after every transfer
     */
    DMA_setDstAddress(__MSP430_BASEADDRESS_DMAX_3__,
        DMA_CHANNEL_0,
        (unsigned long)&ADC_Result[0],
        DMA_DIRECTION_INCREMENT);

    //Enable DMA channel 0 interrupt
    DMA_enableInterrupt(__MSP430_BASEADDRESS_DMAX_3__,
        DMA_CHANNEL_0);

    //Enable transfers on DMA channel 0
    DMA_enableTransfers(__MSP430_BASEADDRESS_DMAX_3__,
        DMA_CHANNEL_0);

    while (1)
    {
        //Enable and Start the conversion
        //in Repeated Single-Channel Conversion Mode
        ADC10_startConversion(__MSP430_BASEADDRESS_ADC10_A__,
            ADC10_REPEATED_SINGLECHANNEL);

        __bis_SR_register(CPUOFF + GIE);        //LPM0, ADC10_ISR will force exit
        __no_operation();                       //For debug only

        //Clear accumulate register
        ADC_Result_sum = 0x0;
        for (i = 0; i < 64; i++){
            ADC_Result_sum += ADC_Result[i];
        }

        //Average of 64 conversions results
        ADC_Result_Average = ADC_Result_sum >> 6;

        //SET BREAKPOINT HERE to be able to watch ADC_Result_Average
        //Delay before next 64 conversions
        __delay_cycles(50000);
    }
}