📄 timer128_8c-source.html
字号:
00224 }00225 <a name="l00226"></a><a class="code" href="timer128_8c.html#a26">00226</a> <span class="keywordtype">long</span> <a class="code" href="timer_8c.html#a18">timer0GetOverflowCount</a>(<span class="keywordtype">void</span>)00227 {00228 <span class="comment">// return the current timer overflow count</span>00229 <span class="comment">// (this is since the last timer0ClearOverflowCount() command was called)</span>00230 <span class="keywordflow">return</span> Timer0Reg0;00231 }00232 00233 <span class="keywordtype">void</span> timer2ClearOverflowCount(<span class="keywordtype">void</span>)00234 {00235 <span class="comment">// clear the timer overflow counter registers</span>00236 Timer2Reg0 = 0; <span class="comment">// initialize time registers</span>00237 Timer2Reg1 = 0; <span class="comment">// initialize time registers</span>00238 }00239 00240 <span class="keywordtype">long</span> timer2GetOverflowCount(<span class="keywordtype">void</span>)00241 {00242 <span class="comment">// return the current timer overflow count</span>00243 <span class="comment">// (this is since the last timer2ClearOverflowCount() command was called)</span>00244 <span class="keywordflow">return</span> Timer2Reg0;00245 }00246 00247 <a name="l00248"></a><a class="code" href="timer128_8c.html#a29">00248</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a59">timer1PWMInit</a>(u08 bitRes)00249 {00250 <span class="comment">// configures timer1 for use with PWM output</span>00251 <span class="comment">// on pins OC1A, OC1B, and OC1C</span>00252 00253 <span class="comment">// enable Timer1 as 8,9,10bit PWM</span>00254 <span class="keywordflow">if</span>(bitRes == 9)00255 { <span class="comment">// 9bit mode</span>00256 sbi(TCCR1A,WGMA1);00257 cbi(TCCR1A,WGMA0);00258 }00259 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( bitRes == 10 )00260 { <span class="comment">// 10bit mode</span>00261 sbi(TCCR1A,WGMA1);00262 sbi(TCCR1A,WGMA0);00263 }00264 <span class="keywordflow">else</span>00265 { <span class="comment">// default 8bit mode</span>00266 cbi(TCCR1A,WGMA1);00267 sbi(TCCR1A,WGMA0);00268 }00269 00270 <span class="comment">// set clear-timer-on-compare-match</span>00271 <span class="comment">//cbi(TCCR1B,CTC1);</span>00272 <span class="comment">// clear output compare value A</span>00273 outb(OCR1AH, 0);00274 outb(OCR1AL, 0);00275 <span class="comment">// clear output compare value B</span>00276 outb(OCR1BH, 0);00277 outb(OCR1BL, 0);00278 <span class="comment">// clear output compare value C</span>00279 outb(OCR1CH, 0);00280 outb(OCR1CL, 0);00281 }00282 <a name="l00283"></a><a class="code" href="timer128_8h.html#a60">00283</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a60">timer1PWMInitICR</a>(u16 topcount)00284 {00285 <span class="comment">// set PWM mode with ICR top-count</span>00286 cbi(TCCR1A,WGM10);00287 sbi(TCCR1A,WGM11);00288 sbi(TCCR1B,WGM12);00289 sbi(TCCR1B,WGM13);00290 00291 <span class="comment">// set top count value</span>00292 ICR1H = (u08)(topcount>>8);00293 ICR1L = (u08)topcount;00294 00295 <span class="comment">// clear output compare value A</span>00296 outb(OCR1AH, 0);00297 outb(OCR1AL, 0);00298 <span class="comment">// clear output compare value B</span>00299 outb(OCR1BH, 0);00300 outb(OCR1BL, 0);00301 <span class="comment">// clear output compare value C</span>00302 outb(OCR1CH, 0);00303 outb(OCR1CL, 0);00304 }00305 <a name="l00306"></a><a class="code" href="timer128_8c.html#a31">00306</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a20">timer1PWMOff</a>(<span class="keywordtype">void</span>)00307 {00308 <span class="comment">// turn off PWM on Timer1</span>00309 cbi(TCCR1A,WGMA1);00310 cbi(TCCR1A,WGMA0);00311 <span class="comment">// clear (disable) clear-timer-on-compare-match</span>00312 <span class="comment">//cbi(TCCR1B,CTC1);</span>00313 <span class="comment">// set PWM1A/B/C (OutputCompare action) to none</span>00314 <a class="code" href="timer_8c.html#a23">timer1PWMAOff</a>();00315 <a class="code" href="timer_8c.html#a24">timer1PWMBOff</a>();00316 <a class="code" href="timer128_8c.html#a37">timer1PWMCOff</a>();00317 }00318 <a name="l00319"></a><a class="code" href="timer128_8c.html#a32">00319</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a21">timer1PWMAOn</a>(<span class="keywordtype">void</span>)00320 {00321 <span class="comment">// turn on channel A (OC1A) PWM output</span>00322 <span class="comment">// set OC1A as non-inverted PWM</span>00323 sbi(TCCR1A,COMA1);00324 cbi(TCCR1A,COMA0);00325 }00326 <a name="l00327"></a><a class="code" href="timer128_8c.html#a33">00327</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a22">timer1PWMBOn</a>(<span class="keywordtype">void</span>)00328 {00329 <span class="comment">// turn on channel B (OC1B) PWM output</span>00330 <span class="comment">// set OC1B as non-inverted PWM</span>00331 sbi(TCCR1A,COMB1);00332 cbi(TCCR1A,COMB0);00333 }00334 <a name="l00335"></a><a class="code" href="timer128_8h.html#a64">00335</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8c.html#a34">timer1PWMCOn</a>(<span class="keywordtype">void</span>)00336 {00337 <span class="comment">// turn on channel C (OC1C) PWM output</span>00338 <span class="comment">// set OC1C as non-inverted PWM</span>00339 sbi(TCCR1A,COMC1);00340 cbi(TCCR1A,COMC0);00341 }00342 <a name="l00343"></a><a class="code" href="timer128_8c.html#a35">00343</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a23">timer1PWMAOff</a>(<span class="keywordtype">void</span>)00344 {00345 <span class="comment">// turn off channel A (OC1A) PWM output</span>00346 <span class="comment">// set OC1A (OutputCompare action) to none</span>00347 cbi(TCCR1A,COMA1);00348 cbi(TCCR1A,COMA0);00349 }00350 <a name="l00351"></a><a class="code" href="timer128_8c.html#a36">00351</a> <span class="keywordtype">void</span> <a class="code" href="timer_8c.html#a24">timer1PWMBOff</a>(<span class="keywordtype">void</span>)00352 {00353 <span class="comment">// turn off channel B (OC1B) PWM output</span>00354 <span class="comment">// set OC1B (OutputCompare action) to none</span>00355 cbi(TCCR1A,COMB1);00356 cbi(TCCR1A,COMB0);00357 }00358 <a name="l00359"></a><a class="code" href="timer128_8h.html#a67">00359</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8c.html#a37">timer1PWMCOff</a>(<span class="keywordtype">void</span>)00360 {00361 <span class="comment">// turn off channel C (OC1C) PWM output</span>00362 <span class="comment">// set OC1C (OutputCompare action) to none</span>00363 cbi(TCCR1A,COMC1);00364 cbi(TCCR1A,COMC0);00365 }00366 <a name="l00367"></a><a class="code" href="timer128_8c.html#a38">00367</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a68">timer1PWMASet</a>(u16 pwmDuty)00368 {00369 <span class="comment">// set PWM (output compare) duty for channel A</span>00370 <span class="comment">// this PWM output is generated on OC1A pin</span>00371 <span class="comment">// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM</span>00372 <span class="comment">// pwmDuty should be in the range 0-511 for 9bit PWM</span>00373 <span class="comment">// pwmDuty should be in the range 0-1023 for 10bit PWM</span>00374 outp( (pwmDuty>>8), OCR1AH); <span class="comment">// set the high 8bits of OCR1A</span>00375 outp( (pwmDuty&0x00FF), OCR1AL); <span class="comment">// set the low 8bits of OCR1A</span>00376 }00377 <a name="l00378"></a><a class="code" href="timer128_8c.html#a39">00378</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a69">timer1PWMBSet</a>(u16 pwmDuty)00379 {00380 <span class="comment">// set PWM (output compare) duty for channel B</span>00381 <span class="comment">// this PWM output is generated on OC1B pin</span>00382 <span class="comment">// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM</span>00383 <span class="comment">// pwmDuty should be in the range 0-511 for 9bit PWM</span>00384 <span class="comment">// pwmDuty should be in the range 0-1023 for 10bit PWM</span>00385 outp( (pwmDuty>>8), OCR1BH); <span class="comment">// set the high 8bits of OCR1B</span>00386 outp( (pwmDuty&0x00FF), OCR1BL); <span class="comment">// set the low 8bits of OCR1B</span>00387 }00388 <a name="l00389"></a><a class="code" href="timer128_8h.html#a70">00389</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a70">timer1PWMCSet</a>(u16 pwmDuty)00390 {00391 <span class="comment">// set PWM (output compare) duty for channel C</span>00392 <span class="comment">// this PWM output is generated on OC1C pin</span>00393 <span class="comment">// NOTE: pwmDuty should be in the range 0-255 for 8bit PWM</span>00394 <span class="comment">// pwmDuty should be in the range 0-511 for 9bit PWM</span>00395 <span class="comment">// pwmDuty should be in the range 0-1023 for 10bit PWM</span>00396 outp( (pwmDuty>>8), OCR1CH); <span class="comment">// set the high 8bits of OCR1C</span>00397 outp( (pwmDuty&0x00FF), OCR1CL); <span class="comment">// set the low 8bits of OCR1C</span>00398 }00399 00400 <a name="l00401"></a><a class="code" href="timer128_8h.html#a71">00401</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a71">timer3PWMInit</a>(u08 bitRes)00402 {00403 <span class="comment">// configures timer1 for use with PWM output</span>00404 <span class="comment">// on pins OC3A, OC3B, and OC3C</span>00405 00406 <span class="comment">// enable Timer3 as 8,9,10bit PWM</span>00407 <span class="keywordflow">if</span>(bitRes == 9)00408 { <span class="comment">// 9bit mode</span>00409 sbi(TCCR3A,WGMA1);00410 cbi(TCCR3A,WGMA0);00411 }00412 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( bitRes == 10 )00413 { <span class="comment">// 10bit mode</span>00414 sbi(TCCR3A,WGMA1);00415 sbi(TCCR3A,WGMA0);00416 }00417 <span class="keywordflow">else</span>00418 { <span class="comment">// default 8bit mode</span>00419 cbi(TCCR3A,WGMA1);00420 sbi(TCCR3A,WGMA0);00421 }00422 00423 <span class="comment">// set clear-timer-on-compare-match</span>00424 <span class="comment">//cbi(TCCR3B,CTC1);</span>00425 <span class="comment">// clear output compare value A</span>00426 outb(OCR3AH, 0);00427 outb(OCR3AL, 0);00428 <span class="comment">// clear output compare value B</span>00429 outb(OCR3BH, 0);00430 outb(OCR3BL, 0);00431 <span class="comment">// clear output compare value B</span>00432 outb(OCR3CH, 0);00433 outb(OCR3CL, 0);00434 }00435 <a name="l00436"></a><a class="code" href="timer128_8h.html#a72">00436</a> <span class="keywordtype">void</span> <a class="code" href="timer128_8h.html#a72">timer3PWMInitICR</a>(u16 topcount)00437 {00438 <span class="comment">// set PWM mode with ICR top-count</span>00439 cbi(TCCR3A,WGM30);00440 sbi(TCCR3A,WGM31);00441 sbi(TCCR3B,WGM32);00442 sbi(TCCR3B,WGM33);00443 00444 <span class="comment">// set top count value</span>00445 ICR3H = (u08)(topcount>>8);00446 ICR3L = (u08)topcount;00447 00448 <span class="comment">// clear output compare value A</span>00449 outb(OCR3AH, 0);00450 outb(OCR3AL, 0);00451 <span class="comment">// clear output compare value B</span>00452 outb(OCR3BH, 0);00453 outb(OCR3BL, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -