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
00045 #ifndef _TIMER8_DRV_H_
00046 #define _TIMER8_DRV_H_
00047
00048
00049
00050 #include "config.h"
00051
00052
00053
00054 #ifndef FOSC
00055 # error You must define FOSC in "config.h" file
00056 #endif
00057
00058 #ifndef TIMER8_0 // 8-bit TIMER 0 Defintion
00059 #define TIMER8_0 0x00
00060 #endif
00061 #ifndef TIMER8_2 // 8-bit TIMER 2 Defintion
00062 #define TIMER8_2 0x02
00063 #endif
00064 #ifndef BOTH_TIMER8 // Both the 8-bit TIMERs Defintion
00065 #define BOTH_TIMER8 0xFF
00066 #endif
00067
00068
00069
00070
00071 #define Timer8_set_pwm_a(value) ( Timer8_set_compare_a(value) )
00072 #define Timer8_set_pwm(value) ( Timer8_set_pwm_a(value) )
00073 #define Timer8_get_pwm_a() ( Timer8_get_compare_a() )
00074 #define Timer8_get_pwm() ( Timer8_get_pwm_a() )
00075
00076 #define Timer8_off() Timer8_set_clock(TIMER8_NO_CLOCK)
00077
00078
00079 #ifndef USE_TIMER8
00080 # error You must define USE_TIMER8 to TIMER8_0 in "config.h" file
00081
00082 # elif (USE_TIMER8 == TIMER8_0) //!< 8-bit TIMER 0 used
00083
00084
00085
00086 # define Timer8_select(timer8_num) // Empty !
00087
00088 # define Timer8_clear() { TCCR0A=0; TCNT0=0; OCR0A=0; }
00089
00090 # define Timer8_set_counter(value) ( TCNT0 = value )
00091 # define Timer8_get_counter() ( TCNT0 )
00092
00093 # define Timer8_set_compare_a(value) ( OCR0A = value )
00094 # define Timer8_set_compare(value) ( Timer8_set_compare_a(value) ) // No index specified
00095 # define Timer8_get_compare_a() ( OCR0A )
00096 # define Timer8_get_compare() ( Timer8_get_compare_a() ) // No index specified
00097
00098 # define Timer8_set_mode_output_a(conf) ( TCCR0A = (TCCR0A & (~TIMER8_COMP_MODE_MASK_A)) | (conf << COM0A0) )
00099 # define Timer8_set_mode_output(conf) ( Timer8_set_mode_output_a(conf) ) // No index specified
00100 # define Timer8_get_mode_output_a() ((TCCR0A & TIMER8_COMP_MODE_MASK_A) >> COM0A0 )
00101 # define Timer8_get_mode_output() ( Timer8_get_mode_output_a() ) // No index specified
00102
00103 # define Timer8_set_waveform_mode(conf) ( TCCR0A = (TCCR0A & (~TIMER8_WGM_RA_MASK)) | \
00104 ( (((conf & 0x02) >> 1) << WGM01) | ((conf & 0x1) << WGM00) ) )
00105 # define Timer8_get_waveform_mode() ( ((TCCR0A & (1<<WGM00)) >> WGM00) | \
00106 ( ((TCCR0A & (1<<WGM01)) >> WGM01) << 0x1) )
00107
00108 # define Timer8_set_clock(value) ( TCCR0B = (TCCR0B & (~TIMER8_CLK_MASK)) | (value << CS00) )
00109 # define Timer8_get_clock() ((TCCR0B & TIMER8_CLK_MASK) >> CS00 )
00110
00111 # define Timer8_overflow_it_enable() ( TIMSK0 |= (1<<TOIE0) )
00112 # define Timer8_overflow_it_disable() ( TIMSK0 &= ~(1<<TOIE0) )
00113 # define Timer8_compare_a_it_enable() ( TIMSK0 |= (1<<OCIE0A) )
00114 # define Timer8_compare_a_it_disable() ( TIMSK0 &= ~(1<<OCIE0A) )
00115 # define Timer8_compare_it_enable() ( Timer8_compare_a_it_enable() )
00116 # define Timer8_compare_it_disable() ( Timer8_compare_a_it_disable() )
00117
00118 # define Timer8_get_overflow_it_mask() ((TIMSK0 & (1<<TOIE0) ) >> TOIE0 )
00119 # define Timer8_get_compare_a_it_mask() ((TIMSK0 & (1<<OCIE0A)) >> OCIE0A )
00120 # define Timer8_get_compare_it_mask() ( Timer8_get_compare_a_it_mask() )
00121
00122 # define Timer8_clear_overflow_it() ( TIFR0 |= (1<<TOV0) )
00123 # define Timer8_clear_compare_a_it() ( TIFR0 |= (1<<OCF0A) )
00124 # define Timer8_clear_compare_it() ( Timer8_clear_compare_a_it() )
00125 # define Timer8_get_overflow_it() ((TIFR0 & (1<<TOV0) ) >> TOV0 )
00126 # define Timer8_get_compare_a_it() ((TIFR0 & (1<<OCF0A)) >> OCF0A )
00127 # define Timer8_get_compare_it() ( Timer8_get_compare_a_it() )
00128
00129 #else
00130 #error USE_TIMER8 definition is not referenced in "timer8_drv.h" file
00131 #endif
00132
00133
00137
00138 # define Timer8_2_system_clk() ( ASSR &= ~((1<<EXCLK)|(1<<AS2)) )
00139 # define Timer8_2_external_osc() ( ASSR = (ASSR & ~(1<<EXCLK)) | (1<<AS2) )
00140 # define Timer8_2_external_clk() ( ASSR |= ((1<<EXCLK)|(1<<AS2)) )
00141
00142 # define Timer8_2_update_busy() ( ASSR & ( (1<<TCN2UB) | (1<<OCR2UB) | (1<<TCR2UB) ) )
00143
00144
00145
00146
00147
00148 #define TIMER8_COMP_MODE_NORMAL (0)
00149 #define TIMER8_COMP_MODE_TOGGLE (1)
00150 #define TIMER8_COMP_MODE_CLEAR_OC (2)
00151 #define TIMER8_COMP_MODE_SET_OC (3)
00152 #define TIMER8_COMP_MODE_MASK_A (3<<COM0A0)
00153
00154 #define TIMER8_WGM_NORMAL (0)
00155 #define TIMER8_WGM_PWM_PC8 (1)
00156 #define TIMER8_WGM_CTC_OCR (2)
00157 #define TIMER8_WGM_FAST_PWM8 (3)
00158 #define TIMER8_WGM_RA_MASK ( (1<<WGM00) | (1<<WGM01) )
00159
00160 #define TIMER8_NO_CLOCK (0)
00161 #define TIMER8_CLKIO_BY_1 (1)
00162 #define TIMER8_CLK_MASK (7<<CS00)
00163
00164 #define TIMER8_0_NO_CLOCK (0)
00165 #define TIMER8_0_CLKIO_BY_1 (1)
00166 #define TIMER8_0_CLKIO_BY_8 (2)
00167 #define TIMER8_0_CLKIO_BY_64 (3)
00168 #define TIMER8_0_CLKIO_BY_256 (4)
00169 #define TIMER8_0_CLKIO_BY_1024 (5)
00170 #define TIMER8_0_EXT_CLOCK_FALLING_EDGE (6)
00171 #define TIMER8_0_EXT_CLOCK_RISING_EDGE (7)
00172
00173 #define TIMER8_2_NO_CLOCK (0)
00174 #define TIMER8_2_CLKIO_BY_1 (1)
00175 #define TIMER8_2_CLKIO_BY_8 (2)
00176 #define TIMER8_2_CLKIO_BY_32 (3)
00177 #define TIMER8_2_CLKIO_BY_64 (4)
00178 #define TIMER8_2_CLKIO_BY_128 (5)
00179 #define TIMER8_2_CLKIO_BY_256 (6)
00180 #define TIMER8_2_CLKIO_BY_1024 (7)
00181
00182
00183
00184
00185
00186
00196 extern U8 timer8_get_counter(void);
00197
00198
00199
00200 #endif // _TIMER8_DRV_H_
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230