adc_drv.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 #ifndef ADC_DRV_H
00015 #define ADC_DRV_H
00016 
00017 //_____ I N C L U D E S ____________________________________________________
00018 
00019 
00023 //_____ M A C R O S ________________________________________________________
00024 
00028 
00032 #define Enable_adc()                         (ADCSRA |= (1<<ADEN))
00033 
00034 
00038 #define Right_adjust_adc_result()            (ADMUX  &= ~(1<<ADLAR))
00039 #define Left_adjust_adc_result()             (ADMUX  |=  (1<<ADLAR))
00040 
00041 
00045 #define Enable_adc_high_speed_mode()         (ADCSRB |=  (1<<ADHSM))
00046 #define Disable_adc_high_speed_mode()        (ADCSRB &= ~(1<<ADHSM))
00047 
00048 
00049 
00053 #define Enable_internal_vref()               (ADMUX  |=  ((1<<REFS1)|(1<<REFS0)) )
00054 #define Enable_external_vref()               (ADMUX  &= ~((1<<REFS1)|(1<<REFS0)) )
00055 #define Enable_vcc_vref()                    (ADMUX  &= ~(1<<REFS1),          \
00056                                               ADMUX  |=  (1<<REFS0) )
00057 
00058 
00062 #define Enable_all_it()                      (SREG   |=  (0x80) )
00063 #define Disable_all_it()                     (SREG   &= ~(0x80) )
00064 #define Enable_adc_it()                      (ADCSRA |=  (1<<ADIE) )
00065 #define Disable_adc_it()                     (ADCSRA &= ~(1<<ADIE) )
00066 #define Clear_adc_flag()                     (ADCSRA &=  (1<<ADIF) )
00067 
00068 
00072 #define Set_prescaler(prescaler)             (ADCSRA &= ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)),\
00073                                               ADCSRA |=  (prescaler) )
00074 
00075 
00079 #define Clear_adc_mux()                      (ADMUX  &= ~((1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0)) )
00080 #define Select_adc_channel(channel)          (Clear_adc_mux(), ADMUX |= (channel) )
00081 
00082 
00086 
00090 #define Start_conv()                          (ADCSRA |= (1<<ADSC) )
00091 #define Start_conv_channel(channel)           (Select_adc_channel(channel), Start_conv() )
00092 #define Start_amplified_conv()                (ADCSRB |= (1<<ADASCR) )
00093 #define Stop_amplified_conv()                 (ADCSRB &= ~(1<<ADASCR) )
00094 #define Start_amplified_conv_channel(channel) (Select_adc_channel(channel), Start_amplified_conv() )
00095 
00096 
00100 #define Start_conv_idle()                    (SMCR   |=  (1<<SM0)|(1<<SE) )
00101 #define Start_conv_idle_channel(channel)     (Select_adc_channel(channel), Start_conv_idle() )
00102 #define Clear_sleep_mode()                   (SMCR   &= ~(1<<SM0)|(1<<SE) )
00103 
00104 
00106 
00110 #define Adc_get_8_bits_result()               ((U8)(ADCH))
00111 #define Adc_get_10_bits_result()              ((U16)(ADCL+((U16)(ADCH<<8))))
00112 
00113 
00114 
00118 #define Disable_adc()                        (ADCSRA &= ~(1<<ADEN))
00119 
00120 
00124 #define Is_adc_conv_finished()               ((ADCSRA &  (1<<ADIF)) ? TRUE : FALSE)
00125 #define Is_adc_conv_not_finished()           ((ADCSRA | ~(1<<ADIF)) ? TRUE : FALSE)
00126 
00127 
00129 
00130 //_____ D E F I N I T I O N S ______________________________________________
00131 
00132 //_____ F U N C T I O N S __________________________________________________
00136 
00141 void init_adc(void);
00143 
00145 
00146 #endif  // ADC_DRV_H

Generated on Fri Mar 17 16:02:03 2006 for Atmel by  doxygen 1.4.6-NO