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

📄 timer.c

📁 ucos相关移植的典型代码
💻 C
字号:
#include <ioas.h>
#include "timer.h"
#include "includes.h"

/*****************************************************************************************************                                                                        
*   Function: TimerInit()
*
*   Description: This is the initialization function. This function sets the channel 4 timer to be
*                interrupted every 20 msec (1 tick).                                                                           
*
*   Caveats:
*****************************************************************************************************/ 

void TimerInit(void)
	{
	/* Stop the timer and reset the counter to 0 */
	TSC = TMR_TSTOP | TMR_TRST;

	/* Set the initial modulus for the timer */
	TMODH = (unsigned char)(40000 >> 8);
	TMODL = (unsigned char)(40000);

	/* set interrupt at 20ms */
	TCH4H = (20000 >> 8);
	TCH4L = 20000;

	/* Enable interrupt, Pin under port control, Initial output low */
	TSC4 = TMR_CHIE | TMR_MSXA;
 
	/* Select TIM clock and start timer */
	TSC = TMR_PRESCALER;
	}

/***************************************************************************************************** 
*   Function: TimerISR()
*
*   Description: This is RTOS interrupt handler function that gets called every 20msec.
*
*   Caveats:
*****************************************************************************************************/ 

@interrupt void TimerISR(void)
	{
	unsigned short tmp;
   
    tmp = TCH4H << 8;
    tmp |= TCH4L;

	/* Setup for new output compare value and watch for overflow */
    if ((tmp += 20000) > 40000)
		tmp -= 40000;

    TCH4H = (unsigned char)(tmp >> 8);
    TCH4L = (unsigned char)(tmp);

    while (TSC4 & 0x80)
	    {
    	/* clear the interrupt */
    	TSC4 &= ~0x80;
	    }

	/* Notify uC/OS-II about ISR */
	OSIntNesting++;

	/* Enable interrupts to allow interrupt nesting */
	_asm("cli\n");

	/* Call uC/OS-II's tick updating function */
    OSTimeTick();

	/* Notify uC/OS-II about end of ISR */
    OSIntExit();
	}

⌨️ 快捷键说明

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