00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "config.h"
00047 #include "usb_key.h"
00048
00049 #if (TARGET_BOARD==USBKEY)
00050
00051 #ifdef USE_ADC
00052 #include "lib_mcu/adc/adc_drv.h"
00053
00054
00055
00056
00057
00058
00059
00060
00061
00068 code U16 temperature_code[]={ 0x3B4,0x3B0,0x3AB,0x3A6,0x3A0,0x39A,0x394,0x38E,0x388,0x381,0x37A,0x373,
00069 0x36B,0x363,0x35B,0x353,0x34A,0x341,0x338,0x32F,0x325,0x31B,0x311,0x307,
00070 0x2FC,0x2F1,0x2E6,0x2DB,0x2D0,0x2C4,0x2B8,0x2AC,0x2A0,0x294,0x288,0x27C,
00071 0x26F,0x263,0x256,0x24A,0x23D,0x231,0x225,0x218,0x20C,0x200,0x1F3,0x1E7,
00072 0x1DB,0x1CF,0x1C4,0x1B8,0x1AC,0x1A1,0x196,0x18B,0x180,0x176,0x16B,0x161,
00073 0x157,0x14D,0x144,0x13A,0x131,0x128,0x11F,0x117,0x10F,0x106,0xFE,0xF7,
00074 0xEF,0xE8,0xE1,0xDA,0xD3,0xCD,0xC7,0xC0,0xBA,0xB5,0xAF,0xAA,0xA4,0x9F,
00075 0x9A,0x96,0x91,0x8C,0x88,0x84,0x80,0x7C,0x78,0x74,0x71,0x6D,0x6A,0x67,
00076 0x64,0x61,0x5E,0x5B,0x58,0x55,0x53,0x50,0x4E,0x4C,0x49,0x47,0x45,0x43,
00077 0x41,0x3F,0x3D,0x3C,0x3A,0x38};
00078
00079
00080
00081
00082 #ifdef __ICCAVR__
00083 #pragma diag_suppress=Pa082
00084 #endif
00085
00086 U16 Get_adc_temp_val(void)
00087 {
00088 Start_conv_channel(ADC_TEMP_CH);
00089 while (!Is_adc_conv_finished());
00090 return Adc_get_10_bits_result();
00091 }
00092
00093 S16 Read_temperature(void)
00094 {
00095 #ifndef __GNUC__
00096 U16 adc_code;
00097 S8 index=0;
00098 adc_code=Get_adc_temp_val();
00099 if(adc_code>temperature_code[0])
00100 {
00101 return (S16)(-20);
00102 }
00103 else
00104 {
00105 while(temperature_code[index++]>adc_code);
00106 return (S16)(index-1-20);
00107 }
00108 #else
00109 U16 adc_code;
00110 S8 index=0;
00111 adc_code=Get_adc_temp_val();
00112 if(adc_code>pgm_read_word_near(&temperature_code))
00113 {
00114 return (S16)(-20);
00115 }
00116 else
00117 {
00118 while(pgm_read_word_near(&temperature_code[index++])>adc_code);
00119 return (S16)(index-1-20);
00120 }
00121
00122 #endif
00123 }
00124
00125 #endif // USE_ADC
00126 #endif // (TARGET_BOARD==USBKEY)