⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.c

📁 butterflylogger_src_20060822 for atmel avr
💻 C
📖 第 1 页 / 共 2 页
字号:
    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(THH);		USART_Tx(TH);		USART_Tx(TL);		USART_Tx(' ');        }else    {		LCD_putc(0, sensor+'T');		// print x,y or z 		LCD_putc(1, ' ');		LCD_putc(2, ' ');		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 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';        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);      }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 : ADC2RAW**   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 ADC2RAW(char log, unsigned int ADCresult){    //  int Temp_int;    int Temp;    //    char i = 0;    char TL;    char TH;     char THH;        Temp = CHAR2BCD3(ADCresult);                        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)    {		if (THH>'9'){ // adjust to print 10 rather than A			USART_Tx('1');			THH = '0';		}		USART_Tx(THH);		USART_Tx(TH);		USART_Tx(TL);            }else    {		LCD_putc(0, 'A');		LCD_putc(1, 'D');		LCD_putc(2, 'C');		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;    }        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;    static unsigned char sensor=0;    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_PLUS){		if (sensor<(DIRECTION_ADCS-1)){			sensor++;			ADC_init(DIR_SENSOR+sensor);       // Init the ADC		}	}		if (input == KEY_MINUS){		if (sensor){			sensor--;			ADC_init(DIR_SENSOR+sensor);       // Init the ADC		}	}        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 + -