📄 timer_soft.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML><HEAD> <META NAME="GENERATOR" CONTENT="langdoc 1.0.1"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE> timer_soft </TITLE> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="6"> <TR> <TD ALIGN=CENTER VALIGN=MIDDLE BGCOLOR=BLUE> <H1> <FONT COLOR="#FFFFFF"> timer_soft </FONT> </H1> </TD> </TR> </TABLE><P ALIGN=RIGHT> <I> Copyright (c) 2003 Atmel</I> </P><H2> Library Usage </H2><H3> Package Description </H3><H4> Overview </H4>This file contains all functions to manage temporizations and soft time out.The functions use optimized modulo algorithms 8/16bit.<P><PRE>Typical use of:Type: Timer setup: Accuracy: Advised Timeout:bits_t Min/Advised/Max Logical/Phy Std / required__16s 0ms/32s/65s 1ms / tick 33s / > sched_rollover_time__16l 0s/2h20/4h40 256ms 2h20 / >> sched_rollover_time__8s 0ms/127ms/255ms 1ms / tick 127ms / > sched_rollover_time__8l 0ms/32s/65s 256ms 33s / > sched_rollover_time</PRE><P><H4> Configuration </H4>Near plug & play, if Timer0 is free.<P>Available defines:<P>* I_HAVE_SETUP_SOFT_TIMER_TICK (optional)for advanced purpose, for most applications: do not define this value.<P>* FOSC (required)FOSC must be setup to relevant value: Ex.: 11059 for 11.059MHz CrystalDo not care of X2 mode in most of cases.<P><H3> Package Summary </H3><H4> Constants </H4><PRE></PRE><H4> Global Variables </H4><PRE><A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> </PRE><H4> Macros </H4><PRE><A HREF="#set_timerxy">set_timerxy</A> </PRE><H4> Functions </H4><PRE><A HREF="#init_soft_timers">init_soft_timers</A> <A HREF="#reload_TH0">reload_TH0</A> <A HREF="#tempo">tempo</A> <A HREF="#Timer0_interrupt">Timer0_interrupt</A> </PRE><H3> Files List </H3><UL><LI><B><A NAME="timer_soft.c"></A> timer_soft.c</B><BR></LI><UL>This file controls the temporizations of the application. The tempo value is a define symbol in c51_time.h file. The oscillator value is a parameter in c51_time.h file.</UL><LI><B><A NAME="timer_soft.h"></A> timer_soft.h</B><BR></LI><UL>Macro definition for soft timers. Note that the standard unit for time is the millisecond (ms). Typical use of: Type: Timer setup: Accuracy: Advised Timeout: bits_t Min/Advised/Max Logical/Phy Std / required __16s 0ms/32s/65s 1ms / tick 33s / > sched_rollover_time __16l 0s/2h20/4h40 256ms 2h20 / >> sched_rollover_time __8s 0ms/127ms/255ms 1ms / tick 127ms / > sched_rollover_time __8l 0ms/32s/65s 256ms 33s / > sched_rollover_time</UL></UL><H3> Included Files </H3><UL><LI><B>config.h </B><BR></LI><LI><B><A HREF="#timer_soft.h">timer_soft.h</A> </B><BR></LI></UL><H2> Types Description </H2><UL><LI><B><A NAME="Timer"></A> Timer</B><BR></LI><UL><PRE>Uint16 </PRE></UL><LI><B><A NAME="Timer8"></A> Timer8</B><BR></LI><UL><PRE>Uint8 </PRE></UL><LI><B><A NAME="Timer8l"></A> Timer8l</B><BR></LI><UL><PRE>Uint8 </PRE></UL><LI><B><A NAME="Timer8s"></A> Timer8s</B><BR></LI><UL><PRE>Uint8 </PRE></UL><LI><B><A NAME="Timer16"></A> Timer16</B><BR></LI><UL><PRE>Uint16 </PRE></UL><LI><B><A NAME="Timer16l"></A> Timer16l</B><BR></LI><UL><PRE>Uint16 </PRE></UL><LI><B><A NAME="Timer16s"></A> Timer16s</B><BR></LI><UL><PRE>Uint16 </PRE></UL></UL><H2> Constant Macros </H2><H2> Global Variables </H2><A NAME="gl_soft_timer_tick"></A><H3> gl_soft_timer_tick </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>volatile Uint32 data <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> </PRE></TD></TABLE><P>Number of ms since mcu reset.This variable is used by soft timers, it must be updated periodically (usuallyby timer interrupt routine).<P><HR><H2> Function Macros </H2><A NAME="set_timerxy"></A><H3> set_timerxy </H3><TABLE BORDER="0" WIDTH="100 %" BGCOLOR="#D6E8FF" CELLPADDING="6"><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer16s ( delay ) ( ( Uint16 ) ( delay ) + ( Uint16 ) <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer16l ( delay ) ( ( Uint16 ) ( ( delay ) >>8 ) + ( Uint16 ) ( gl_soft_timer_tick>>8 ) +1 ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer8s ( delay ) ( ( Uint8 ) ( delay ) + ( Uint8 ) <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer8l ( delay ) ( ( Uint8 ) ( ( delay ) >>8 ) + ( Uint8 ) ( gl_soft_timer_tick>>8 ) + ( Uint8 ) 1 ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer ( delay ) set_timer16s ( delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer16 ( delay ) set_timer16s ( delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define set_timer8 ( delay ) set_timer8s ( delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE></PRE></TD><TR> <TD VALIGN=MIDDLE><PRE></PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>/ * M * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * NAME: timeoutxy </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * PARAMS: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * timer: variable used for timer , type xy </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * delay: delay in ms </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * return: TRUE if timeout , FALSE anyelse. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * PURPOSE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Test if a timeout occurs on a timer. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * x=8 or 16 or nothing for default ( number of bits of the variable , default=16 ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * y=s for short or l for long or nothing for default ( default=short ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * EXAMPLE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * if ( timeout ( my_timer , TIMER_1_S ) ) // action </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * else // wait </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * NOTE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Use ( x-1 ) bits value for a correct usage of soft timers. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Be careful that scheduler roll over must be shortest than 2^ ( x-1 ) ms. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * This function is more accurate than std_timeoutxy but the speed is lower. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * REQUIREMENTS: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * The <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> must be updated correctly , according crystal & x2 mode </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout16s ( timer , delay ) ( ( ( ( Uint16 ) ( timer ) - ( Uint16 ) <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> ) <= ( Uint16 ) ( delay ) ) ?FALSE:TRUE ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout16l ( timer , delay ) ( ( ( ( Uint16 ) ( timer ) - ( Uint16 ) ( gl_soft_timer_tick>>8 ) ) <= ( Uint16 ) ( ( delay ) >>8 ) ) ?FALSE:TRUE ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout8s ( timer , delay ) ( ( ( ( Uint8 ) ( timer ) - ( Uint8 ) <A HREF="#gl_soft_timer_tick">gl_soft_timer_tick</A> ) <= ( Uint8 ) ( delay ) ) ?FALSE:TRUE ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout8l ( timer , delay ) ( ( ( ( Uint8 ) ( timer ) - ( Uint8 ) ( gl_soft_timer_tick>>8 ) ) <= ( Uint8 ) ( ( delay ) >>8 ) ) ?FALSE:TRUE ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout ( timer , delay ) timeout16s ( timer , delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout16 ( timer , delay ) timeout16s ( timer , delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>#define timeout8 ( timer , delay ) timeout8s ( timer , delay ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE></PRE></TD><TR> <TD VALIGN=MIDDLE><PRE>/ * M * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * NAME: std_timeoutxy </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * PARAMS: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * timer: variable used for timer , type xy </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * return: TRUE if timeout , FALSE anyelse. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * PURPOSE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Test if a timeout occurs on a timer. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * x=8 or 16 or nothing for default ( number of bits of the variable , default=16 ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * y=s for short or l for long or nothing for default ( default=short ) </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * EXAMPLE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * if ( std_timeout ( my_timer ) ) // action </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * else // wait </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * ---------------------------------------------------------------------------- </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * NOTE: </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Use ( x-1 ) bits value for a correct usage of soft timers. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * Be careful that scheduler roll over must be shortest than 2^ ( x-1 ) ms. </PRE></TD><TR> <TD VALIGN=MIDDLE><PRE> * </PRE></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -