cepintimer.c

来自「基于AVR平台」· C语言 代码 · 共 68 行

C
68
字号
//cepinTimer.c : source file for the cepin Timers
//

#include "cepin.h"
#include "cepinTimer.h"

/////////////////////////////////////////////////////////////////////////////
//cepinTimer

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: 8000.000kHz
	// Timer/Counter1 Mode: Normal
	// Timer/Counter1 Output: A: Disconnected, B: Disconnected
	OCR1A = 0x0000;
	OCR1B = 0x0000;
	TCNT1 = 0x0000;
	TCCR1A = 0x00;
	TCCR1B = 0x42;//上升沿捕捉,8分频

	// 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 = 0x65;
	//}}WIZARD_MAP(Timers)
}

SIGNAL(SIG_INPUT_CAPTURE1)
{
	uint f1,f2;
	extern uint f3;
	// TODO: Add your code here
	f1=ICR1;
	if(f1 >= f2)
		f3=f1-f2;
	else
		f3=0xffff-f2+f1;
	f2=f1;
}

SIGNAL(SIG_OUTPUT_COMPARE2)
{
	// TODO: Add your code here
	
}

SIGNAL(SIG_OVERFLOW1)
{
	// TODO: Add your code here
	TCNT1=0x0000;
}

⌨️ 快捷键说明

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