📄 pulse_8c-source.html
字号:
00144 }00145 00146 <span class="keywordtype">void</span> pulseT1BRun(u16 nPulses)00147 {00148 <span class="comment">// set the number of pulses we want and the mode</span>00149 <span class="keywordflow">if</span>(nPulses)00150 {00151 <span class="comment">// if the nPulses is non-zero, use "counted" mode</span>00152 PulseT1BMode |= PULSE_MODE_COUNTED;00153 PulseT1BCount = nPulses<<1;00154 }00155 <span class="keywordflow">else</span>00156 {00157 <span class="comment">// if nPulses is zero, run forever</span>00158 PulseT1BMode &= ~PULSE_MODE_COUNTED;00159 PulseT1BCount = 1<<1;00160 }00161 <span class="comment">// set OutputCompare action to toggle OC1B pin</span>00162 <span class="comment">// (note: with all the A's and B's flying around, TCCR1A is not a bug)</span>00163 cbi(TCCR1A,COM1B1);00164 sbi(TCCR1A,COM1B0);00165 00166 <span class="comment">// now the "enabling" stuff</span>00167 00168 <span class="comment">// set the output compare one pulse cycle ahead of current timer position </span>00169 <span class="comment">// to make sure we don't have to wait until the timer overflows and comes</span>00170 <span class="comment">// back to the current value</span>00171 <span class="comment">// set future output compare time to TCNT1 + PulseT1APeriodTics</span>00172 <span class="comment">//outw(OCR1B, inw(TCNT1) + PulseT1BPeriodTics);</span>00173 OCR1B += PulseT1BPeriodTics;00174 00175 <span class="comment">// enable OutputCompare interrupt</span>00176 sbi(TIMSK, OCIE1B);00177 }00178 00179 <span class="keywordtype">void</span> pulseT1AStop(<span class="keywordtype">void</span>)00180 {00181 <span class="comment">// stop output regardless of remaining pulses or mode</span>00182 <span class="comment">// go to "counted" mode</span>00183 PulseT1AMode |= PULSE_MODE_COUNTED;00184 <span class="comment">// set pulses to zero</span>00185 PulseT1ACount = 0;00186 }00187 00188 <span class="keywordtype">void</span> pulseT1BStop(<span class="keywordtype">void</span>)00189 {00190 <span class="comment">// stop output regardless of remaining pulses or mode</span>00191 <span class="comment">// go to "counted" mode</span>00192 PulseT1BMode |= PULSE_MODE_COUNTED;00193 <span class="comment">// set pulses to zero</span>00194 PulseT1BCount = 0;00195 }00196 00197 u16 pulseT1ARemaining(<span class="keywordtype">void</span>)00198 {00199 <span class="comment">// return the number of pulses remaining for channel A</span>00200 <span class="comment">// add 1 to make sure we round up, >>1 equivalent to /2</span>00201 <span class="keywordflow">return</span> (PulseT1ACount+1)>>1;00202 }00203 00204 u16 pulseT1BRemaining(<span class="keywordtype">void</span>)00205 {00206 <span class="comment">// return the number of pulses remaining for channel A</span>00207 <span class="comment">// add 1 to make sure we round up, >>1 equivalent to /2</span>00208 <span class="keywordflow">return</span> (PulseT1BCount+1)>>1;00209 }00210 00211 <span class="keywordtype">void</span> pulseT1AService(<span class="keywordtype">void</span>)00212 {00213 <span class="comment">// check if TimerPulseACount is non-zero</span>00214 <span class="comment">// (i.e. pulses are still requested)</span>00215 <span class="keywordflow">if</span>(PulseT1ACount)00216 {00217 <span class="comment">//u16 OCValue;</span>00218 <span class="comment">// read in current value of output compare register OCR1A</span>00219 <span class="comment">//OCValue = inp(OCR1AL); // read low byte of OCR1A</span>00220 <span class="comment">//OCValue += inp(OCR1AH)<<8; // read high byte of OCR1A</span>00221 <span class="comment">// increment OCR1A value by PulseT1APeriodTics</span>00222 <span class="comment">//OCValue += PulseT1APeriodTics;</span>00223 <span class="comment">// set future output compare time to this new value</span>00224 <span class="comment">//outp((OCValue>>8), OCR1AH); // write high byte</span>00225 <span class="comment">//outp((OCValue & 0x00FF),OCR1AL); // write low byte</span>00226 00227 <span class="comment">// the following line should be identical in operation</span>00228 <span class="comment">// to the lines above, but for the moment, I'm not convinced</span>00229 <span class="comment">// this method is bug-free. At least it's simpler!</span>00230 <span class="comment">//outw(OCR1A, inw(OCR1A) + PulseT1APeriodTics);</span>00231 <span class="comment">// change again</span>00232 OCR1A += PulseT1APeriodTics;00233 00234 <span class="comment">// decrement the number of pulses executed</span>00235 <span class="keywordflow">if</span>(PulseT1AMode & PULSE_MODE_COUNTED)00236 PulseT1ACount--;00237 }00238 <span class="keywordflow">else</span>00239 {00240 <span class="comment">// pulse count has reached zero</span>00241 <span class="comment">// disable the output compare's action on OC1A pin</span>00242 cbi(TCCR1A,COM1A1);00243 cbi(TCCR1A,COM1A0);00244 <span class="comment">// and disable the output compare's interrupt to stop pulsing</span>00245 cbi(TIMSK, OCIE1A);00246 }00247 }00248 00249 <span class="keywordtype">void</span> pulseT1BService(<span class="keywordtype">void</span>)00250 {00251 <span class="comment">// check if TimerPulseACount is non-zero</span>00252 <span class="comment">// (i.e. pulses are still requested)</span>00253 <span class="keywordflow">if</span>(PulseT1BCount)00254 {00255 <span class="comment">//u16 OCValue;</span>00256 <span class="comment">// read in current value of output compare register OCR1B</span>00257 <span class="comment">//OCValue = inp(OCR1BL); // read low byte of OCR1B</span>00258 <span class="comment">//OCValue += inp(OCR1BH)<<8; // read high byte of OCR1B</span>00259 <span class="comment">// increment OCR1B value by PulseT1BPeriodTics</span>00260 <span class="comment">//OCValue += PulseT1BPeriodTics; </span>00261 <span class="comment">// set future output compare time to this new value</span>00262 <span class="comment">//outp((OCValue>>8), OCR1BH); // write high byte</span>00263 <span class="comment">//outp((OCValue & 0x00FF),OCR1BL); // write low byte</span>00264 00265 <span class="comment">// the following line should be identical in operation</span>00266 <span class="comment">// to the lines above, but for the moment, I'm not convinced</span>00267 <span class="comment">// this method is bug-free. At least it's simpler!</span>00268 <span class="comment">//outw(OCR1B, inw(OCR1B) + PulseT1BPeriodTics);</span>00269 <span class="comment">// change again</span>00270 OCR1B += PulseT1BPeriodTics;00271 00272 00273 <span class="comment">// decrement the number of pulses executed</span>00274 <span class="keywordflow">if</span>(PulseT1BMode & PULSE_MODE_COUNTED)00275 PulseT1BCount--;00276 }00277 <span class="keywordflow">else</span>00278 {00279 <span class="comment">// pulse count has reached zero</span>00280 <span class="comment">// disable the output compare's action on OC1B pin</span>00281 cbi(TCCR1A,COM1B1);00282 cbi(TCCR1A,COM1B0);00283 <span class="comment">// and disable the output compare's interrupt to stop pulsing</span>00284 cbi(TIMSK, OCIE1B);00285 }00286 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:55 2005 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -