evk_527.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of Atmel may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * 4. This software may only be redistributed and used in connection with an Atmel
00030  * AVR product.
00031  *
00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 //_____  I N C L U D E S ___________________________________________________
00045 
00046 #include "config.h"
00047 #include "evk_527.h"
00048 
00049 #ifdef USE_ADC       
00050 #include "lib_mcu/adc/adc_drv.h"
00051 
00052 //_____ M A C R O S ________________________________________________________
00053 
00054 
00055 //_____ P R I V A T E    D E C L A R A T I O N _____________________________
00056 
00057 
00058 //_____ D E F I N I T I O N ________________________________________________
00059 
00066 code U16 temperature_code[]={  0x3B4,0x3B0,0x3AB,0x3A6,0x3A0,0x39A,0x394,0x38E,0x388,0x381,0x37A,0x373,
00067    0x36B,0x363,0x35B,0x353,0x34A,0x341,0x338,0x32F,0x325,0x31B,0x311,0x307,
00068    0x2FC,0x2F1,0x2E6,0x2DB,0x2D0,0x2C4,0x2B8,0x2AC,0x2A0,0x294,0x288,0x27C,
00069    0x26F,0x263,0x256,0x24A,0x23D,0x231,0x225,0x218,0x20C,0x200,0x1F3,0x1E7,
00070    0x1DB,0x1CF,0x1C4,0x1B8,0x1AC,0x1A1,0x196,0x18B,0x180,0x176,0x16B,0x161,
00071    0x157,0x14D,0x144,0x13A,0x131,0x128,0x11F,0x117,0x10F,0x106,0xFE,0xF7,
00072    0xEF,0xE8,0xE1,0xDA,0xD3,0xCD,0xC7,0xC0,0xBA,0xB5,0xAF,0xAA,0xA4,0x9F,
00073    0x9A,0x96,0x91,0x8C,0x88,0x84,0x80,0x7C,0x78,0x74,0x71,0x6D,0x6A,0x67,
00074    0x64,0x61,0x5E,0x5B,0x58,0x55,0x53,0x50,0x4E,0x4C,0x49,0x47,0x45,0x43,
00075    0x41,0x3F,0x3D,0x3C,0x3A,0x38};
00076 
00077 
00078 //_____ D E C L A R A T I O N ______________________________________________
00079 
00080 U16 Get_adc_mic_val(void)
00081 {
00082    Start_conv_channel(ADC_MIC_CH);
00083    while (!Is_adc_conv_finished());
00084    return (U16)(ADCL+((U16)(ADCH<<8)));
00085 }
00086 
00087 
00088 U16 Get_adc_temp_val(void)
00089 {
00090    Start_conv_channel(ADC_TEMP_CH);
00091    while (!Is_adc_conv_finished());
00092    return (U16)(ADCL+((U16)(ADCH<<8)));
00093 }
00094 
00095 S16 Read_temperature(void)
00096 {
00097 #ifndef __GNUC__
00098    U16 adc_code;
00099    S8 index=0;
00100    adc_code=Get_adc_temp_val();
00101    if(adc_code>temperature_code[0])
00102    {
00103       return (S16)(-20);
00104    }
00105    else
00106    {
00107       while(temperature_code[index++]>adc_code);
00108       return (S16)(index-1-20);
00109    }
00110 #else
00111    U16 adc_code;
00112    S8 index=0;
00113    adc_code=Get_adc_temp_val();
00114    if(adc_code>pgm_read_word_near(&temperature_code))
00115    {
00116       return (S16)(-20);
00117    }
00118    else
00119    {
00120       while(pgm_read_word_near(&temperature_code[index++])>adc_code);
00121       return (S16)(index-1-20);
00122    }   
00123 
00124 #endif
00125 }
00126 
00127 #endif // USE_ADC

Generated on Fri Sep 11 15:02:34 2009 for ATMEL by  doxygen 1.5.3