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

📄 timer.c

📁 LV4137显示驱动,自己做的,比较简单,但很实用,MCU用的是Myson MTV512,Keil下编译
💻 C
字号:
//----------------------------------------------------------------------------------------------------
// ID Code      : Timer.c No.0000
// Update Note  : 
//
//----------------------------------------------------------------------------------------------------

#define __TIMER__

#include "Header\Include.h"

//--------------------------------------------------
// Description  : Hold program for 0 ~ 65535 ms
// Input Value  : usNum     --> Delay time
// Output Value : None
//--------------------------------------------------
void CTimerDelayXms(WORD usNum)
{
    if(usNum)
    {
        bNotifyTimer0Int = _FALSE;

        while(_TRUE)
        {
            if(bNotifyTimer0Int)
            {
                bNotifyTimer0Int = _FALSE;

                if(--usNum)
                    TR0 = _ON;
                else
                    return;
            }
        }
    }
}


//--------------------------------------------------
void BitDly(void)
{
    _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
    _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
    _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();	//V310
}

//--------------------------------------------------
// Decrease timer counts while 10ms Interrupt is up.
//--------------------------------------------------
void CTimerDecreaseTimerCnt(void)
{
	BYTE timerdeccnt;

	for (timerdeccnt = 0; timerdeccnt < _MAX_EVENT_AMOUNT; timerdeccnt++) 
    {
		if ((TimerEvent[timerdeccnt].Time != _INACTIVE_TIMER_EVENT) &&
			(TimerEvent[timerdeccnt].Time != 0)) 
        {
			TimerEvent[timerdeccnt].Time--;
		}
	}
}

//--------------------------------------------------
void CTimerReactiveTimerEvent(WORD usTime, void (*Event) (void))
{
	WORD timereventcnt;

	for (timereventcnt = 0;
		timereventcnt < _MAX_EVENT_AMOUNT;
		timereventcnt++) 
    {

		if ((TimerEvent[timereventcnt].Time != _INACTIVE_TIMER_EVENT) &&
			(TimerEvent[timereventcnt].Event == Event)) 
            {
			EA =0;
			TimerEvent[timereventcnt].Time = usTime;
			EA =1;
			return;
		}
	}

	CTimerActiveTimerEvent(usTime, Event);
}


//--------------------------------------------------
void CTimerActiveTimerEvent(WORD usTime, void (*Event) ())
{
	WORD timereventcnt;

	for (timereventcnt = 0;
		timereventcnt < _MAX_EVENT_AMOUNT;
		timereventcnt++) 
        {
		if ((TimerEvent[timereventcnt].Time != _INACTIVE_TIMER_EVENT) &&
			(TimerEvent[timereventcnt].Event == Event))
			return;
	}

	for (timereventcnt = 0;
		timereventcnt < _MAX_EVENT_AMOUNT;
		timereventcnt++) 
    {		
		if (TimerEvent[timereventcnt].Time == _INACTIVE_TIMER_EVENT) 
        {
			EA =0;
			TimerEvent[timereventcnt].Time = usTime;
			EA =1;
			TimerEvent[timereventcnt].Event = Event;
			break;
		}
	}
}

⌨️ 快捷键说明

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