📄 timer_8h-source.html
字号:
00139 <span class="comment"></span>00140 <span class="comment">// default prescale settings for the timers</span>00141 <span class="comment">// these settings are applied when you call</span>00142 <span class="comment">// timerInit or any of the timer<x>Init</span><a name="l00143"></a><a class="code" href="timer_8h.html#a20">00143</a> <span class="preprocessor">#define TIMER0PRESCALE TIMER_CLK_DIV8 </span><span class="comment">///< timer 0 prescaler default</span><a name="l00144"></a><a class="code" href="timer_8h.html#a21">00144</a> <span class="comment"></span>#define TIMER1PRESCALE TIMER_CLK_DIV64 <span class="comment">///< timer 1 prescaler default</span><a name="l00145"></a><a class="code" href="timer_8h.html#a22">00145</a> <span class="comment"></span>#define TIMER2PRESCALE TIMERRTC_CLK_DIV64 <span class="comment">///< timer 2 prescaler default</span>00146 <span class="comment"></span>00147 <span class="comment">// interrupt macros for attaching user functions to timer interrupts</span>00148 <span class="comment">// use these with timerAttach( intNum, function )</span>00149 <span class="preprocessor">#define TIMER0OVERFLOW_INT 0</span>00150 <span class="preprocessor"></span><span class="preprocessor">#define TIMER1OVERFLOW_INT 1</span>00151 <span class="preprocessor"></span><span class="preprocessor">#define TIMER1OUTCOMPAREA_INT 2</span>00152 <span class="preprocessor"></span><span class="preprocessor">#define TIMER1OUTCOMPAREB_INT 3</span>00153 <span class="preprocessor"></span><span class="preprocessor">#define TIMER1INPUTCAPTURE_INT 4</span>00154 <span class="preprocessor"></span><span class="preprocessor">#define TIMER2OVERFLOW_INT 5</span>00155 <span class="preprocessor"></span><span class="preprocessor">#define TIMER2OUTCOMPARE_INT 6</span>00156 <span class="preprocessor"></span><span class="preprocessor">#ifdef OCR0 // for processors that support output compare on Timer0</span>00157 <span class="preprocessor"></span><span class="preprocessor">#define TIMER0OUTCOMPARE_INT 7</span>00158 <span class="preprocessor"></span><span class="preprocessor">#define TIMER_NUM_INTERRUPTS 8</span>00159 <span class="preprocessor"></span><span class="preprocessor">#else</span>00160 <span class="preprocessor"></span><span class="preprocessor">#define TIMER_NUM_INTERRUPTS 7</span>00161 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00162 <span class="preprocessor"></span>00163 <span class="comment">// default type of interrupt handler to use for timers</span>00164 <span class="comment">// *do not change unless you know what you're doing</span>00165 <span class="comment">// Value may be SIGNAL or INTERRUPT</span>00166 <span class="preprocessor">#ifndef TIMER_INTERRUPT_HANDLER</span>00167 <span class="preprocessor"></span><span class="preprocessor">#define TIMER_INTERRUPT_HANDLER SIGNAL</span>00168 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00169 <span class="preprocessor"></span>00170 <span class="comment">// functions</span>00171 <span class="keywordtype">void</span> delay(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> us);00172 <span class="comment"></span>00173 <span class="comment">//! initializes timing system (all timers)</span>00174 <span class="comment"></span><span class="comment">// runs all timer init functions</span>00175 <span class="comment">// sets all timers to default prescale values #defined in systimer.c</span>00176 <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a7">timerInit</a>(<span class="keywordtype">void</span>);00177 00178 <span class="comment">// default initialization routines for each timer</span>00179 <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a8">timer0Init</a>(<span class="keywordtype">void</span>); <span class="comment">///< initialize timer0</span>00180 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a9">timer1Init</a>(<span class="keywordtype">void</span>); <span class="comment">///< initialize timer1</span>00181 <span class="comment"></span><span class="preprocessor">#ifdef TCNT2 // support timer2 only if it exists</span>00182 <span class="preprocessor"></span><span class="keywordtype">void</span> timer2Init(<span class="keywordtype">void</span>); <span class="comment">///< initialize timer2</span>00183 <span class="comment"></span><span class="preprocessor">#endif</span>00184 <span class="preprocessor"></span>00185 <span class="comment">// Clock prescaler set/get commands for each timer/counter</span>00186 <span class="comment">// For setting the prescaler, you should use one of the #defines</span>00187 <span class="comment">// above like TIMER_CLK_DIVx, where [x] is the division rate</span>00188 <span class="comment">// you want.</span>00189 <span class="comment">// When getting the current prescaler setting, the return value</span>00190 <span class="comment">// will be the [x] division value currently set.</span>00191 <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a44">timer0SetPrescaler</a>(u08 prescale); <span class="comment">///< set timer0 prescaler</span>00192 <span class="comment"></span>u16 <a class="code" href="timer_8c.html#a12">timer0GetPrescaler</a>(<span class="keywordtype">void</span>); <span class="comment">///< get timer0 prescaler</span>00193 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a45">timer1SetPrescaler</a>(u08 prescale); <span class="comment">///< set timer1 prescaler</span>00194 <span class="comment"></span>u16 <a class="code" href="timer_8c.html#a13">timer1GetPrescaler</a>(<span class="keywordtype">void</span>); <span class="comment">///< get timer0 prescaler</span>00195 <span class="comment"></span><span class="preprocessor">#ifdef TCNT2 // support timer2 only if it exists</span>00196 <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a46">timer2SetPrescaler</a>(u08 prescale); <span class="comment">///< set timer2 prescaler</span>00197 <span class="comment"></span>u16 <a class="code" href="timer128_8c.html#a20">timer2GetPrescaler</a>(<span class="keywordtype">void</span>); <span class="comment">///< get timer2 prescaler</span>00198 <span class="comment"></span><span class="preprocessor">#endif</span>00199 <span class="preprocessor"></span>00200 00201 <span class="comment">// TimerAttach and Detach commands</span>00202 <span class="comment">// These functions allow the attachment (or detachment) of any user function</span>00203 <span class="comment">// to a timer interrupt. "Attaching" one of your own functions to a timer</span>00204 <span class="comment">// interrupt means that it will be called whenever that interrupt happens.</span>00205 <span class="comment">// Using attach is better than rewriting the actual INTERRUPT() function</span>00206 <span class="comment">// because your code will still work and be compatible if the timer library</span>00207 <span class="comment">// is updated. Also, using Attach allows your code and any predefined timer</span>00208 <span class="comment">// code to work together and at the same time. (ie. "attaching" your own</span>00209 <span class="comment">// function to the timer0 overflow doesn't prevent timerPause from working,</span>00210 <span class="comment">// but rather allows you to share the interrupt.)</span>00211 <span class="comment">//</span>00212 <span class="comment">// timerAttach(TIMER1OVERFLOW_INT, myOverflowFunction);</span>00213 <span class="comment">// timerDetach(TIMER1OVERFLOW_INT)</span>00214 <span class="comment">//</span>00215 <span class="comment">// timerAttach causes the myOverflowFunction() to be attached, and therefore</span>00216 <span class="comment">// execute, whenever an overflow on timer1 occurs. timerDetach removes the</span>00217 <span class="comment">// association and executes no user function when the interrupt occurs.</span>00218 <span class="comment">// myOverflowFunction must be defined with no return value and no arguments:</span>00219 <span class="comment">//</span>00220 <span class="comment">// void myOverflowFunction(void) { ... }</span>00221 <span class="comment"></span>00222 <span class="comment">//! Attach a user function to a timer interrupt</span>00223 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a52">timerAttach</a>(u08 interruptNum, <span class="keywordtype">void</span> (*userFunc)(<span class="keywordtype">void</span>) );<span class="comment"></span>00224 <span class="comment">//! Detach a user function from a timer interrupt</span>00225 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a53">timerDetach</a>(u08 interruptNum);00226 00227 00228 <span class="comment">// timing commands</span><span class="comment"></span>00229 <span class="comment">//! timerPause pauses for the number of milliseconds specified in <pause_ms></span>00230 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a54">timerPause</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> pause_ms);00231 00232 <span class="comment">// overflow counters</span>00233 <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a17">timer0ClearOverflowCount</a>(<span class="keywordtype">void</span>); <span class="comment">///< clear timer0's overflow counter</span>00234 <span class="comment"></span><span class="keywordtype">long</span> <a class="code" href="timer_8c.html#a18">timer0GetOverflowCount</a>(<span class="keywordtype">void</span>); <span class="comment">///< read timer0's overflow counter</span>00235 <span class="comment"></span><span class="preprocessor">#ifdef TCNT2 // support timer2 only if it exists</span>00236 <span class="preprocessor"></span><span class="keywordtype">void</span> timer2ClearOverflowCount(<span class="keywordtype">void</span>); <span class="comment">///< clear timer2's overflow counter</span>00237 <span class="comment"></span><span class="keywordtype">long</span> timer2GetOverflowCount(<span class="keywordtype">void</span>); <span class="comment">///< read timer0's overflow counter</span>00238 <span class="comment"></span><span class="preprocessor">#endif</span>00239 <span class="preprocessor"></span>00240 <span class="comment">// PWM initialization and set commands for timer1</span>00241 <span class="comment">// timer1PWMInit()</span>00242 <span class="comment">// configures the timer1 hardware for PWM mode on pins OC1A and OC1B.</span>00243 <span class="comment">// bitRes should be 8,9,or 10 for 8,9,or 10bit PWM resolution</span>00244 <span class="comment">//</span>00245 <span class="comment">// timer1PWMOff()</span>00246 <span class="comment">// turns off all timer1 PWM output and set timer mode to normal state</span>00247 <span class="comment">//</span>00248 <span class="comment">// timer1PWMAOn() and timer1PWMBOn()</span>00249 <span class="comment">// turn on output of PWM signals to OC1A or OC1B pins</span>00250 <span class="comment">// NOTE: Until you define the OC1A and OC1B pins as outputs, and run</span>00251 <span class="comment">// this "on" command, no PWM output will be output</span>00252 <span class="comment">//</span>00253 <span class="comment">// timer1PWMAOff() and timer1PWMBOff()</span>00254 <span class="comment">// turn off output of PWM signals to OC1A or OC1B pins</span>00255 <span class="comment">//</span>00256 <span class="comment">// timer1PWMASet() and timer1PWMBSet()</span>00257 <span class="comment">// sets the PWM duty cycle for each channel</span>00258 <span class="comment">// NOTE: <pwmDuty> should be in the range 0-255 for 8bit PWM</span>00259 <span class="comment">// <pwmDuty> should be in the range 0-511 for 9bit PWM</span>00260 <span class="comment">// <pwmDuty> should be in the range 0-1023 for 10bit PWM</span>00261 <span class="comment">// NOTE: the PWM frequency can be controlled in increments by setting the</span>00262 <span class="comment">// prescaler for timer1</span>00263 00264 <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a59">timer1PWMInit</a>(u08 bitRes); <span class="comment">///< initialize and set timer1 mode to PWM</span>00265 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a60">timer1PWMInitICR</a>(u16 topcount);<span class="comment">///< initialize and set timer1 mode to PWM with specific top count</span>00266 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a20">timer1PWMOff</a>(<span class="keywordtype">void</span>); <span class="comment">///< turn off all timer1 PWM output and set timer mode to normal</span>00267 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a21">timer1PWMAOn</a>(<span class="keywordtype">void</span>); <span class="comment">///< turn on timer1 Channel A (OC1A) PWM output</span>00268 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a22">timer1PWMBOn</a>(<span class="keywordtype">void</span>); <span class="comment">///< turn on timer1 Channel B (OC1B) PWM output</span>00269 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a23">timer1PWMAOff</a>(<span class="keywordtype">void</span>); <span class="comment">///< turn off timer1 Channel A (OC1A) PWM output</span>00270 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a24">timer1PWMBOff</a>(<span class="keywordtype">void</span>); <span class="comment">///< turn off timer1 Channel B (OC1B) PWM output</span>00271 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a68">timer1PWMASet</a>(u16 pwmDuty); <span class="comment">///< set duty of timer1 Channel A (OC1A) PWM output</span>00272 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a69">timer1PWMBSet</a>(u16 pwmDuty); <span class="comment">///< set duty of timer1 Channel B (OC1B) PWM output</span>00273 <span class="comment"></span>00274 <span class="comment">// Pulse generation commands have been moved to the pulse.c library</span>00275 00276 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -