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

📄 tick.c

📁 motorola jw32 usb 源码
💻 C
字号:
/*********************************************************************
 *
 *                  MFT MAC layer
 *
 *********************************************************************
 * FileName:        mftMAC.c
 * Dependencies:
 * Processor:       c51
 * Company:         chengdu MFT, Inc.
 *
 * Software License Agreement
 *
 *
 * Author               Date    Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * jiangchao    				5/09/05 Rel 0.1
 ********************************************************************/




#define TICK_TEMP_VALUE_1   ( (CLOCK_FREQ/TICKS_PER_SECOND) / TICK_PRESCALE_VALUE )

#if TICK_TEMP_VALUE_1 > 60000
#error TICK_PER_SECOND value cannot be programmed with current _CLOCK_FREQ_
#error Either lower TICK_PER_SECOND or manually configure the Timer
#endif

#define TICK_TEMP_VALUE         0x3E8//1000//(65535 - TICK_TEMP_VALUE_1)

#define TICK_COUNTER_HIGH       0x03//((TICK_TEMP_VALUE >> 8) & 0xff)
#define TICK_COUNTER_LOW        0xE8//(TICK_TEMP_VALUE & 0xff)


TICK TickCount=0;

//TICK TickSecond=0;
/*********************************************************************
 * Function:        void TickInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Tick manager is initialized.
 *
 * Side Effects:    None
 *
 * Overview:        Initializes Timer0 as a tick counter.
 *
 * Note:            None
 ********************************************************************/
void TickInit(void)
{
    // Start the timer.
    T1SC = 0x73;  /*  Timer 1 -  TSTOP=1 TRST=1 */
  	T1MODH = TICK_COUNTER_HIGH; /*  Modulo value set to create 125us overflow - interrupt  */
  	T1MODL = TICK_COUNTER_LOW;
    T1SC = 0x43;	 /*  Timer 1 - TOIE=1 TSTOP=0 TRST=0 */
    TickCount = 0x00;           /*  Prescaler 8 BUS Cycles, 6MHz - 1.33uS	*/
 //    TickSecond = 0x00;

}

/*********************************************************************
 * Function:        TICK TickGet(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          Current second value is given
 *
 * Side Effects:    None
 *
 * Overview:        None
 *
 * Note:            None
 ********************************************************************/
TICK TickGet(void)
{
   // TICK tempTick;
		//TSC1_CHxIE =0;
   // tempTick = TickCount;
 		//TSC1_CHxIE =1 ;
    return TickCount;
}
/*
TICK TickGetSecond(void)
{
	  return TickSecond;
}*/
/*********************************************************************
 * Function:       void TickClear(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:         none
 *
 * Side Effects:    None
 *
 * Overview:        None
 *
 * Note:            clear system tick
 ********************************************************************/
/*void TickClear(void)
{
	TSC1_CHxIE =0;
    TickCount= 0x00;
 	TSC1_CHxIE =1 ;
}*/
/*********************************************************************
 * Macro:           TickGetDiff(current, previous)
 *
 * PreCondition:    None
 *
 * Input:           current - Current tick count
 *                  previous - Previous tick count
 *
 * Output:          Different of two
 *
 * Side Effects:    None
 *
 * Overview:        Calculates tick difference.
 *
 * Note:            None
 ********************************************************************/
TICK  TickGetDiff(TICK current, TICK previous)
{

	TICK temp;														 
//	DisableInterrupts;
	if(current>=previous)
	{
	  temp 	 =  current-previous;
	}
	else												 
	{

  //     PTD_PTD4^=1;
	    temp=(0xfffe-previous)+current;
	}
	//EnableInterrupts;
	//if(temp>=0x100)
	//		return 0xff;
//	else
	  return   temp;
}

                
                
/*********************************************************************
 * Function:        void TickUpdate(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Internal Tick and Seconds count are updated.
 *
 * Note:            None
 ********************************************************************/
void TickUpdate(void)
{
		BYTE tsc;
    TickCount++;
    tsc = T1SC;
    tsc &= 0x7F;
    //tsc &= 0x43;
    T1SC = tsc;
}
/*********************************************************************
 * Function:       void delayms(BYTE delayms)
 *
 *
 * Input:           delayms:delay time unit ms
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Internal Tick and Seconds count are updated.
 *
 * Note:            None
 ********************************************************************/
void delayms(BYTE delayms)
{
 	  unsigned char i ;
 	  unsigned int j;
 	  for(i=0;i<delayms;i++) {

           
		   __RESET_WATCHDOG();
     	   for(j=0;j<250;j++) {


     	   }
 	  }

}


⌨️ 快捷键说明

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