00001
00002
00021
00022
00023 #ifndef _TIMER8_DRV_H_
00024 #define _TIMER8_DRV_H_
00025
00026
00027
00028 #include "config.h"
00029
00030
00031
00032 # define Timer8_select(timer8_num) __no_operation() // for compatibility with others MCUs (2 timers)
00033
00034 # define Timer8_clear() ( TCCR0A=0, TCCR0B=0, TCNT0=0, OCR0A=0, OCR0B=0)
00035
00036 # define Timer8_set_counter(value) ( TCNT0 = value )
00037 # define Timer8_get_counter() ( TCNT0 )
00038
00039 # define Timer8_set_compare_a(value) ( OCR0A = value )
00040 # define Timer8_set_compare_b(value) ( OCR0B = value )
00041 # define Timer8_set_compare(value) ( Timer8_set_compare_a(value) ) // default : module A is used
00042 # define Timer8_get_compare_a() ( OCR0A )
00043 # define Timer8_get_compare_b() ( OCR0B )
00044 # define Timer8_get_compare() ( Timer8_get_compare_a() ) // default : module A is used
00045
00046 # define Timer8_force_output_compare_a() ( TCCR0B |= (1<FOC0A) )
00047 # define Timer8_clear_output_compare_a() ( TCCR0B &= ~(1<FOC0A) )
00048 # define Timer8_force_output_compare_b() ( TCCR0B |= (1<FOC0B) )
00049 # define Timer8_clear_output_compare_b() ( TCCR0B &= ~(1<FOC0B) )
00050 # define Timer8_force_output_compare() ( Timer8_force_output_compare_a() )
00051 # define Timer8_clear_output_compare() ( Timer8_clear_output_compare_a() )
00052
00053 # define Timer8_set_mode_output_a(conf) ( TCCR0A = (TCCR0A & (~TIMER8_COMP_MODE_MASK_A)) | (conf << COM0A0) )
00054 # define Timer8_set_mode_output_b(conf) ( TCCR0A = (TCCR0A & (~TIMER8_COMP_MODE_MASK_B)) | (conf << COM0B0) )
00055 # define Timer8_set_mode_output(conf) ( Timer8_set_mode_output_a(conf) ) // default : module A is used
00056 # define Timer8_get_mode_output_a() ((TCCR0A & TIMER8_COMP_MODE_MASK_A) >> COM0A0 )
00057 # define Timer8_get_mode_output_b() ((TCCR0A & TIMER8_COMP_MODE_MASK_B) >> COM0B0 )
00058 # define Timer8_get_mode_output() ( Timer8_get_mode_output_a() ) // default : module A is used
00059
00060 # define Timer8_set_waveform_mode(conf) ( TCCR0A = (TCCR0A&(~TIMER8_WGM_01_MASK)) | ((conf&0x03) << WGM00), \
00061 ( TCCR0B = (TCCR0B&(~TIMER8_WGM_2_MASK)) | (((conf&0x04)>>2) << WGM02)) )
00062 # define Timer8_get_waveform_mode() ( ((TCCR0A & TIMER8_WGM_01_MASK) >> WGM00) | \
00063 ( ((TCCR0A & TIMER8_WGM_2_MASK) >> WGM02) << 0x2) )
00064
00065 # define Timer8_set_clock(value) ( TCCR0B = (TCCR0B & (~TIMER8_CLK_MASK)) | (value << CS00) )
00066 # define Timer8_get_clock() ( (TCCR0B & TIMER8_CLK_MASK) >> CS00 )
00067
00068 # define Timer8_overflow_it_enable() ( TIMSK0 |= (1<<TOIE0) )
00069 # define Timer8_overflow_it_disable() ( TIMSK0 &= ~(1<<TOIE0) )
00070 # define Timer8_compare_a_it_enable() ( TIMSK0 |= (1<<OCIE0A) )
00071 # define Timer8_compare_a_it_disable() ( TIMSK0 &= ~(1<<OCIE0A) )
00072 # define Timer8_compare_b_it_enable() ( TIMSK0 |= (1<<OCIE0B) )
00073 # define Timer8_compare_b_it_disable() ( TIMSK0 &= ~(1<<OCIE0B) )
00074 # define Timer8_compare_it_enable() ( Timer8_compare_a_it_enable() ) // default : module A is used
00075 # define Timer8_compare_it_disable() ( Timer8_compare_a_it_disable() ) // default : module A is used
00076 # define Timer8_get_overflow_it_mask() ((TIMSK0 & (1<<TOIE0) ) >> TOIE0 )
00077 # define Timer8_get_compare_a_it_mask() ((TIMSK0 & (1<<OCIE0A)) >> OCIE0A )
00078 # define Timer8_get_compare_b_it_mask() ((TIMSK0 & (1<<OCIE0B)) >> OCIE0B )
00079 # define Timer8_get_compare_it_mask() ( Timer8_get_compare_a_it_mask() ) // default : module A is used
00080
00081 # define Timer8_clear_overflow_it() ( TIFR0 |= (1<<TOV0) )
00082 # define Timer8_clear_compare_a_it() ( TIFR0 |= (1<<OCF0A) )
00083 # define Timer8_clear_compare_b_it() ( TIFR0 |= (1<<OCF0B) )
00084 # define Timer8_clear_compare_it() ( Timer8_clear_compare_a_it() ) // default : module A is used
00085 # define Timer8_get_overflow_it() ((TIFR0 & (1<<TOV0) ) >> TOV0 )
00086 # define Timer8_get_compare_a_it() ((TIFR0 & (1<<OCF0A)) >> OCF0A )
00087 # define Timer8_get_compare_b_it() ((TIFR0 & (1<<OCF0B)) >> OCF0B )
00088 # define Timer8_get_compare_it() ( Timer8_get_compare_a_it() ) // default : module A is used
00089
00090
00091
00092
00093
00094
00095
00096 #define TIMER8_COMP_MODE_NORMAL (0)
00097 #define TIMER8_COMP_MODE_TOGGLE (1)
00098 #define TIMER8_COMP_MODE_CLEAR_OC (2)
00099 #define TIMER8_COMP_MODE_SET_OC (3)
00100 #define TIMER8_COMP_MODE_MASK_A (3<<COM0A0)
00101 #define TIMER8_COMP_MODE_MASK_B (3<<COM0B0)
00102
00103 #define TIMER8_WGM_NORMAL (0)
00104 #define TIMER8_WGM_PWM_PC8 (1)
00105 #define TIMER8_WGM_CTC_OCR (2)
00106 #define TIMER8_WGM_FAST_PWM8 (3)
00107 #define TIMER8_WGM_PWM_PC_OCRA (5)
00108 #define TIMER8_WGM_PWM_FAST_OCRA (7)
00109 #define TIMER8_WGM_01_MASK ((1<<WGM00) | (1<<WGM01))
00110 #define TIMER8_WGM_2_MASK (1<<WGM02)
00111
00112 #define TIMER8_CLK_MASK (7<<CS00)
00113 #define TIMER8_NO_CLOCK (0)
00114 #define TIMER8_CLKIO_BY_1 (1)
00115 #define TIMER8_CLKIO_BY_8 (2)
00116 #define TIMER8_CLKIO_BY_64 (3)
00117 #define TIMER8_CLKIO_BY_256 (4)
00118 #define TIMER8_CLKIO_BY_1024 (5)
00119 #define TIMER8_EXT_CLOCK_FALLING_EDGE (6)
00120 #define TIMER8_EXT_CLOCK_RISING_EDGE (7)
00121
00122
00123
00124
00125
00126
00127
00128
00138 extern U8 timer8_get_counter(void);
00139
00140
00141
00142 #endif // _TIMER8_DRV_H_
00143
00144