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

📄 测频timer.c

📁 基于AVR平台
💻 C
字号:
//测频Timer.c : source file for the 测频 Timers
//

#include "测频.h"
#include "测频Timer.h"

/////////////////////////////////////////////////////////////////////////////
//测频Timer

void timers_init(void)
{
	//{{WIZARD_MAP(Timers)
	// Timer/Counter0 Clock source: System Clock
	// Timer/Counter0 Clock value: Stopped
	// Timer/Counter0 Mode: Normal
	// Timer/Counter0 Output: Disconnected
	OCR0 = 0x00;
	TCNT0 = 0x00;
	TCCR0 = 0x00;

	// Timer/Counter1 Clock source: System Clock
	// Timer/Counter1 Clock value: Stopped
	// Timer/Counter1 Mode: Normal
	// Timer/Counter1 Output: A: Disconnected, B: Disconnected
	OCR1A = 0x0000;
	OCR1B = 0x0000;
	TCNT1 = 0x0000;
	TCCR1A = 0x00;
	TCCR1B = 0x42;//位6――ICES1:输入捕获触发方式选择ICES1=0时,外部引脚ICP1上逻电辑平上升电沿触发一次输入捕获
                  //ICES1=1时,外部引脚ICP1上逻辑电平变化的上升沿触发一次输入捕获。
	// Timer/Counter2 Clock source: System Clock
	// Timer/Counter2 Clock value: Stopped
	// Timer/Counter2 Mode: Normal
	// Timer/Counter2 Output: Disconnected
	ASSR = 0x00;
	OCR2 = 0x00;
	TCNT2 = 0x00;
	TCCR2 = 0x00;

	TIMSK = 0x04;
	//}}WIZARD_MAP(Timers)
}

SIGNAL(SIG_OVERFLOW1)
{
	extern uchar fb;
	// TODO: Add your code here
	TCNT1 = 0x0000;
	if (fb < 3)//fb的值只有两种可能:是0或是1,此处对其判断为2,只是为了放宽了条件,3没有理论意义
	{
		fb++;
	}
}

⌨️ 快捷键说明

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