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

📄 timer.c

📁 Mp3 Player using ATmega128, VS1003B, Character LCD. Test OK.Good Sound.
💻 C
字号:
// Standard Header files
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

// AVRlib Header files
#include "global.h"
#include "timer.h"

volatile U32 Counter_1ms=0;
U32 Counter_10ms;

U8 bTimerUpdateName;
U8 bTimerKeyLock;
U8 bTimerClearVol;

static U8 led_status=1;
/*

// 1檬付促 惯积窍绰 鸥捞赣 牢磐反飘
SIGNAL(SIG_OUTPUT_COMPARE1A)	// OC1A interrupt function
{
	Counter_sec++;

	if(Counter_sec % 4 == 0)	// 4檬付促 颇老疙 盎脚
		bTimerUpdateName = 1;
}

// 0.01檬付促 惯积窍绰 鸥捞赣 牢磐反飘
SIGNAL(SIG_OUTPUT_COMPARE3A)	// OC3A interrupt function
{
	Counter_10ms++;

	if(Counter_10ms == 30)		// 0.3檬饶 key lock阑 秦力
		bTimerKeyLock = 0;
	
	if(Counter_10ms == 200)		// 2檬饶 杭俘 钎矫甫 瘤框
		bTimerClearVol = 1;
}

*/


// 1ms付促 牢磐反飘 惯积
SIGNAL(SIG_OVERFLOW0)
{
	Counter_1ms++;

	// 弊贰侨 LCD俊 钎矫瞪 颇老疙 诀单捞飘
	if ((Counter_1ms % 2000)==0)
	{
		bTimerUpdateName = 1;
		Counter_1ms=0;
	}

	// Run LED Toggle
	if(Counter_1ms % 1000 == 0)	// 0.5檬 埃拜栏肺 痢戈
	{
		if(led_status == 1)
		{
			cbi(LED_PORT, LED_RUN);
			led_status = 0;
		}
		else if(led_status == 0)
		{
			sbi(LED_PORT, LED_RUN);
			led_status = 1;
		}
	}

	TCNT0 = 0x83;
}


void Timer_Init(void)
{
	cli();

/*
	// TCCR1A Setting
	TCCR1A = 0x00;			// CTC mode(4), don't output OC1A
	TCCR1B = 0x0C;			// 8MHz/256/(1+31249) = 1Hz = 1sec
	TCCR1C = 0x00;
	OCR1AH = (31249 >> 8);
	OCR1AL = 31249 & 0xFF;
	TCNT1H = 0x00;			// clear Timer/Counter1
	TCNT1L = 0x00;


	// TCCR3A Setting
	TCCR3A = 0x00;			// CTC mode(4), don't output OC3A
	TCCR3B = 0x0C;			// 8MHz/256/(1+311) = 100Hz = 10ms
	TCCR1C = 0x00;
	OCR3AH = (311 >> 8);
	OCR3AL = 311 & 0xFF;
	TCNT3H = 0x00;			// clear Timer/Counter3
	TCNT3L = 0x00;
*/

	// Timer0 Overflow
	TCCR0 = 0x04;
	TCNT0 = 0x83;
	TIMSK = 0x01;
	TIFR = 0x00;			// clear all interrupt flags
	 	

/*	

//	TIMSK = 0x10;			// enable OC1A interrupt
	ETIMSK = 0x10;			// enable OC3A interrupt
	TIFR = 0x00;			// clear all interrupt flags
	ETIFR = 0x00;

	Timer_Reset(TIMER_SEC);
	Timer_Reset(TIMER_MS);
*/
	sei();					// global interrupt enable
}

/*
void Timer_Reset(U8 timerType)
{
	if(timerType == TIMER_SEC)
		Counter_sec = 0;
	else if(timerType == TIMER_MS)
		Counter_10ms = 0;
}

struct tagTime TimerGetTime(void)
{
	struct tagTime time;

	time.hour = Counter_sec / 3600;
	time.min = Counter_sec / 60;
	time.sec = Counter_sec % 60;

	return time;
}

void Timer_Enable(U8 timerType)
{
	if(timerType == TIMER_SEC)
		sbi(TIMSK, OCIE1A);
	else if(timerType == TIMER_MS)
		sbi(ETIMSK, OCIE3A);
}

void Timer_Disable(U8 timerType)
{
	if(timerType == TIMER_SEC)
		cbi(TIMSK, OCIE1A);
	else if(timerType == TIMER_MS)
		cbi(ETIMSK, OCIE3A);
}
*/

⌨️ 快捷键说明

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