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

📄 timer.c

📁 单片机中的定时器模块
💻 C
字号:

#include <macros.h>
#include "stdtypes.h"
#include "timer.h"



UNS8 time_couter;


//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value:  0.998mSec (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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -