Go to the documentation of this file.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 #ifndef ADC_DRV_H
00045 #define ADC_DRV_H
00046
00047
00048
00049 #ifndef ADHSM
00050 #define ADHSM 7
00051 #endif
00052
00056
00057
00058 #define ADC_ADC1_ADC0_x200 0x0B
00059 #define ADC_ADC1_ADC0_x10 0x09
00060 #define ADC_ADC1_ADC0_x40 0x26
00061 #define ADC_TEMP_SENSOR_CHANNEL 0x27
00062 #define ADC_GND_CHANNEL 0x1F
00063 #define ADC_BG_CHANNEL 0x1E
00064
00068
00072 #define Enable_adc() (ADCSRA |= (1<<ADEN))
00073
00074
00078 #define Right_adjust_adc_result() (ADMUX &= ~(1<<ADLAR))
00079 #define Left_adjust_adc_result() (ADMUX |= (1<<ADLAR))
00080
00081
00085 #define Enable_adc_high_speed_mode() (ADCSRB |= (1<<ADHSM))
00086 #define Disable_adc_high_speed_mode() (ADCSRB &= ~(1<<ADHSM))
00087
00088
00089
00093 #define Enable_internal_vref() (ADMUX |= ((1<<REFS1)|(1<<REFS0)) )
00094 #define Enable_external_vref() (ADMUX &= ~((1<<REFS1)|(1<<REFS0)) )
00095 #define Enable_vcc_vref() (ADMUX &= ~(1<<REFS1), \
00096 ADMUX |= (1<<REFS0) )
00097
00098
00102 #define Enable_all_it() (SREG |= (0x80) )
00103 #define Disable_all_it() (SREG &= ~(0x80) )
00104 #define Enable_adc_it() (ADCSRA |= (1<<ADIE) )
00105 #define Disable_adc_it() (ADCSRA &= ~(1<<ADIE) )
00106 #define Clear_adc_flag() (ADCSRA |= (1<<ADIF) )
00107
00108
00112 #define Set_adc_prescaler(prescaler) (ADCSRA &= ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)),\
00113 ADCSRA |= (prescaler) )
00114
00115
00119 #define MUX4_0_MSK ((1<<MUX4)|(1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0))
00120 #define Clear_adc_mux() ADMUX &= ~(MUX4_0_MSK),(ADCSRB &= ~(1<<MUX5))
00121 #define Select_adc_channel(channel) (Clear_adc_mux(), ADCSRB |= (channel>>5)<<MUX5, ADMUX |= (channel&MUX4_0_MSK))
00122
00123
00127
00131 #define Start_conv() (ADCSRA |= (1<<ADSC) )
00132 #define Start_conv_channel(channel) (Select_adc_channel(channel), Start_conv() )
00133
00134
00138 #define Start_conv_idle() (SMCR |= (1<<SM0)|(1<<SE) )
00139 #define Start_conv_idle_channel(channel) (Select_adc_channel(channel), Start_conv_idle() )
00140 #define Clear_sleep_mode() (SMCR &= ~(1<<SM0)|(1<<SE) )
00141
00142
00144
00148 #define Adc_get_8_bits_result() ((U8)(ADCH))
00149 #define Adc_get_10_bits_result() ((U16)(ADCL+((U16)(ADCH<<8))))
00150
00151
00152
00156 #define Disable_adc() (ADCSRA &= ~(1<<ADEN))
00157
00158
00162 #define Is_adc_conv_finished() ((ADCSRA & (1<<ADIF)) ? TRUE : FALSE)
00163 #define Is_adc_conv_not_finished() ((ADCSRA | ~(1<<ADIF)) ? TRUE : FALSE)
00164
00165
00167
00168
00169
00170
00174
00179 void init_adc(void);
00181
00182
00184
00185 #endif // ADC_DRV_H