ButterflyMP3
|
00001 //*************************************************************************** 00002 // 00003 // File........: ADC.c 00004 // 00005 // Author(s)...: ATMEL Norway 00006 // 00007 // Target(s)...: ATmega169 00008 // 00009 // Compiler....: AVR-GCC 3.3.1; avr-libc 1.2 00010 // 00011 // Description.: AVR Butterfly ADC routines 00012 // 00013 // Revisions...: 1.0 00014 // 00015 // YYYYMMDD - VER. - COMMENT - SIGN. 00016 // 00017 // 20030116 - 1.0 - Created - LHM 00018 // 20031009 port to avr-gcc/avr-libc - M.Thomas 00019 // 20050610 modified for VUW datalogger use - N.Lott 00020 // 00021 //*************************************************************************** 00022 00023 //mtA 00024 //#include <inavr.h> 00025 //#include "iom169.h" 00026 #include <avr/io.h> 00027 #include <avr/pgmspace.h> 00028 #include "pgmspacehlp.h" 00029 00030 //mtE 00031 00032 #include "main.h" 00033 #include "ADC.h" 00034 #include "BCD.h" 00035 #include "LCD_functions.h" 00036 #include "types.h" 00037 //#include "timer0.h" 00038 #include "uart.h" 00039 //#include "speed.h" 00040 //MP3 Player #include "dataflash.h" 00041 00042 #define Log2Flash 1 00043 00044 // mt __flash int TEMP_Celcius_pos[] = // Positive Celcius temperatures (ADC-value) 00045 const int TEMP_Celcius_pos[] PROGMEM = // Positive Celcius temperatures (ADC-value) 00046 { // from 0 to 60 degrees 00047 806,796,786,775,765,754,743,732,720,709,697,685,673,661,649, 00048 636,624,611,599,586,574,562,549,537,524,512,500,488,476,464, 00049 452,440,429,418,406,396,385,374,364,354,344,334,324,315,306, 00050 297,288,279,271,263,255,247,240,233,225,219,212,205,199,193, 00051 187, 00052 }; 00053 00054 // mt __flash int TEMP_Celcius_neg[] = // Negative Celcius temperatures (ADC-value) 00055 const int TEMP_Celcius_neg[] PROGMEM = // Negative Celcius temperatures (ADC-value) 00056 { // from -1 to -15 degrees 00057 815,825,834,843,851,860,868,876,883,891,898,904,911,917,923, 00058 }; 00059 /* Removed for space - NAL 00060 // mt __flash int TEMP_Farenheit_pos[] = // Positive Farenheit temperatures (ADC-value) 00061 const int TEMP_Fahrenheit_pos[] PROGMEM = // Positive Fahrenheit temperatures (ADC-value) 00062 { // from 0 to 140 degrees 00063 938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902, 898, 00064 894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851, 847, 842, 00065 837, 832, 827, 822, 816, 811, 806, 800, 795, 789, 783, 778, 772, 00066 766, 760, 754, 748, 742, 735, 729, 723, 716, 710, 703, 697, 690, 00067 684, 677, 670, 663, 657, 650, 643, 636, 629, 622, 616, 609, 602, 00068 595, 588, 581, 574, 567, 560, 553, 546, 539, 533, 526, 519, 512, 00069 505, 498, 492, 485, 478, 472, 465, 459, 452, 446, 439, 433, 426, 00070 420, 414, 408, 402, 396, 390, 384, 378, 372, 366, 360, 355, 349, 00071 344, 338, 333, 327, 322, 317, 312, 307, 302, 297, 292, 287, 282, 00072 277, 273, 268, 264, 259, 255, 251, 246, 242, 238, 234, 230, 226, 00073 222, 219, 215, 211, 207, 204, 200, 197, 194, 190, 187, 00074 }; 00075 */ 00076 /* 00077 // mt __flash int LIGHT_ADC[] = // Table used to find the Vref, when using the voltage-reading function 00078 const int LIGHT_ADC[] PROGMEM = // Table used to find the Vref, when using the voltage-reading function 00079 { 00080 0x35,0x60,0x80,0x0B0,0x11D,0x13D,0x15A,0x17A,0x197,0x1B9,0x1DA, 00081 0x1F9,0x216,0x240,0x26D,0x282,0x2A2,0x2EF,0x332,0x3B0,0x3F2 00082 }; 00083 */ 00084 /* 00085 //mt __flash float LIGHT_VOLTAGE[] = // Vref table correspondent to the LIGHT_ADC[] table 00086 const float LIGHT_VOLTAGE[] PROGMEM = // Vref table correspondent to the LIGHT_ADC[] table 00087 { 00088 2.818,2.820,2.824,2.827,2.832,2.835,2.839,2.841,2.843,2.847,2.850, 00089 2.853,2.857,2.863,2.867,2.870,2.874,2.882,2.893,2.917,2.939 00090 }; 00091 00092 */ 00093 float Vref = 2.900; // initial value 00094 char degree = CELCIUS; // char degree = CELCIUS; 00095 00096 //MP3 Player extern char gLogging; 00097 //MP3 Player extern char gLogNow; 00098 //MP3 Player int gMaxTemp=1023; 00099 //MP3 Player int gMinTemp=0; 00100 00101 /***************************************************************************** 00102 * 00103 * Function name : ADC_init 00104 * 00105 * Returns : None 00106 * 00107 * Parameters : char input 00108 * 00109 * Purpose : Initialize the ADC with the selected ADC-channel 00110 * 00111 *****************************************************************************/ 00112 void ADC_init(char input) 00113 { 00114 00115 // todo : change to internal bandgap referencec when input = voltage. 00116 // if (input == VOLTAGE_SENSOR){ 00117 // // disable the VCP (VC-peripheral) 00118 // PORTF &= ~(1<<PF3); // mt sbi(PORTF, PORTF3); // Enable 00119 // DDRF &= ~(1<<DDF3); 00120 // ADMUX = VOLTAGE_SENSOR|(1<<REFS0)|(1<<REFS1); // select internal bandgap reference see VOLTAGE_SENSOR definition 00121 // Vref = 3.0; 00122 // }else{ 00123 // !!!:nick:20051120 00124 PORTF |= (1<<PF3); // mt sbi(PORTF, PORTF3); // Enable the VCP (VC-peripheral) 00125 DDRF|= (1<<DDF3); // sbi(DDRF, PORTF3); 00126 ADMUX = input; // external AREF and ADCx 00127 Vref = 2.900; 00128 // } 00129 ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0); // set ADC prescaler to , 1MHz / 8 = 125kHz 00130 //MP3 PLayer : note above line has timing 8 x faster. 00131 input = ADC_read(); // dummy 00132 } 00133 00134 00135 /***************************************************************************** 00136 * 00137 * Function name : ADC_read 00138 * 00139 * Returns : int ADC 00140 * 00141 * Parameters : None 00142 * 00143 * Purpose : Do a Analog to Digital Conversion 00144 * 00145 *****************************************************************************/ 00146 int ADC_read(void) 00147 { 00148 char i; 00149 int ADC_temp; 00150 // mt int ADC = 0 ; 00151 int ADCr = 0; 00152 00153 // To save power, the voltage over the LDR and the NTC is turned off when not used 00154 // This is done by controlling the voltage from a I/O-pin (PORTF3) 00155 /* 00156 CBI(PORTD, PF4); // Set internal pullup 00157 CBI(DDRF, DDF4 00158 */ 00159 PORTF &= ~(1<<PF4); 00160 DDRF &= ~(1<<DDF4); 00161 /* 00162 SBI(PORTF, PF3); // mt sbi(PORTF, PORTF3); // Enable the VCP (VC-peripheral) 00163 SBI(DDRF, DDF3); // sbi(DDRF, PORTF3); 00164 */ 00165 00166 PORTF |=(1<<PF3); 00167 DDRF |= (1<<DDF3); 00168 00169 ADCSRA |= (1<<ADEN); 00170 00171 //SBI(ADCSRA, ADEN); // Enable the ADC 00172 00173 //do a dummy readout first 00174 ADCSRA |= (1<<ADSC); // do single conversion 00175 while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active 00176 00177 for(i=0;i<8;i++) // do the ADC conversion 8 times for better accuracy 00178 { 00179 ADCSRA |= (1<<ADSC); // do single conversion 00180 while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active 00181 00182 ADC_temp = ADCL; // read out ADCL register 00183 ADC_temp += (ADCH << 8); // read out ADCH register 00184 00185 ADCr += ADC_temp; // accumulate result (8 samples) for later averaging 00186 } 00187 00188 ADCr = ADCr >> 3; // average the 8 samples 00189 /* 00190 CBI(PORTF,PF3); // mt CBI(PORTF, PORTF3); // disable the VCP 00191 CBI(DDRF,DDF3); // mt CBI(DDRF, PORTF3); 00192 00193 CBI(PORTF,PF6); //disable VCP 00194 CBI(DDRF,DDF6); 00195 CBI(PORTF,PF4); //disable the internal Pullup. 00196 CBI(DDRF,DDF4); 00197 */ 00198 // PORTF &= ~(1<<PF3)|(1<<PF4)|(1<<PF6); 00199 DDRF &= ~(1<<DDF3)|(1<<DDF4)|(1<<DDF6); 00200 00201 00202 //CBI(ADCSRA, ADEN); // disable the ADC 00203 ADCSRA &= ~(1<<ADEN); 00204 return ADCr; 00205 } 00206 00207 00208 /***************************************************************************** 00209 * 00210 * Function name : ADC_periphery 00211 * 00212 * Returns : None 00213 * 00214 * Parameters : None 00215 * 00216 * Purpose : Calculates the Temperature/Voltage/Ligth from the ADC_read 00217 * and puts it out on the LCD. 00218 * 00219 *****************************************************************************/ 00220 //void ADC_periphery(void) 00221 //{ 00222 // int ADCresult = 0; 00223 // 00224 // if (!gLogNow) { // don't read while lig in process 00225 // ADCresult=ADC_read(); // read ADC Value 00226 // 00227 // switch ((ADMUX & 7)){ 00228 // case TEMPERATURE_SENSOR: 00229 // ADC2Temp(FALSE,ADCresult); 00230 // break; 00231 // case DIR_SENSOR : 00232 // ADC2Direction(FALSE,ADCresult); 00233 // break; 00234 // case VOLTAGE_SENSOR: 00235 // ADC2Volt(FALSE,ADCresult); 00236 // break; 00237 // case LIGHT_SENSOR: 00238 // ADC2Light(FALSE,ADCresult); 00239 // } 00240 // } 00241 // 00242 //} 00243 00244 /***************************************************************************** 00245 * 00246 * Function name : ADC2Temp 00247 * 00248 * Returns : nothing 00249 * 00250 * Parameters : char log (char to log to rs232 else print to screen) 00251 * int ADCResult (ADC reading to convert) 00252 * 00253 * Purpose : Convert an ADC reading into a temp 00254 * 00255 *****************************************************************************/ 00256 void ADC2Temp(char log,int ADCresult) 00257 { 00258 // int ADCresult = 0; 00259 // int ADCresult_temp = 0; 00260 int Temp_int=0; 00261 int dif; 00262 int top; 00263 00264 char Temp; 00265 unsigned char i = 0; 00266 char TL; 00267 char TH; 00268 char VH; 00269 char VL; 00270 00271 // if (ADCresult<gMaxTemp) // these appear backwards (the gt and lt) due to NTC of thermister 00272 // gMaxTemp=ADCresult; 00273 // if (ADCresult>gMinTemp) 00274 // gMinTemp=ADCresult; 00275 00276 /* if (gTempOffset) 00277 { 00278 ADCresult = ADCresult -gTempOffset; 00279 } 00280 */ 00281 if(degree == CELCIUS){ 00282 if(ADCresult > 810){ // If it's a negtive temperature 00283 for (i=0; i<=25; i++){ // Find the temperature 00284 if (ADCresult <= pgm_read_word(&TEMP_Celcius_neg[i])){ 00285 // add a decimal reading 00286 if (i>0){ 00287 dif= pgm_read_word(&TEMP_Celcius_neg[i])-pgm_read_word(&TEMP_Celcius_neg[i-1]); 00288 top =(ADCresult-pgm_read_word(TEMP_Celcius_neg[i-1]))*100; 00289 00290 Temp_int = top/(dif+1); 00291 i++; 00292 } 00293 break; 00294 } 00295 } 00296 00297 //LCD_putc(0, '-'); // Put a minus sign in front of the temperature 00298 } 00299 else if (ADCresult < 800){ // If it's a positive temperature 00300 for (i=0; i<100; i++) { 00301 if (ADCresult >= pgm_read_word(&TEMP_Celcius_pos[i])){ 00302 // add a decimal reading 00303 if (i>0){ 00304 dif= pgm_read_word(&TEMP_Celcius_pos[i-1])-pgm_read_word(&TEMP_Celcius_pos[i]); 00305 top =(pgm_read_word(&TEMP_Celcius_pos[i-1])-ADCresult)*100; 00306 00307 Temp_int = top/(dif+1); 00308 i--; 00309 } 00310 break; 00311 } 00312 } 00313 //LCD_putc(0, '+'); // Put a plus sign in front of the temperature 00314 } else{ //If the temperature is zero degrees 00315 i = 0; 00316 LCD_putc(0, ' '); 00317 } 00318 00319 Temp = CHAR2BCD2(i); // Convert from char to bin 00320 TL = (Temp & 0x0F) + '0'; // Find the low-byte 00321 TH = (Temp >> 4) + '0'; // Find the high-byte 00322 00323 Temp= CHAR2BCD2(Temp_int); 00324 VH = (Temp >> 4) + '0'; 00325 VL = (Temp & 0x0F) + '0'; 00326 00327 if(log) { 00328 /* Usart_Tx(TH); 00329 Usart_Tx(TL); 00330 Usart_Tx('.'); 00331 Usart_Tx(VH); 00332 Usart_Tx(VL); 00333 Usart_Tx(' '); 00334 */ 00335 // #ifdef Log2Flash 00336 // DF_SPI_RW(TH); 00337 // DF_SPI_RW(TL); 00338 // DF_SPI_RW('.'); 00339 // DF_SPI_RW(VH); 00340 // DF_SPI_RW(VL); 00341 // DF_SPI_RW(' '); 00342 // #endif 00343 } else { 00344 LCD_putc(0, TH); 00345 LCD_putc(1, TL); 00346 LCD_putc(2, VH); 00347 LCD_putc(3, VL); 00348 LCD_putc(4, '*'); 00349 LCD_putc(5, 'C'); 00350 LCD_Colon(TRUE); 00351 LCD_putc(6, '\0'); 00352 } 00353 00354 } 00355 /* 00356 else if (degree == FARENHEIT) 00357 { 00358 for (i=0; i<=141; i++) // Find the temperature 00359 { 00360 if (ADCresult > pgm_read_word(TEMP_Farenheit_pos[i])) 00361 { 00362 break; 00363 } 00364 } 00365 00366 Temp_int = CHAR2BCD3(i); 00367 00368 if (i > 99) // if there are three digits 00369 { 00370 LCD_putc(0, '+'); 00371 TH = (Temp_int >> 8) + '0'; // Find the high-byte 00372 LCD_putc(1, TH); 00373 } 00374 else // if only two digits 00375 { 00376 LCD_putc(0, ' '); 00377 LCD_putc(1, '+'); 00378 } 00379 00380 TL = (Temp_int & 0x0F) + '0'; // Find the low-byte 00381 TH = ( (Temp_int >> 4) & 0x0F ) + '0'; // Find the high-byte 00382 00383 LCD_putc(2, TH); 00384 LCD_putc(3, TL); 00385 LCD_putc(4, '*'); 00386 LCD_putc(5, 'F'); 00387 LCD_putc(6, '\0'); 00388 LCD_Colon(FALSE); 00389 00390 } 00391 */ 00392 } 00393 00394 00395 /***************************************************************************** 00396 * 00397 * Function name : ADC2Direction 00398 * 00399 * Returns : nothing 00400 * 00401 * Parameters : char log (char to log to flash else print to screen) 00402 * int ADCResult (ADC reading to convert) 00403 * 00404 * Purpose : Convert an ADC reading into a Direction Reading 00405 * 00406 *****************************************************************************/ 00407 //void ADC2Direction(char log, int ADCresult) 00408 //{ 00409 // // int Temp_int; 00410 // int Temp; 00411 // char TL; 00412 // char TH; 00413 // char THH; 00414 // 00415 // Temp = CHAR2BCD3((ADCL+(ADCH<<8))); 00416 // 00417 // TL = (Temp & 0x0F) + '0'; 00418 // if(TL > '9') // if the hex-value is over 9, add 7 in order to go 00419 // TL += 7; // jump to the character in the ASCII-table 00420 // 00421 // TH = ((Temp >>= 4)& 0x0F) + '0'; 00422 // if(TH > '9') // if the hex-value is over 9, add 7 in order to go 00423 // TH += 7; // jump to the character in the ASCII-table 00424 // 00425 // THH = ((Temp >>= 4)& 0x0F) + '0'; 00426 // if(THH > '9') // if the hex-value is over 9, add 7 in order to go 00427 // THH += 7; // jump to the character in the ASCII-table 00428 // 00429 // if (log) 00430 // { 00431 // /* Usart_Tx((ADCH + 0x30)); 00432 // Usart_Tx(TH); 00433 // Usart_Tx(TL); 00434 // Usart_Tx(' '); */ 00435 //#ifdef Log2Flash 00436 // DF_SPI_RW(THH); 00437 // DF_SPI_RW(TH); 00438 // DF_SPI_RW(TL); 00439 // DF_SPI_RW(' '); 00440 //#endif 00441 // 00442 // }else 00443 // { 00444 // LCD_putc(0, 'D'); 00445 // LCD_putc(1, 'I'); 00446 // LCD_putc(2, 'R'); 00447 // LCD_putc(3, THH); 00448 // LCD_putc(4, TH); 00449 // LCD_putc(5, TL); 00450 // LCD_putc(6, '\0'); 00451 // } 00452 //} 00453 00454 /***************************************************************************** 00455 * 00456 * Function name : ADC2Volt 00457 * 00458 * Returns : nothing 00459 * 00460 * Parameters : char log (char to log to flash else print to screen) 00461 * int ADCResult (ADC reading to convert) 00462 * 00463 * Purpose : Convert an ADC reading into a Voltage 00464 * 00465 *****************************************************************************/ 00466 00467 void ADC2Volt(char log, int ADCresult) 00468 { 00469 // int ADCresult_temp = 0; 00470 char Temp; 00471 00472 char TL; 00473 // char TH; 00474 char VH; 00475 char VL; 00476 00477 float V_ADC; 00478 char VoltageHB; 00479 char VoltageLB; 00480 00481 V_ADC = ( ADCresult * Vref ) / 1024; // Calculate the voltage 00482 00483 V_ADC = ( V_ADC * 6 ); // Multiply by 6 because of the voltage division 00484 00485 VoltageHB = V_ADC; // Store the high-byte 00486 V_ADC = ( V_ADC - VoltageHB ); 00487 VoltageLB = ( V_ADC * 100 ); // Store the low-byte 00488 00489 Temp = CHAR2BCD2(VoltageHB); // Convert from char to bin 00490 00491 TL = (Temp & 0x0F) + '0'; 00492 //TH = (Temp >> 4) + '0'; 00493 00494 Temp = CHAR2BCD2(VoltageLB); // Convert from char to bin 00495 00496 VH = (Temp >> 4) + '0'; 00497 VL = (Temp & 0x0F) + '0'; 00498 if (log) 00499 { 00500 00501 /* Usart_Tx(TL); 00502 Usart_Tx('.'); 00503 Usart_Tx(VH); 00504 Usart_Tx(VL); 00505 Usart_Tx(' '); */ 00506 00507 //#ifdef Log2Flash 00508 // DF_SPI_RW(TL); 00509 // DF_SPI_RW('.'); 00510 // DF_SPI_RW(VH); 00511 // DF_SPI_RW(VL); 00512 // DF_SPI_RW(' '); 00513 //#endif 00514 }else 00515 { 00516 LCD_putc(0, ' '); 00517 LCD_putc(1, ' '); 00518 LCD_putc(2, TL); 00519 LCD_putc(3, 'v'); 00520 LCD_putc(4, VH); 00521 LCD_putc(5, VL); 00522 LCD_putc(6, '\0'); 00523 } 00524 00525 } 00526 /***************************************************************************** 00527 * 00528 * Function name : ADC2Light 00529 * 00530 * Returns : nothing 00531 * 00532 * Parameters : char log (char to log to flash else print to screen) 00533 * int ADCResult (ADC reading to convert) 00534 * 00535 * Purpose : Convert an ADC reading into a Light Reading 00536 * 00537 *****************************************************************************/ 00538 void ADC2Light(char log, int ADCresult) 00539 { 00540 // int Temp_int; 00541 int Temp; 00542 // char i = 0; 00543 char TL; 00544 char TH; 00545 char THH; 00546 /* 00547 // Find Vref 00548 for (i=0; i<=22; i++) 00549 { 00550 if (ADCresult <= LIGHT_ADC[i]) 00551 { 00552 break; 00553 } 00554 } 00555 00556 if(!i) // if it's very bright 00557 Vref = 2.815; 00558 else if(i > 21) 00559 Vref = 2.942; // if it's totally dark 00560 else 00561 Vref = LIGHT_VOLTAGE[i]; 00562 */ 00563 // The relation between ADC-value and lux is yet to be found, 00564 // for now the ADC-value is presented on the LCD 00565 00566 Temp = CHAR2BCD3(1023 - (ADCL+(ADCH<<8))); 00567 00568 TL = (Temp & 0x0F) + '0'; 00569 if(TL > '9') // if the hex-value is over 9, add 7 in order to go 00570 TL += 7; // jump to the character in the ASCII-table 00571 00572 TH = ((Temp >>= 4)& 0x0F) + '0'; 00573 if(TH > '9') // if the hex-value is over 9, add 7 in order to go 00574 TH += 7; // jump to the character in the ASCII-table 00575 00576 THH = ((Temp >>= 4)& 0x0F) + '0'; 00577 if(THH > '9') // if the hex-value is over 9, add 7 in order to go 00578 THH += 7; // jump to the character in the ASCII-table 00579 00580 if (log) 00581 { 00582 /* Usart_Tx((ADCH + 0x30)); 00583 Usart_Tx(TH); 00584 Usart_Tx(TL); 00585 Usart_Tx(' '); */ 00586 //#ifdef Log2Flash 00587 // DF_SPI_RW(THH); 00588 // DF_SPI_RW(TH); 00589 // DF_SPI_RW(TL); 00590 // DF_SPI_RW(' '); 00591 //#endif 00592 00593 }else 00594 { 00595 LCD_putc(0, 'L'); 00596 LCD_putc(1, 'D'); 00597 LCD_putc(2, 'R'); 00598 LCD_putc(3, THH); 00599 LCD_putc(4, TH); 00600 LCD_putc(5, TL); 00601 LCD_putc(6, '\0'); 00602 } 00603 } 00604 00605 00606 /***************************************************************************** 00607 * 00608 * Function name : TemperatureFunc 00609 * 00610 * Returns : char ST_state (to the state-machine) 00611 * 00612 * Parameters : char input (from joystick) 00613 * 00614 * Purpose : Enable or disable temperature measurements 00615 * 00616 *****************************************************************************/ 00617 //char TemperatureFunc(char input) 00618 //{ 00619 // static char enter = 1; 00620 // 00621 // if (enter) 00622 // { 00623 // enter = 0; 00624 // 00625 // ADC_init(TEMPERATURE_SENSOR); // Init the ADC 00626 // 00627 // // Enable auto-run of the ADC_perphery every 10ms 00628 // // (it will actually be more than 10ms cause of the SLEEP) 00629 // Timer0_RegisterCallbackFunction(ADC_periphery); 00630 // } 00631 // else 00632 // LCD_UpdateRequired(TRUE, 0); // New data to be presented 00633 // 00634 // if (input == KEY_PREV) 00635 // { 00636 // // Disable the auto-run of the ADC_periphery 00637 // Timer0_RemoveCallbackFunction(ADC_periphery); 00638 // 00639 // enter = 1; // Set enter to 1 before leaving the TemperatureFunc 00640 // 00641 // return ST_TEMPERATURE; 00642 // }/* 00643 // else if (input == KEY_PLUS) 00644 // { 00645 // if (degree == FAHRENHEIT) 00646 // degree = CELCIUS; 00647 // else 00648 // degree = FAHRENHEIT; 00649 // } 00650 // else if (input == KEY_MINUS) 00651 // { 00652 // if (degree == FAHRENHEIT) 00653 // degree = CELCIUS; 00654 // else 00655 // degree = FAHRENHEIT; 00656 // } 00657 // else if (input == KEY_ENTER) 00658 // { 00659 // if (gTempOffset) 00660 // gTempOffset=0; 00661 // else 00662 // gTempOffset=ADC_read()-806; 00663 // } 00664 // */ 00665 // 00666 // return ST_TEMPERATURE_FUNC; 00667 //} 00668 00669 00670 /***************************************************************************** 00671 * 00672 * Function name : VoltageFunc 00673 * 00674 * Returns : char ST_state (to the state-machine) 00675 * 00676 * Parameters : char input (from joystick) 00677 * 00678 * Purpose : Enable or disable voltage measurements 00679 * 00680 *****************************************************************************/ 00681 //char VoltageFunc(char input) 00682 //{ 00683 // static char enter = 1; 00684 // 00685 // if (enter) 00686 // { 00687 // enter = 0; 00688 // 00689 // ADC_init(VOLTAGE_SENSOR); // Init the ADC 00690 // 00691 // // Enable auto-run of the ADC_perphery every 10ms 00692 // // (it will actually be more than 10ms cause of the SLEEP) 00693 // Timer0_RegisterCallbackFunction(ADC_periphery); 00694 // } 00695 // else 00696 // LCD_UpdateRequired(TRUE, 0); 00697 // 00698 // if (input == KEY_PREV) 00699 // { 00700 // // Disable the auto-run of the ADC_periphery 00701 // Timer0_RemoveCallbackFunction(ADC_periphery); 00702 // 00703 // enter = 1; // Set enter to 1 before leaving the TemperatureFunc 00704 // 00705 // return ST_VOLTAGE; 00706 // } 00707 // else 00708 // return ST_VOLTAGE_FUNC; 00709 //} 00710 00711 00712 00713 /***************************************************************************** 00714 * 00715 * Function name : DirectionFunc 00716 * 00717 * Returns : char ST_state (to the state-machine) 00718 * 00719 * Parameters : char input (from joystick) 00720 * 00721 * Purpose : Enable or disable voltage measurements 00722 * 00723 *****************************************************************************/ 00724 // 00725 //char DirectionFunc(char input) 00726 //{ 00727 // static char enter = 1; 00728 // 00729 // if (enter) 00730 // { 00731 // enter = 0; 00732 // 00733 // ADC_init(DIR_SENSOR); // Init the ADC 00734 // 00735 // // Enable auto-run of the ADC_perphery every 10ms 00736 // // (it will actually be more than 10ms cause of the SLEEP) 00737 // Timer0_RegisterCallbackFunction(ADC_periphery); 00738 // } 00739 // else 00740 // LCD_UpdateRequired(TRUE, 0); 00741 // 00742 // if (input == KEY_PREV) 00743 // { 00744 // // Disable the auto-run of the ADC_periphery 00745 // Timer0_RemoveCallbackFunction(ADC_periphery); 00746 // 00747 // enter = 1; // Set enter to 1 before leaving the TemperatureFunc 00748 // 00749 // return ST_DIR; 00750 // } 00751 // else 00752 // return ST_DIR_FUNC; 00753 //} 00754 00755 00756 /***************************************************************************** 00757 * 00758 * Function name : LightFunc 00759 * 00760 * Returns : char ST_state (to the state-machine) 00761 * 00762 * Parameters : char input (from joystick) 00763 * 00764 * Purpose : Enable or disable light measurements 00765 * 00766 *****************************************************************************/ 00767 //char LightFunc(char input) 00768 //{ 00769 // static char enter = 1; 00770 // 00771 // if (enter) 00772 // { 00773 // 00774 // enter = 0; 00775 // 00776 // ADC_init(LIGHT_SENSOR); // Init the ADC 00777 // 00778 // // Enable auto-run of the ADC_perphery every 10ms 00779 // // (it will actually be more than 10ms cause of the SLEEP) 00780 // Timer0_RegisterCallbackFunction(ADC_periphery); 00781 // } 00782 // else 00783 // LCD_UpdateRequired(TRUE, 0); 00784 // 00785 // if (input == KEY_PREV) 00786 // { 00787 // // Disable the auto-run of the ADC_periphery 00788 // Timer0_RemoveCallbackFunction(ADC_periphery); 00789 // 00790 // enter = 1; // Set enter to 1 before leaving the TemperatureFunc 00791 // 00792 // return ST_LIGHT; 00793 // } 00794 // else 00795 // return ST_LIGHT_FUNC; 00796 //}