?? adc.c
字號:
** Parameters : char log (char to log to flash else print to screen)* int ADCResult (ADC reading to convert)** Purpose : Convert an ADC reading into a Direction Reading******************************************************************************///void ADC2Direction(char log, int ADCresult)//{// // int Temp_int;// int Temp;// char TL;// char TH; // char THH;// // Temp = CHAR2BCD3((ADCL+(ADCH<<8))); // // 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)& 0x0F) + '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// // THH = ((Temp >>= 4)& 0x0F) + '0';// if(THH > '9') // if the hex-value is over 9, add 7 in order to go // THH += 7; // jump to the character in the ASCII-table// // if (log)// {// /* Usart_Tx((ADCH + 0x30));// Usart_Tx(TH);// Usart_Tx(TL);// Usart_Tx(' '); */ //#ifdef Log2Flash// DF_SPI_RW(THH);// DF_SPI_RW(TH);// DF_SPI_RW(TL);// DF_SPI_RW(' '); //#endif// // }else// {// LCD_putc(0, 'D');// LCD_putc(1, 'I');// LCD_putc(2, 'R');// LCD_putc(3, THH);// LCD_putc(4, TH);// LCD_putc(5, TL);// LCD_putc(6, '\0');// }//}/******************************************************************************* Function name : ADC2Volt** Returns : nothing** Parameters : char log (char to log to flash else print to screen)* int ADCResult (ADC reading to convert)** Purpose : Convert an ADC reading into a Voltage******************************************************************************/void ADC2Volt(char log, int ADCresult){ // int ADCresult_temp = 0; char Temp; char TL; // char TH; char VH; char VL; float V_ADC; char VoltageHB; char VoltageLB; V_ADC = ( ADCresult * Vref ) / 1024; // Calculate the voltage V_ADC = ( V_ADC * 6 ); // Multiply by 6 because 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 VH = (Temp >> 4) + '0'; VL = (Temp & 0x0F) + '0'; if (log) { /* Usart_Tx(TL); Usart_Tx('.'); Usart_Tx(VH); Usart_Tx(VL); Usart_Tx(' '); */ //#ifdef Log2Flash// DF_SPI_RW(TL);// DF_SPI_RW('.');// DF_SPI_RW(VH);// DF_SPI_RW(VL);// DF_SPI_RW(' ');//#endif }else { LCD_putc(0, ' '); LCD_putc(1, ' '); LCD_putc(2, TL); LCD_putc(3, 'v'); LCD_putc(4, VH); LCD_putc(5, VL); LCD_putc(6, '\0'); } }/******************************************************************************* Function name : ADC2Light** Returns : nothing** Parameters : char log (char to log to flash else print to screen)* int ADCResult (ADC reading to convert)** Purpose : Convert an ADC reading into a Light Reading******************************************************************************/void ADC2Light(char log, int ADCresult){ // int Temp_int; int Temp; // char i = 0; char TL; char TH; char THH; /* // 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]; */ // The relation between ADC-value and lux is yet to be found, // for now the ADC-value is presented on the LCD Temp = CHAR2BCD3(1023 - (ADCL+(ADCH<<8))); 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)& 0x0F) + '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 THH = ((Temp >>= 4)& 0x0F) + '0'; if(THH > '9') // if the hex-value is over 9, add 7 in order to go THH += 7; // jump to the character in the ASCII-table if (log) { /* Usart_Tx((ADCH + 0x30)); Usart_Tx(TH); Usart_Tx(TL); Usart_Tx(' '); */ //#ifdef Log2Flash// DF_SPI_RW(THH);// DF_SPI_RW(TH);// DF_SPI_RW(TL);// DF_SPI_RW(' '); //#endif }else { LCD_putc(0, 'L'); LCD_putc(1, 'D'); LCD_putc(2, 'R'); LCD_putc(3, THH); LCD_putc(4, TH); LCD_putc(5, TL); LCD_putc(6, '\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 == FAHRENHEIT)// degree = CELCIUS;// else// degree = FAHRENHEIT;// }// else if (input == KEY_MINUS)// {// if (degree == FAHRENHEIT)// degree = CELCIUS;// else// degree = FAHRENHEIT;// }// else if (input == KEY_ENTER)// {// if (gTempOffset)// gTempOffset=0;// else// gTempOffset=ADC_read()-806;// }// */// // 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 : DirectionFunc** Returns : char ST_state (to the state-machine)** Parameters : char input (from joystick)** Purpose : Enable or disable voltage measurements******************************************************************************/////char DirectionFunc(char input)//{// static char enter = 1;// // if (enter)// {// enter = 0;// // ADC_init(DIR_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_DIR;// }// else// return ST_DIR_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 + -