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 #ifndef ADC_DRV_H
00042 #define ADC_DRV_H
00043
00044
00045
00046 #ifndef ADHSM
00047 #define ADHSM 7
00048 #endif
00049
00053
00054
00058
00062 #define Enable_adc() (ADCSRA |= (1<<ADEN))
00064
00068 #define Right_adjust_adc_result() (ADMUX &= ~(1<<ADLAR))
00069 #define Left_adjust_adc_result() (ADMUX |= (1<<ADLAR))
00071
00075 #define Enable_adc_high_speed_mode() (ADCSRB |= (1<<ADHSM))
00076 #define Disable_adc_high_speed_mode() (ADCSRB &= ~(1<<ADHSM))
00078
00079
00083 #define Enable_internal_vref() (ADMUX |= ((1<<REFS1)|(1<<REFS0)) )
00084 #define Enable_external_vref() (ADMUX &= ~((1<<REFS1)|(1<<REFS0)) )
00085 #define Enable_vcc_vref() (ADMUX &= ~(1<<REFS1), \
00086 ADMUX |= (1<<REFS0) )
00088
00092 #define Enable_all_it() (SREG |= (0x80) )
00093 #define Disable_all_it() (SREG &= ~(0x80) )
00094 #define Enable_adc_it() (ADCSRA |= (1<<ADIE) )
00095 #define Disable_adc_it() (ADCSRA &= ~(1<<ADIE) )
00096 #define Clear_adc_flag() (ADCSRA &= (1<<ADIF) )
00098
00102 #define Set_prescaler(prescaler) (ADCSRA &= ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)),\
00103 ADCSRA |= (prescaler) )
00105
00109 #define Clear_adc_mux() (ADMUX &= ~((1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0)) )
00110 #define Select_adc_channel(channel) (Clear_adc_mux(), ADMUX |= (channel) )
00112
00116
00120 #define Start_conv() (ADCSRA |= (1<<ADSC) )
00121 #define Start_conv_channel(channel) (Select_adc_channel(channel), Start_conv() )
00122 #define Start_amplified_conv() (ADCSRB |= (1<<ADASCR) )
00123 #define Stop_amplified_conv() (ADCSRB &= ~(1<<ADASCR) )
00124 #define Start_amplified_conv_channel(channel) (Select_adc_channel(channel), Start_amplified_conv() )
00126
00130 #define Start_conv_idle() (SMCR |= (1<<SM0)|(1<<SE) )
00131 #define Start_conv_idle_channel(channel) (Select_adc_channel(channel), Start_conv_idle() )
00132 #define Clear_sleep_mode() (SMCR &= ~(1<<SM0)|(1<<SE) )
00134
00136
00140 #define Adc_get_8_bits_result() ((U8)(ADCH))
00141 #define Adc_get_10_bits_result() ((U16)(ADCL+((U16)(ADCH<<8))))
00143
00144
00148 #define Disable_adc() (ADCSRA &= ~(1<<ADEN))
00150
00154 #define Is_adc_conv_finished() ((ADCSRA & (1<<ADIF)) ? TRUE : FALSE)
00155 #define Is_adc_conv_not_finished() ((ADCSRA | ~(1<<ADIF)) ? TRUE : FALSE)
00157
00159
00160
00161
00162
00166
00171 void init_adc(void);
00173
00175
00176 #endif // ADC_DRV_H