⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_8c-source.html

📁 ATMEL的AVR单片机库文件
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00229 <span class="comment">    TimerPauseReg = 0;</span>00230 <span class="comment">    while(TimerPauseReg &lt; pause);</span>00231 <span class="comment"></span>00232 <span class="comment">    */</span>00233 }00234 <a name="l00235"></a><a class="code" href="timer128_8h.html#a55">00235</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a17">timer0ClearOverflowCount</a>(<span class="keywordtype">void</span>)00236 {00237     <span class="comment">// clear the timer overflow counter registers</span>00238     Timer0Reg0 = 0; <span class="comment">// initialize time registers</span>00239 }00240 <a name="l00241"></a><a class="code" href="timer128_8h.html#a56">00241</a> <span class="keywordtype">long</span> <a class="code" href="timer_8c.html#a18">timer0GetOverflowCount</a>(<span class="keywordtype">void</span>)00242 {00243     <span class="comment">// return the current timer overflow count</span>00244     <span class="comment">// (this is since the last timer0ClearOverflowCount() command was called)</span>00245     <span class="keywordflow">return</span> Timer0Reg0;00246 }00247 00248 <span class="preprocessor">#ifdef TCNT2    // support timer2 only if it exists</span>00249 <span class="preprocessor"></span><span class="keywordtype">void</span> timer2ClearOverflowCount(<span class="keywordtype">void</span>)00250 {00251     <span class="comment">// clear the timer overflow counter registers</span>00252     Timer2Reg0 = 0; <span class="comment">// initialize time registers</span>00253 }00254 00255 <span class="keywordtype">long</span> timer2GetOverflowCount(<span class="keywordtype">void</span>)00256 {00257     <span class="comment">// return the current timer overflow count</span>00258     <span class="comment">// (this is since the last timer2ClearOverflowCount() command was called)</span>00259     <span class="keywordflow">return</span> Timer2Reg0;00260 }00261 <span class="preprocessor">#endif</span>00262 <span class="preprocessor"></span><a name="l00263"></a><a class="code" href="timer128_8h.html#a59">00263</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a59">timer1PWMInit</a>(u08 bitRes)00264 {00265     <span class="comment">// configures timer1 for use with PWM output</span>00266     <span class="comment">// on OC1A and OC1B pins</span>00267 00268     <span class="comment">// enable timer1 as 8,9,10bit PWM</span>00269     <span class="keywordflow">if</span>(bitRes == 9)00270     {   <span class="comment">// 9bit mode</span>00271         sbi(TCCR1A,PWM11);00272         cbi(TCCR1A,PWM10);00273     }00274     <span class="keywordflow">else</span> <span class="keywordflow">if</span>( bitRes == 10 )00275     {   <span class="comment">// 10bit mode</span>00276         sbi(TCCR1A,PWM11);00277         sbi(TCCR1A,PWM10);00278     }00279     <span class="keywordflow">else</span>00280     {   <span class="comment">// default 8bit mode</span>00281         cbi(TCCR1A,PWM11);00282         sbi(TCCR1A,PWM10);00283     }00284 00285     <span class="comment">// clear output compare value A</span>00286     outb(OCR1AH, 0);00287     outb(OCR1AL, 0);00288     <span class="comment">// clear output compare value B</span>00289     outb(OCR1BH, 0);00290     outb(OCR1BL, 0);00291 }00292 00293 <span class="preprocessor">#ifdef WGM10</span>00294 <span class="preprocessor"></span><span class="comment">// include support for arbitrary top-count PWM</span>00295 <span class="comment">// on new AVR processors that support it</span>00296 <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a60">timer1PWMInitICR</a>(u16 topcount)00297 {00298     <span class="comment">// set PWM mode with ICR top-count</span>00299     cbi(TCCR1A,WGM10);00300     sbi(TCCR1A,WGM11);00301     sbi(TCCR1B,WGM12);00302     sbi(TCCR1B,WGM13);00303     00304     <span class="comment">// set top count value</span>00305     ICR1 = topcount;00306     00307     <span class="comment">// clear output compare value A</span>00308     OCR1A = 0;00309     <span class="comment">// clear output compare value B</span>00310     OCR1B = 0;00311 00312 }00313 <span class="preprocessor">#endif</span>00314 <span class="preprocessor"></span><a name="l00315"></a><a class="code" href="timer128_8h.html#a61">00315</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a20">timer1PWMOff</a>(<span class="keywordtype">void</span>)00316 {00317     <span class="comment">// turn off timer1 PWM mode</span>00318     cbi(TCCR1A,PWM11);00319     cbi(TCCR1A,PWM10);00320     <span class="comment">// set PWM1A/B (OutputCompare action) to none</span>00321     <a class="code" href="timer_8c.html#a23">timer1PWMAOff</a>();00322     <a class="code" href="timer_8c.html#a24">timer1PWMBOff</a>();00323 }00324 <a name="l00325"></a><a class="code" href="timer128_8h.html#a62">00325</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a21">timer1PWMAOn</a>(<span class="keywordtype">void</span>)00326 {00327     <span class="comment">// turn on channel A (OC1A) PWM output</span>00328     <span class="comment">// set OC1A as non-inverted PWM</span>00329     sbi(TCCR1A,COM1A1);00330     cbi(TCCR1A,COM1A0);00331 }00332 <a name="l00333"></a><a class="code" href="timer128_8h.html#a63">00333</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a22">timer1PWMBOn</a>(<span class="keywordtype">void</span>)00334 {00335     <span class="comment">// turn on channel B (OC1B) PWM output</span>00336     <span class="comment">// set OC1B as non-inverted PWM</span>00337     sbi(TCCR1A,COM1B1);00338     cbi(TCCR1A,COM1B0);00339 }00340 <a name="l00341"></a><a class="code" href="timer128_8h.html#a65">00341</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a23">timer1PWMAOff</a>(<span class="keywordtype">void</span>)00342 {00343     <span class="comment">// turn off channel A (OC1A) PWM output</span>00344     <span class="comment">// set OC1A (OutputCompare action) to none</span>00345     cbi(TCCR1A,COM1A1);00346     cbi(TCCR1A,COM1A0);00347 }00348 <a name="l00349"></a><a class="code" href="timer128_8h.html#a66">00349</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a24">timer1PWMBOff</a>(<span class="keywordtype">void</span>)00350 {00351     <span class="comment">// turn off channel B (OC1B) PWM output</span>00352     <span class="comment">// set OC1B (OutputCompare action) to none</span>00353     cbi(TCCR1A,COM1B1);00354     cbi(TCCR1A,COM1B0);00355 }00356 <a name="l00357"></a><a class="code" href="timer128_8h.html#a68">00357</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a68">timer1PWMASet</a>(u16 pwmDuty)00358 {00359     <span class="comment">// set PWM (output compare) duty for channel A</span>00360     <span class="comment">// this PWM output is generated on OC1A pin</span>00361     <span class="comment">// NOTE:    pwmDuty should be in the range 0-255 for 8bit PWM</span>00362     <span class="comment">//          pwmDuty should be in the range 0-511 for 9bit PWM</span>00363     <span class="comment">//          pwmDuty should be in the range 0-1023 for 10bit PWM</span>00364     <span class="comment">//outp( (pwmDuty&gt;&gt;8), OCR1AH);      // set the high 8bits of OCR1A</span>00365     <span class="comment">//outp( (pwmDuty&amp;0x00FF), OCR1AL);  // set the low 8bits of OCR1A</span>00366     OCR1A = pwmDuty;00367 }00368 <a name="l00369"></a><a class="code" href="timer128_8h.html#a69">00369</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a69">timer1PWMBSet</a>(u16 pwmDuty)00370 {00371     <span class="comment">// set PWM (output compare) duty for channel B</span>00372     <span class="comment">// this PWM output is generated on OC1B pin</span>00373     <span class="comment">// NOTE:    pwmDuty should be in the range 0-255 for 8bit PWM</span>00374     <span class="comment">//          pwmDuty should be in the range 0-511 for 9bit PWM</span>00375     <span class="comment">//          pwmDuty should be in the range 0-1023 for 10bit PWM</span>00376     <span class="comment">//outp( (pwmDuty&gt;&gt;8), OCR1BH);      // set the high 8bits of OCR1B</span>00377     <span class="comment">//outp( (pwmDuty&amp;0x00FF), OCR1BL);  // set the low 8bits of OCR1B</span>00378     OCR1B = pwmDuty;00379 }00380 <span class="comment"></span>00381 <span class="comment">//! Interrupt handler for tcnt0 overflow interrupt</span><a name="l00382"></a><a class="code" href="timer_8c.html#a27">00382</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OVERFLOW0)00383 {00384     Timer0Reg0++;           <span class="comment">// increment low-order counter</span>00385 00386     <span class="comment">// increment pause counter</span>00387     TimerPauseReg++;00388 00389     <span class="comment">// if a user function is defined, execute it too</span>00390     <span class="keywordflow">if</span>(TimerIntFunc[TIMER0OVERFLOW_INT])00391         TimerIntFunc[TIMER0OVERFLOW_INT]();00392 }00393 <span class="comment"></span>00394 <span class="comment">//! Interrupt handler for tcnt1 overflow interrupt</span><a name="l00395"></a><a class="code" href="timer_8c.html#a28">00395</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OVERFLOW1)00396 {00397     <span class="comment">// if a user function is defined, execute it</span>00398     <span class="keywordflow">if</span>(TimerIntFunc[TIMER1OVERFLOW_INT])00399         TimerIntFunc[TIMER1OVERFLOW_INT]();00400 }00401 00402 <span class="preprocessor">#ifdef TCNT2    // support timer2 only if it exists</span>00403 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for tcnt2 overflow interrupt</span>00404 <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OVERFLOW2)00405 {00406     Timer2Reg0++;           <span class="comment">// increment low-order counter</span>00407 00408     <span class="comment">// if a user function is defined, execute it</span>00409     <span class="keywordflow">if</span>(TimerIntFunc[TIMER2OVERFLOW_INT])00410         TimerIntFunc[TIMER2OVERFLOW_INT]();00411 }00412 <span class="preprocessor">#endif</span>00413 <span class="preprocessor"></span>00414 <span class="preprocessor">#ifdef OCR0</span>00415 <span class="preprocessor"></span><span class="comment">// include support for Output Compare 0 for new AVR processors that support it</span><span class="comment"></span>00416 <span class="comment">//! Interrupt handler for OutputCompare0 match (OC0) interrupt</span>00417 <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OUTPUT_COMPARE0)00418 {00419     <span class="comment">// if a user function is defined, execute it</span>00420     <span class="keywordflow">if</span>(TimerIntFunc[TIMER0OUTCOMPARE_INT])00421         TimerIntFunc[TIMER0OUTCOMPARE_INT]();00422 }00423 <span class="preprocessor">#endif</span>00424 <span class="preprocessor"></span><span class="comment"></span>00425 <span class="comment">//! Interrupt handler for CutputCompare1A match (OC1A) interrupt</span><a name="l00426"></a><a class="code" href="timer_8c.html#a29">00426</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OUTPUT_COMPARE1A)00427 {00428     <span class="comment">// if a user function is defined, execute it</span>00429     <span class="keywordflow">if</span>(TimerIntFunc[TIMER1OUTCOMPAREA_INT])00430         TimerIntFunc[TIMER1OUTCOMPAREA_INT]();00431 }00432 <span class="comment"></span>00433 <span class="comment">//! Interrupt handler for OutputCompare1B match (OC1B) interrupt</span><a name="l00434"></a><a class="code" href="timer_8c.html#a30">00434</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OUTPUT_COMPARE1B)00435 {00436     <span class="comment">// if a user function is defined, execute it</span>00437     <span class="keywordflow">if</span>(TimerIntFunc[TIMER1OUTCOMPAREB_INT])00438         TimerIntFunc[TIMER1OUTCOMPAREB_INT]();00439 }00440 <span class="comment"></span>00441 <span class="comment">//! Interrupt handler for InputCapture1 (IC1) interrupt</span><a name="l00442"></a><a class="code" href="timer_8c.html#a31">00442</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_INPUT_CAPTURE1)00443 {00444     <span class="comment">// if a user function is defined, execute it</span>00445     <span class="keywordflow">if</span>(TimerIntFunc[TIMER1INPUTCAPTURE_INT])00446         TimerIntFunc[TIMER1INPUTCAPTURE_INT]();00447 }00448 <span class="comment"></span>00449 <span class="comment">//! Interrupt handler for OutputCompare2 match (OC2) interrupt</span><a name="l00450"></a><a class="code" href="timer_8c.html#a32">00450</a> <span class="comment"></span><a class="code" href="timer128_8c.html#a66">TIMER_INTERRUPT_HANDLER</a>(SIG_OUTPUT_COMPARE2)00451 {00452     <span class="comment">// if a user function is defined, execute it</span>00453     <span class="keywordflow">if</span>(TimerIntFunc[TIMER2OUTCOMPARE_INT])00454         TimerIntFunc[TIMER2OUTCOMPARE_INT]();00455 }</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 + -