timer._c
来自「单片机中的定时器模块」· _C 代码 · 共 47 行
_C
47 行
#include <macros.h>
#include "stdtypes.h"
#include "timer.h"
UNS8 time_couter;
//TIMER0 initialize - prescale:256
// WGM: Normal
// desired value: 10mSec
// actual value: 9.984mSec (0.2%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = SET_COUNT; //set count
TCCR0 = 0x07; //start timer
TIMSK = TIMSK | (1 << TOIE0);
time_couter=0;
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
//CLI(); //disable all interrupts
TCNT0 = SET_COUNT;
/*read the key value*/
if(time_couter>10)
{
time_couter=0;
}
else
{
time_couter++;
}
// SEI(); //re-enable interrupts
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?