亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? adc.c

?? avr Rtos 255 Task avr Rtos 255 Task
?? C
字號:
//***************************************************************************
//
//  File........: ADC.c
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: ATmega169
//
//  Compiler....: IAR EWAAVR 2.28a
//
//  Description.: AVR Butterfly ADC routines
//
//  Revisions...: 1.0
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20030116 - 1.0  - Created                                       - LHM
//
//***************************************************************************

//#include <inavr.h>
//#include "iom169.h"
#include <mega169.h>   
#include "deinclus.h"
#include "main.h"
#include "ADC.h"
#include "BCD.h"
//#include "LCD_functions.h"
//#include "Timer0.h"

__flash int TEMP_Celcius_pos[] =    // Positive Celcius temperatures (ADC-value)
        {                           // from 0 to 60 degrees
            806,796,786,775,765,754,743,732,720,709,697,685,673,661,649,
            636,624,611,599,586,574,562,549,537,524,512,500,488,476,464,
            452,440,429,418,406,396,385,374,364,354,344,334,324,315,306,
            297,288,279,271,263,255,247,240,233,225,219,212,205,199,193,
            187
        };

__flash int TEMP_Celcius_neg[] =    // Negative Celcius temperatures (ADC-value)
        {                           // from -1 to -15 degrees
            815,825,834,843,851,860,868,876,883,891,898,904,911,917,923
        };

__flash int TEMP_Farenheit_pos[] =  // Positive Farenheit temperatures (ADC-value)
        {                           // from 0 to 140 degrees
		    938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902, 898,
    		894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851, 847, 842,
    		837, 832, 827, 822, 816, 811, 806, 800, 795, 789, 783, 778, 772,
    		766, 760, 754, 748, 742, 735, 729, 723, 716, 710, 703, 697, 690,
    		684, 677, 670, 663, 657, 650, 643, 636, 629, 622, 616, 609, 602,
    		595, 588, 581, 574, 567, 560, 553, 546, 539, 533, 526, 519, 512,
    		505, 498, 492, 485, 478, 472, 465, 459, 452, 446, 439, 433, 426,
    		420, 414, 408, 402, 396, 390, 384, 378, 372, 366, 360, 355, 349,
    		344, 338, 333, 327, 322, 317, 312, 307, 302, 297, 292, 287, 282,
    		277, 273, 268, 264, 259, 255, 251, 246, 242, 238, 234, 230, 226,
    		222, 219, 215, 211, 207, 204, 200, 197, 194, 190, 187
        };


__flash int LIGHT_ADC[] = // Table used to find the Vref, when using the voltage-reading function
        {
            0x35,0x60,0x80,0x0B0,0x11D,0x13D,0x15A,0x17A,0x197,0x1B9,0x1DA,
            0x1F9,0x216,0x240,0x26D,0x282,0x2A2,0x2EF,0x332,0x3B0,0x3F2
        };

__flash float LIGHT_VOLTAGE[] = // Vref table correspondent to the LIGHT_ADC[] table
        {
            2.818,2.820,2.824,2.827,2.832,2.835,2.839,2.841,2.843,2.847,2.850,
            2.853,2.857,2.863,2.867,2.870,2.874,2.882,2.893,2.917,2.939
        };


float Vref = 2.900; // initial value
char degree = CELCIUS;


/*****************************************************************************
*
*   Function name : ADC_init
*
*   Returns :       None
*
*   Parameters :    char input
*
*   Purpose :       Initialize the ADC with the selected ADC-channel
*
*****************************************************************************/
void ADC_init(char input)
{

    ADMUX = input;    // external AREF and ADCx

    ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0);    // set ADC prescaler to , 1MHz / 8 = 125kHz

    input = ADC_read();        // dummy
}


/*****************************************************************************
*
*   Function name : ADC_read
*
*   Returns :       int ADC
*
*   Parameters :    None
*
*   Purpose :       Do a Analog to Digital Conversion
*
*****************************************************************************/
int ADC_read(void)
{
    char i;
    int ADC_temp;
    int ADC = 0;

    // To save power, the voltage over the LDR and the NTC is turned off when not used
    // This is done by controlling the voltage from a I/O-pin (PORTF3)

    sbi(PORTF, PORTF3);     // Enable the VCP (VC-peripheral)
    sbi(DDRF, PORTF3);

    sbi(ADCSRA, ADEN);     // Enable the ADC

    //do a dummy readout first
    ADCSRA |= (1<<ADSC);        // do single conversion
    while(!(ADCSRA & 0x10));    // wait for conversion done, ADIF flag active

    for(i=0;i<8;i++)            // do the ADC conversion 8 times for better accuracy
    {
        ADCSRA |= (1<<ADSC);        // do single conversion
        while(!(ADCSRA & 0x10));    // wait for conversion done, ADIF flag active

        ADC_temp = ADCL;            // read out ADCL register
        ADC_temp += ((int)(ADCH) << 8);    // read out ADCH register

        ADC += ADC_temp;      // accumulate result (8 samples) for later averaging
    }

    ADC = ADC >> 3;     // average the 8 samples

    cbi(PORTF, PORTF3);     // disable the VCP
    cbi(DDRF, PORTF3);

    cbi(ADCSRA, ADEN);      // disable the ADC

    return ADC;
}


/*****************************************************************************
*
*   Function name : ADC_periphery
*
*   Returns :       None
*
*   Parameters :    None
*
*   Purpose :       Calculates the Temperature/Voltage/Ligth from the ADC_read
*                   and puts it out on the LCD.
*
*****************************************************************************/
void ADC_periphery(void)
{
    int ADCresult = 0;
    int ADCresult_temp = 0;
    int Temp_int;
    char Temp;
    unsigned char i = 0;
    char TL;
    char TH;
    char VL;

    float V_ADC;
    char VoltageHB;
    char VoltageLB;

    ADCresult = ADC_read();         // Find the ADC value

    if( ADMUX == TEMPERATURE_SENSOR )
    {
        if(degree == CELCIUS)
        {
            if(ADCresult > 810)         // If it's a negtive temperature
            {
                for (i=0; i<=25; i++)   // Find the temperature
                {
                    if (ADCresult <= TEMP_Celcius_neg[i])
                    {
                        break;
                    }
                }

                LCD_WriteDigit ('-',1);       // Put a minus sign in front of the temperature
            }
            else if (ADCresult < 800)   // If it's a positive temperature
            {
                for (i=0; i<100; i++)
                {
                    if (ADCresult >= TEMP_Celcius_pos[i])
                    {
                        break;
                    }
                }

                LCD_WriteDigit ('+',1);      // Put a plus sign in front of the temperature
            }
            else                        //If the temperature is zero degrees
            {
                i = 0;
                LCD_WriteDigit (' ',1);
            }

            Temp = CHAR2BCD2(i);        // Convert from char to bin

            TL = (Temp & 0x0F) + '0';   // Find the low-byte
            TH = (Temp >> 4) + '0';     // Find the high-byte

            LCD_WriteDigit ( ' ',0);
            //LCD character 1 is allready written to
            LCD_WriteDigit ( TH,2);
            LCD_WriteDigit ( TL,3);
            LCD_WriteDigit ( '*',4);
            LCD_WriteDigit ( 'C',5);
            LCD_WriteDigit ( '\0',6);
        }
        else if (degree == FARENHEIT)
        {
            for (i=0; i<=141; i++)   // Find the temperature
            {
                if (ADCresult > TEMP_Farenheit_pos[i])
                {
                    break;
                }
            }

            Temp_int = CHAR2BCD3(i);

            if (i > 99) // if there are three digits
            {
                LCD_WriteDigit ( '+',0);
                TH = (Temp_int >> 8) + '0';   // Find the high-byte
                LCD_WriteDigit ( TH,1);
            }
            else    // if only two digits
            {
                LCD_WriteDigit ( ' ',0);
                LCD_WriteDigit ( '+',1);
            }

            TL = (Temp_int & 0x0F) + '0';   // Find the low-byte
            TH = ( (Temp_int >> 4) & 0x0F ) + '0';     // Find the high-byte

            LCD_WriteDigit ( TH,2);
            LCD_WriteDigit ( TL,3);
            LCD_WriteDigit ( '*',4);
            LCD_WriteDigit ( 'F',5);
            LCD_WriteDigit ( '\0',6);

        }

//        Can't set LCD_UpdateRequired = TRUE here cause we are inside the Timer0 interrupt
//        LCD_UpdateRequired(TRUE, 0);

    }
    /*else if( ADMUX == VOLTAGE_SENSOR )
    {

//  Do a Light-measurement first to determine the Vref,
//  because the LDR affects the Vref

        ADCresult_temp = ADCresult;     // Store the ADCresult from the voltage reading

        ADC_init(LIGHT_SENSOR);         // Init the ADC to measure light

        ADCresult = ADC_read();         // Read the light value

        // Find Vref
        for (i=0; i<=22; i++)
        {
            if (ADCresult <= LIGHT_ADC[i])
            {
                break;
            }
        }
        if(!i)              // if it's very bright
            Vref = 2.815;
        else if(i > 21)
            Vref = 2.942;   // if it's totally dark
        else
            Vref = LIGHT_VOLTAGE[i];

        ADMUX = VOLTAGE_SENSOR;
        ADCresult = ADCresult_temp; // Get the ADCresult from the voltage reading

// Light-measurement finished


        V_ADC = ( ADCresult * Vref ) / 1024; // Calculate the voltage

        V_ADC = ( V_ADC * 6 );      // Multiply by 6 cause of the voltage division

        VoltageHB = V_ADC;              // Store the high-byte
        V_ADC = ( V_ADC - VoltageHB );
        VoltageLB = ( V_ADC * 100 );    // Store the low-byte

        Temp = CHAR2BCD2(VoltageHB);    // Convert from char to bin

        TL = (Temp & 0x0F) + '0';
        TH = (Temp >> 4) + '0';

        Temp = CHAR2BCD2(VoltageLB);    // Convert from char to bin

        VL = (Temp >> 4) + '0';

        LCD_WriteDigit ( ' ',0);
        LCD_putc(1, ' ');
        LCD_putc(2, ' ');
        LCD_putc(3, TL);
        LCD_putc(4, 'V');
        LCD_putc(5, VL);
        LCD_putc(6, '\0');

//        Can't set LCD_UpdateRequired = TRUE here cause we are inside the Timer0 interrupt
//        LCD_UpdateRequired(TRUE, 0);

    }
    else if( ADMUX == LIGHT_SENSOR )
    {
        // The relation between ADC-value and lux is yet to be found,
        // for now the ADC-value is presented on the LCD

        VoltageHB = CHAR2BCD2(ADCH);    // Convert from char to bin

        Temp = ADCL;

        TL = (Temp & 0x0F) + '0';
        if(TL > '9')        // if the hex-value is over 9, add 7 in order to go
            TL += 7;        // jump to the character in the ASCII-table

        TH = (Temp >> 4) + '0';
        if(TH > '9')        // if the hex-value is over 9, add 7 in order to go
            TH += 7;        // jump to the character in the ASCII-table

        LCD_WriteDigit ('A',0);
        LCD_putc(1, 'D');
        LCD_putc(2, 'C');
        LCD_putc(3, (ADCH + 0x30));
        LCD_putc(4, TH);
        LCD_putc(5, TL);
        LCD_putc(6, '\0');

//        Can't set LCD_UpdateRequired = TRUE here cause we are inside the Timer0 interrupt
//        LCD_UpdateRequired(TRUE, 0);

    } */
}


/*****************************************************************************
*
*   Function name : TemperatureFunc
*
*   Returns :       char ST_state (to the state-machine)
*
*   Parameters :    char input (from joystick)
*
*   Purpose :       Enable or disable temperature measurements
*
*****************************************************************************/
/*char TemperatureFunc(char input)
{
    static char enter = 1;

    if (enter)
    {
        enter = 0;

        ADC_init(TEMPERATURE_SENSOR);       // Init the ADC

        // Enable auto-run of the ADC_perphery every 10ms
        // (it will actually be more than 10ms cause of the SLEEP)
        Timer0_RegisterCallbackFunction(ADC_periphery);
    }
    else
        LCD_UpdateRequired(TRUE, 0);        // New data to be presented

    if (input == KEY_PREV)
    {
        // Disable the auto-run of the ADC_periphery
        Timer0_RemoveCallbackFunction(ADC_periphery);

        enter = 1;  // Set enter to 1 before leaving the TemperatureFunc

        return ST_TEMPERATURE;
    }
    else if (input == KEY_PLUS)
    {
        if (degree == FARENHEIT)
            degree = CELCIUS;
        else
            degree = FARENHEIT;
    }
    else if (input == KEY_MINUS)
    {
        if (degree == FARENHEIT)
            degree = CELCIUS;
        else
            degree = FARENHEIT;
    }

    return ST_TEMPERATURE_FUNC;
}
*/

/*****************************************************************************
*
*   Function name : VoltageFunc
*
*   Returns :       char ST_state (to the state-machine)
*
*   Parameters :    char input (from joystick)
*
*   Purpose :       Enable or disable voltage measurements
*
*****************************************************************************/
/*char VoltageFunc(char input)
{
    static char enter = 1;

    if (enter)
    {
        enter = 0;

        ADC_init(VOLTAGE_SENSOR);       // Init the ADC

        // Enable auto-run of the ADC_perphery every 10ms
        // (it will actually be more than 10ms cause of the SLEEP)
        Timer0_RegisterCallbackFunction(ADC_periphery);
    }
    else
        LCD_UpdateRequired(TRUE, 0);

    if (input == KEY_PREV)
    {
        // Disable the auto-run of the ADC_periphery
        Timer0_RemoveCallbackFunction(ADC_periphery);

        enter = 1;  // Set enter to 1 before leaving the TemperatureFunc

        return ST_VOLTAGE;
    }
    else
        return ST_VOLTAGE_FUNC;
}
*/

/*****************************************************************************
*
*   Function name : LightFunc
*
*   Returns :       char ST_state (to the state-machine)
*
*   Parameters :    char input (from joystick)
*
*   Purpose :       Enable or disable light measurements
*
*****************************************************************************/
/*char LightFunc(char input)
{
    static char enter = 1;

    if (enter)
    {

        enter = 0;

        ADC_init(LIGHT_SENSOR);     // Init the ADC

        // Enable auto-run of the ADC_perphery every 10ms
        // (it will actually be more than 10ms cause of the SLEEP)
        Timer0_RegisterCallbackFunction(ADC_periphery);
    }
    else
        LCD_UpdateRequired(TRUE, 0);

    if (input == KEY_PREV)
    {
        // Disable the auto-run of the ADC_periphery
        Timer0_RemoveCallbackFunction(ADC_periphery);

        enter = 1;  // Set enter to 1 before leaving the TemperatureFunc

        return ST_LIGHT;
    }
    else
        return ST_LIGHT_FUNC;
}
*/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久不卡影院| 久久国产精品99精品国产| 午夜精品久久久久久久99水蜜桃| 麻豆精品一区二区三区| 99国产精品国产精品久久| 精品人在线二区三区| 亚洲精品乱码久久久久久久久 | 免费成人av在线播放| 成人午夜免费av| 日韩欧美二区三区| 五月开心婷婷久久| 91国产福利在线| 国产精品二区一区二区aⅴ污介绍| 日韩精品视频网站| 欧美伊人久久久久久午夜久久久久| 国产日韩成人精品| 久久99久久久久| 欧美精品日韩精品| 伊人夜夜躁av伊人久久| 99热这里都是精品| 久久综合久色欧美综合狠狠| 日韩成人午夜精品| 欧美日韩国产影片| 亚洲午夜三级在线| 欧美在线免费观看亚洲| 亚洲狼人国产精品| 91免费看`日韩一区二区| 亚洲国产精品精华液ab| 国产麻豆日韩欧美久久| 欧美v国产在线一区二区三区| 免费久久99精品国产| 日韩片之四级片| 美日韩黄色大片| 亚洲精品一区二区三区99| 麻豆国产精品777777在线| 欧美日韩电影一区| 天天亚洲美女在线视频| 在线播放中文字幕一区| 日本亚洲三级在线| 91精品国产高清一区二区三区 | 《视频一区视频二区| 国产a区久久久| 国产精品久久久久一区| 99精品视频在线观看免费| 国产精品白丝在线| 99国产精品99久久久久久| 一区二区三区中文在线观看| 欧美三级三级三级爽爽爽| 天天色天天爱天天射综合| 欧美大度的电影原声| 国产91综合网| 亚洲人成网站影音先锋播放| 欧美在线三级电影| 老司机午夜精品| 国产精品网站在线播放| 一本大道av伊人久久综合| 天堂成人国产精品一区| 久久免费美女视频| 色综合激情久久| 蜜臀av性久久久久蜜臀av麻豆| 久久精品免视看| 色综合久久久久网| 美女免费视频一区| 国产精品素人一区二区| 欧美亚洲综合网| 精品亚洲成a人在线观看| 亚洲同性gay激情无套| 精品视频一区二区三区免费| 久久精品国产亚洲高清剧情介绍 | 日韩午夜三级在线| 高清成人免费视频| 亚洲1区2区3区视频| 久久嫩草精品久久久精品| 在线看国产日韩| 国产自产视频一区二区三区| 亚洲欧美日本韩国| 精品日韩在线一区| 欧美亚洲国产一区在线观看网站| 精品在线一区二区三区| 夜夜嗨av一区二区三区网页| 亚洲精品在线三区| 欧美日韩在线三级| 成人激情免费视频| 老司机免费视频一区二区三区| 亚洲丝袜精品丝袜在线| 久久精品日韩一区二区三区| 精品视频在线看| 91视视频在线观看入口直接观看www | 国产精品一区二区三区乱码| 亚洲一区二区精品视频| 亚洲国产高清在线| 精品久久人人做人人爱| 欧美日韩高清在线播放| 成人黄色片在线观看| 精品在线观看免费| 日本伊人色综合网| 亚洲精品国产一区二区精华液| 久久久99免费| 日韩欧美在线网站| 91精品在线观看入口| 在线日韩一区二区| av一区二区不卡| 丁香激情综合五月| 国产九色sp调教91| 狠狠色狠狠色合久久伊人| 免费高清在线视频一区·| 亚洲成人午夜电影| 亚洲精品综合在线| 专区另类欧美日韩| 一区二区中文视频| 日韩美女久久久| 综合欧美亚洲日本| 亚洲欧洲日本在线| 亚洲欧洲成人精品av97| 国产精品美女久久久久久久久久久| 精品少妇一区二区三区| 2020日本不卡一区二区视频| 精品国产乱码久久久久久图片| 日韩精品一区二区三区三区免费| 91精品久久久久久蜜臀| 在线不卡一区二区| 日韩一区二区免费在线观看| 欧美一区二区三区啪啪| 日韩欧美中文一区| 久久久久久久综合色一本| 久久久久国产精品人| 国产精品污www在线观看| 亚洲欧洲韩国日本视频| 亚洲资源在线观看| 日韩电影在线观看一区| 国产一区久久久| 国产激情一区二区三区| 91日韩精品一区| 欧美性受xxxx| 日韩你懂的在线播放| 久久久精品国产免大香伊| 一区视频在线播放| 亚洲成人av一区二区| 六月婷婷色综合| 99麻豆久久久国产精品免费优播| 色哟哟欧美精品| 欧美久久一区二区| 久久久国产一区二区三区四区小说| 国产精品国产三级国产aⅴ原创| 亚洲日本一区二区三区| 亚洲福中文字幕伊人影院| 蜜桃视频免费观看一区| 国产sm精品调教视频网站| 日本韩国一区二区三区| 欧美一级欧美一级在线播放| 欧美激情在线看| 亚洲成av人片| 丰满岳乱妇一区二区三区| 欧美亚洲自拍偷拍| 国产午夜精品在线观看| 亚洲一区视频在线| 国产成人av一区二区三区在线观看| 色综合久久88色综合天天免费| 7777精品伊人久久久大香线蕉的 | 国产精品成人在线观看| 偷拍日韩校园综合在线| 成人午夜电影网站| 欧美一区二区三区视频免费| 亚洲丝袜另类动漫二区| 韩国女主播成人在线观看| www.爱久久.com| 欧美成人精品二区三区99精品| 亚洲人成精品久久久久| 国内不卡的二区三区中文字幕 | 国产91精品露脸国语对白| 欧美猛男超大videosgay| 国产喷白浆一区二区三区| 五月婷婷久久综合| 91丨九色丨尤物| 欧美国产日产图区| 久久97超碰色| 91精品视频网| 亚洲人xxxx| k8久久久一区二区三区| 久久免费午夜影院| 久久国产尿小便嘘嘘| 欧美日韩一二三| 亚洲综合色成人| 99精品久久只有精品| 国产欧美综合在线| 国产美女娇喘av呻吟久久| 91 com成人网| 性做久久久久久免费观看欧美| 波多野结衣欧美| 国产欧美精品在线观看| 国产精品一品二品| 精品免费一区二区三区| 日韩福利电影在线观看| 欧美日韩不卡视频| 一区二区国产盗摄色噜噜| 99视频国产精品| 亚洲美女屁股眼交| 91免费视频观看| 亚洲欧美视频在线观看| 91麻豆国产自产在线观看|