在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            ATMEGA16 多通道AD采集

            作者: 時間:2016-11-13 來源:網(wǎng)絡(luò) 收藏

            本文引用地址:http://www.biyoush.com/article/201611/316564.htm

            //ADEN置位即啟動ADC ,否則ADC功能關(guān)閉。在轉(zhuǎn)換過程中關(guān)閉ADC將立即中止正在進行的轉(zhuǎn)換。同時ADEN清零會將ADIE(AD結(jié)束中斷使能)清除。另外工作在連續(xù)模式下如果沒有對ADEN清零則AD采樣一直運行。

            #include "main.h"

            #define HOT_MUX 4
            #define MIX_MUX 5
            #define POWER_MUX 7
            #define AD_PORT PORTA
            #define AD_DIR DDRA

            //采集次數(shù)
            #define HOT_SAMP_CNT 4
            #define MIX_SAMP_CNT 4
            #define POWER_SAMP_CNT 4

            unsigned char AD_READY = 0;
            volatile unsigned int buf[8];

            volatile unsigned int AD_hot_result = 0;
            volatile unsigned int AD_mix_result = 0;
            volatile unsigned int AD_power_result = 0;

            void ADC_Init(void)
            {
            AD_PORT &= ~(1<AD_DIR &= ~(1< ADMUX = (1<ACSR |= 0x80; //禁止模擬比較器
            SFIOR = 0x00; //連續(xù)轉(zhuǎn)換模式
            ADCSRA = (1<}

            #pragma interrupt_handler ADC_ISR:15
            void ADC_ISR(void)
            {
            unsigned int temp = 0;
            static unsigned int sum = 0;
            static unsigned char cnt = 0;
            static unsigned char AD_status = 0;

            if (cnt == 0) //切換通道時第一個數(shù)據(jù)必須舍棄
            {
            cnt = 1;
            ADCSR|=(1}

            temp = ADCL;
            temp |= (unsigned int)ADCH<<8;
            sum += temp;

            switch(AD_status)
            {
            case 0:

            if (++cnt > HOT_SAMP_CNT)
            {
            AD_status++;
            ADMUX = (1<AD_hot_result = sum / HOT_SAMP_CNT;
            cnt = 0;
            sum = 0;
            }
            break;
            case 1:

            if (++cnt > MIX_SAMP_CNT)
            {
            AD_status++;
            ADMUX = (1<AD_mix_result = sum / MIX_SAMP_CNT;
            cnt = 0;
            sum = 0;
            }
            break;
            case 2: //電源電壓
            if (++cnt > POWER_SAMP_CNT)
            {
            AD_status = 1;
            ADMUX = (1<AD_power_result = sum / POWER_SAMP_CNT;
            cnt = 0;
            sum = 0;
            AD_READY = 1;

            ADCSR &= ~(1}
            break;
            }
            ADCSR|=(1<}

            unsigned int Res_Matrixing_Temper(unsigned int temp)
            {
            float Rt = 0;
            float T_inv = 0;
            float temper = 0;

            Rt = (float)50000*temp/(1024-temp);
            T_inv = log(Rt/50000)/3950 + 1/298.15;
            temper = (1/T_inv -273.15)*10 + 0.5;

            return ((unsigned int)temper);
            }

            void get_AD_result(void)
            {
            unsigned int t1 = 0;
            float T_inv = 0;
            float Rt = 0;
            float temp = 0;
            if (AD_READY == 1)
            {
            AD_READY = 0;

            t1 = Res_Matrixing_Temper(AD_hot_result);

            buf[0] = t1/100;
            buf[1] = t1/10%10;
            buf[2] = t1%10;

            t1 = Res_Matrixing_Temper(AD_mix_result);
            buf[3] = t1/100;
            buf[4] = t1/10%10;
            buf[5] = t1%10;

            }
            }



            關(guān)鍵詞: ATMEGA16多通道AD采

            評論


            技術(shù)專區(qū)

            關(guān)閉