📄 timer.h
字号:
/*
** timer.h
**
** Written by Peter Sutton - October 2004
**
** Notes:
** 1. global interrupts must be enabled for timing to happen.
** 2. The implementation uses AVR Timer 0 (the 8 bit timer)
** 3. Integers are used to store millisecond values. The maximum
** time that can be expressed is therefore about 65 seconds.
*/
#include <inttypes.h>
/*
** The time variable counts milliseconds (in multiples of 10) from 0
** up to our timer period (when it is reset to 0). The variable can be
** read if desired, but should not be written outside the timer module.
*/
extern volatile unsigned int time;
/*
** Initialise timer 0 - which provides our regular timebase. Global
** interrupts must be enabled for this to work. The timer will count
** up to the given number of milliseconds (in multiples of 10 - the
** period should also be a multiple of 10) and then start counting
** from 0 again.
**
** You can use the is_period_over() function to regularly monitor
** whether the period has finished.
*/
void init_timer(unsigned int period);
/*
** Returns true if the timer period has been completed since the
** last call to is_period_over() or init_timer(). init_timer()
** must have been called to set up the timer.
*/
int8_t is_period_over(void);
/*
** Wait until the end of the current period. This procedure will
** not return until the given time has passed. Global interrupts
** must be enabled for this to work. (The function will return
** immediately if global interrupts are disabled.) init_timer()
** must hav ebeen called to set up the timer before this function
** is called.
*/
void sleep_until_period_over(void);
/*
** Wait for the given number of milliseconds. This procedure will
** not return until the given time has passed. Global interrupts
** must be enabled for this to work. (The function will return
** immediately if global interrupts are disabled.) init_timer() must
** have been called to set up the timer before this function is
** called. The given delay should be a multiple of 10 milliseconds.
** The value here can be less than, equal to, or greater than the
** period.
*/
void sleep(unsigned int delay_milliseconds);
/*
** Stop the timer - it will continue where it left off when restarted.
** (Has no effect if counting is already paused.)
*/
void pause_timer(void);
/*
** Continue counting (subject to global interrupts being enabled)
** (Has no effect if counting is happening.)
*/
void restart_timer(void);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -