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

📄 timer_8h-source.html

📁 avr应用测试程序
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: timer.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>timer.h</h1><a href="timer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file timer.h \brief System Timer function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'timer.h'</span>00005 <span class="comment">// Title        : System Timer function library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2000-2002</span>00007 <span class="comment">// Created      : 11/22/2000</span>00008 <span class="comment">// Revised      : 02/10/2003</span>00009 <span class="comment">// Version      : 1.1</span>00010 <span class="comment">// Target MCU   : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs  : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// This code is distributed under the GNU Public License</span>00014 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span><span class="comment"></span>00016 <span class="comment">/// \ingroup driver_avr</span>00017 <span class="comment">/// \defgroup timer Timer Function Library (timer.c)</span>00018 <span class="comment">/// \code #include "timer.h" \endcode</span>00019 <span class="comment">/// \par Overview</span>00020 <span class="comment">///     This library provides functions for use with the timers internal</span>00021 <span class="comment">///     to the AVR processors.  Functions include initialization, set prescaler,</span>00022 <span class="comment">///     calibrated pause function (in milliseconds), attaching and detaching of</span>00023 <span class="comment">///     user functions to interrupts, overflow counters, PWM. Arbitrary</span>00024 <span class="comment">///     frequency generation has been moved to the Pulse Library.</span>00025 <span class="comment">///</span>00026 <span class="comment">/// \par About Timers</span>00027 <span class="comment">///     The Atmel AVR-series processors each contain at least one</span>00028 <span class="comment">///     hardware timer/counter.  Many of the processors contain 2 or 3</span>00029 <span class="comment">///     timers.  Generally speaking, a timer is a hardware counter inside</span>00030 <span class="comment">///     the processor which counts at a rate related to the main CPU clock</span>00031 <span class="comment">///     frequency.  Because the counter value increasing (counting up) at</span>00032 <span class="comment">///     a precise rate, we can use it as a timer to create or measure </span>00033 <span class="comment">///     precise delays, schedule events, or generate signals of a certain</span>00034 <span class="comment">///     frequency or pulse-width.</span>00035 <span class="comment">/// \par</span>00036 <span class="comment">///     As an example, the ATmega163 processor has 3 timer/counters.</span>00037 <span class="comment">///     Timer0, Timer1, and Timer2 are 8, 16, and 8 bits wide respectively.</span>00038 <span class="comment">///     This means that they overflow, or roll over back to zero, at a</span>00039 <span class="comment">///     count value of 256 for 8bits or 65536 for 16bits.  A prescaler is</span>00040 <span class="comment">///     avaiable for each timer, and the prescaler allows you to pre-divide</span>00041 <span class="comment">///     the main CPU clock rate down to a slower speed before feeding it to</span>00042 <span class="comment">///     the counting input of a timer.  For example, if the CPU clock</span>00043 <span class="comment">///     frequency is 3.69MHz, and Timer0's prescaler is set to divide-by-8,</span>00044 <span class="comment">///     then Timer0 will "tic" at 3690000/8 = 461250Hz.  Because Timer0 is</span>00045 <span class="comment">///     an 8bit timer, it will count to 256 in just 256/461250Hz = 0.555ms.</span>00046 <span class="comment">///     In fact, when it hits 255, it will overflow and start again at</span>00047 <span class="comment">///     zero.  In this case, Timer0 will overflow 461250/256 = 1801.76</span>00048 <span class="comment">///     times per second.</span>00049 <span class="comment">/// \par</span>00050 <span class="comment">///     Timer0 can be used a number of ways simultaneously.  First, the</span>00051 <span class="comment">///     value of the timer can be read by accessing the CPU register \c TCNT0.</span>00052 <span class="comment">///     We could, for example, figure out how long it takes to execute a</span>00053 <span class="comment">///     C command by recording the value of \c TCNT0 before and after</span>00054 <span class="comment">///     execution, then subtract (after-before) = time elapsed.  Or we can</span>00055 <span class="comment">///     enable the overflow interrupt which goes off every time T0</span>00056 <span class="comment">///     overflows and count out longer delays (multiple overflows), or</span>00057 <span class="comment">///     execute a special periodic function at every overflow.</span>00058 <span class="comment">/// \par</span>00059 <span class="comment">///     The other timers (Timer1 and Timer2) offer all the abilities of</span>00060 <span class="comment">///     Timer0 and many more features.  Both T1 and T2 can operate as</span>00061 <span class="comment">///     general-purpose timers, but T1 has special hardware allowing it to</span>00062 <span class="comment">///     generate PWM signals, while T2 is specially designed to help count</span>00063 <span class="comment">///     out real time (like hours, minutes, seconds).  See the</span>00064 <span class="comment">///     Timer/Counter section of the processor datasheet for more info.</span>00065 <span class="comment">///</span>00066 <span class="comment"></span><span class="comment">//*****************************************************************************</span><span class="comment"></span>00067 <span class="comment">//@{</span>00068 <span class="comment"></span>00069 <span class="preprocessor">#ifndef TIMER_H</span>00070 <span class="preprocessor"></span><span class="preprocessor">#define TIMER_H</span>00071 <span class="preprocessor"></span>00072 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00073 00074 <span class="comment">// constants/macros/typdefs</span>00075 00076 <span class="comment">// processor compatibility fixes</span>00077 <span class="preprocessor">#ifdef __AVR_ATmega323__</span>00078 <span class="preprocessor"></span>    <span class="comment">// redefinition for the Mega323</span>00079 <span class="preprocessor">    #define CTC1    CTC10</span>00080 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00081 <span class="preprocessor"></span><span class="preprocessor">#ifndef PWM10</span>00082 <span class="preprocessor"></span>    <span class="comment">// mega128 PWM bits</span>00083 <span class="preprocessor">    #define PWM10   WGM10</span>00084 <span class="preprocessor"></span><span class="preprocessor">    #define PWM11   WGM11</span>00085 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00086 <span class="preprocessor"></span>00087 00088 <span class="comment">// Timer/clock prescaler values and timer overflow rates</span>00089 <span class="comment">// tics = rate at which the timer counts up</span>00090 <span class="comment">// 8bitoverflow = rate at which the timer overflows 8bits (or reaches 256)</span>00091 <span class="comment">// 16bit [overflow] = rate at which the timer overflows 16bits (65536)</span>00092 <span class="comment">// </span>00093 <span class="comment">// overflows can be used to generate periodic interrupts</span>00094 <span class="comment">//</span>00095 <span class="comment">// for 8MHz crystal</span>00096 <span class="comment">// 0 = STOP (Timer not counting)</span>00097 <span class="comment">// 1 = CLOCK        tics= 8MHz          8bitoverflow= 31250Hz       16bit= 122.070Hz</span>00098 <span class="comment">// 2 = CLOCK/8      tics= 1MHz          8bitoverflow= 3906.25Hz     16bit=  15.259Hz</span>00099 <span class="comment">// 3 = CLOCK/64     tics= 125kHz        8bitoverflow=  488.28Hz     16bit=   1.907Hz</span>00100 <span class="comment">// 4 = CLOCK/256    tics= 31250Hz       8bitoverflow=  122.07Hz     16bit=  0.477Hz</span>00101 <span class="comment">// 5 = CLOCK/1024   tics= 7812.5Hz      8bitoverflow=   30.52Hz     16bit=   0.119Hz</span>00102 <span class="comment">// 6 = External Clock on T(x) pin (falling edge)</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -