00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef COMPARATOR_DRV_H
00016 #define COMPARATOR_DRV_H
00017
00018
00019
00023
00024
00028
00032
00053
00057 #define Enable_comparator0() (AC0CON |= (1<<AC0EN) )
00059
00063 #define Enable_comparator0_interrupt() (AC0CON |= (1<<AC0IE) )
00064 #define Disable_comparator0_interrupt() (AC0CON &= ~(1<<AC0IE) )
00066
00071 #define Comparator0_it_on_output_toggle() \
00072 (AC0CON &= ~( (1<<AC0IS1) | (1<<AC0IS0) ) )
00074 #define Comparator0_it_on_output_falling_edge() \
00075 (AC0CON |= (1<<AC0IS1), \
00076 AC0CON &= ~(1<<AC0IS0) )
00078 #define Comparator0_it_on_output_rising_edge() \
00079 (AC0CON |= ((1<<AC0IS1) | (1<<AC0IS0)) )
00081
00086 #define Set_comparator0_ni_vref_6_40() \
00087 (AC0CON &= ~( (1<<AC0M2) | (1<<AC0M1) | (1<<AC0M0) ) )
00089 #define Set_comparator0_ni_vref_3_20() \
00090 (AC0CON &= ~( (1<<AC0M2) | (1<<AC0M1) | (0<<AC0M0) ), \
00091 AC0CON |= ( (0<<AC0M2) | (0<<AC0M1) | (1<<AC0M0) ) )
00093 #define Set_comparator0_ni_vref_2_13() \
00094 (AC0CON &= ~( (1<<AC0M2) | (0<<AC0M1) | (1<<AC0M0) ), \
00095 AC0CON |= ( (0<<AC0M2) | (1<<AC0M1) | (0<<AC0M0) ) )
00097 #define Set_comparator0_ni_vref_1_60() \
00098 (AC0CON &= ~( (1<<AC0M2) | (0<<AC0M1) | (0<<AC0M0) ), \
00099 AC0CON |= ( (0<<AC0M2) | (1<<AC0M1) | (1<<AC0M0) ) )
00101 #define Set_comparator0_ni_acmp() \
00102 (AC0CON &= ~( (0<<AC0M2) | (1<<AC0M1) | (1<<AC0M0) ), \
00103 AC0CON |= ( (1<<AC0M2) | (0<<AC0M1) | (0<<AC0M0) ) )
00105 #define Set_comparator0_ni_dac() \
00106 (AC0CON &= ~( (0<<AC0M2) | (1<<AC0M1) | (0<<AC0M0) ), \
00107 AC0CON |= ( (1<<AC0M2) | (0<<AC0M1) | (1<<AC0M0) ) )
00109
00113 #define Disable_comparator0() (AC0CON &= ~(1<<AC0EN) )
00115
00117
00118
00122
00143
00147 #define Enable_comparator1() (AC1CON |= (1<<AC1EN) )
00149
00153 #define Enable_comparator1_interrupt() (AC1CON |= (1<<AC1IE) )
00154 #define Disable_comparator1_interrupt() (AC1CON &= ~(1<<AC1IE) )
00156
00161 #define Comparator1_it_on_output_toggle() \
00162 (AC1CON &= ~( (1<<AC1IS1) | (1<<AC1IS0) ) )
00164 #define Comparator1_it_on_output_falling_edge() \
00165 (AC1CON |= (1<<AC1IS1), \
00166 AC1CON &= ~(1<<AC1IS0) )
00168 #define Comparator1_it_on_output_rising_edge() \
00169 (AC1CON |= ((1<<AC1IS1) | (1<<AC1IS0)) )
00171
00176 #define Enable_comparator1_interrupt_capture() (AC1CON |= (1<<AC1ICE) )
00177 #define Disable_comparator1_interrupt_capture() (AC1CON &= ~(1<<AC1ICE) )
00179
00184 #define Set_comparator1_ni_vref_6_40() \
00185 (AC1CON &= ~( (1<<AC1M2) | (1<<AC1M1) | (1<<AC1M0) ) )
00187 #define Set_comparator1_ni_vref_3_20() \
00188 (AC1CON &= ~( (1<<AC1M2) | (1<<AC1M1) | (0<<AC1M0) ), \
00189 AC1CON |= ( (0<<AC1M2) | (0<<AC1M1) | (1<<AC1M0) ) )
00191 #define Set_comparator1_ni_vref_2_13() \
00192 (AC1CON &= ~( (1<<AC1M2) | (0<<AC1M1) | (1<<AC1M0) ), \
00193 AC1CON |= ( (0<<AC1M2) | (1<<AC1M1) | (0<<AC1M0) ) )
00195 #define Set_comparator1_ni_vref_1_60() \
00196 (AC1CON &= ~( (1<<AC1M2) | (0<<AC1M1) | (0<<AC1M0) ), \
00197 AC1CON |= ( (0<<AC1M2) | (1<<AC1M1) | (1<<AC1M0) ) )
00199 #define Set_comparator1_ni_acmp() \
00200 (AC1CON &= ~( (0<<AC1M2) | (1<<AC1M1) | (1<<AC1M0) ), \
00201 AC1CON |= ( (1<<AC1M2) | (0<<AC1M1) | (0<<AC1M0) ) )
00203 #define Set_comparator1_ni_dac() \
00204 (AC1CON &= ~( (0<<AC1M2) | (1<<AC1M1) | (0<<AC1M0) ), \
00205 AC1CON |= ( (1<<AC1M2) | (0<<AC1M1) | (1<<AC1M0) ) )
00207
00211 #define Disable_comparator1() (AC1CON &= ~(1<<AC1EN) )
00213
00215
00219
00240
00244 #define Enable_comparator2() (AC2CON |= (1<<AC2EN) )
00246
00250 #define Enable_comparator2_interrupt() (AC2CON |= (1<<AC2IE) )
00251 #define Disable_comparator2_interrupt() (AC2CON &= ~(1<<AC2IE) )
00253
00258 #define Comparator2_it_on_output_toggle() \
00259 (AC2CON &= ~( (1<<AC2IS1) | (1<<AC2IS0) ) )
00261 #define Comparator2_it_on_output_falling_edge() \
00262 (AC2CON |= (1<<AC2IS1), \
00263 AC2CON &= ~(1<<AC2IS0) )
00265 #define Comparator2_it_on_output_rising_edge() \
00266 (AC2CON |= ((1<<AC2IS1) | (1<<AC2IS0)) )
00268
00273 #define Set_comparator2_ni_vref_6_40() \
00274 (AC2CON &= ~( (1<<AC2M2) | (1<<AC2M1) | (1<<AC2M0) ) )
00276 #define Set_comparator2_ni_vref_3_20() \
00277 (AC2CON &= ~( (1<<AC2M2) | (1<<AC2M1) | (0<<AC2M0) ), \
00278 AC2CON |= ( (0<<AC2M2) | (0<<AC2M1) | (1<<AC2M0) ) )
00280 #define Set_comparator2_ni_vref_2_13() \
00281 (AC2CON &= ~( (1<<AC2M2) | (0<<AC2M1) | (1<<AC2M0) ), \
00282 AC2CON |= ( (0<<AC2M2) | (1<<AC2M1) | (0<<AC2M0) ) )
00284 #define Set_comparator2_ni_vref_1_60() \
00285 (AC2CON &= ~( (1<<AC2M2) | (0<<AC2M1) | (0<<AC2M0) ), \
00286 AC2CON |= ( (0<<AC2M2) | (1<<AC2M1) | (1<<AC2M0) ) )
00288 #define Set_comparator2_ni_acmp() \
00289 (AC2CON &= ~( (0<<AC2M2) | (1<<AC2M1) | (1<<AC2M0) ), \
00290 AC2CON |= ( (1<<AC2M2) | (0<<AC2M1) | (0<<AC2M0) ) )
00292 #define Set_comparator2_ni_dac() \
00293 (AC2CON &= ~( (0<<AC2M2) | (1<<AC2M1) | (0<<AC2M0) ), \
00294 AC2CON |= ( (1<<AC2M2) | (0<<AC2M1) | (1<<AC2M0) ) )
00296
00300 #define Disable_comparator2() (AC2CON &= ~(1<<AC2EN) )
00302
00304
00306
00307
00308
00309
00310
00314
00320
00324 void init_comparator0(void);
00326
00330 void init_comparator1(void);
00332
00336 void init_comparator2(void);
00338
00340
00342 #endif // COMPARATOR_DRV_H
00343