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