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

📄 delay_ms.c

📁 详细介绍了一篇关于pci开发的接口芯片
💻 C
字号:
/*
	delay_ms.c

	Uses tcint8.c source from pctime13 as a ms-resolution timer.
*/

#include <stdtypes.h>
#include <stdlib.h>
#include <time.h>
#include <sys\timeb.h>
#include <tcint70.h>

// use pctime stuff if defined...
#define USE_PCINT70 1


int timer_init_flag = 0;
/* 	timer_init_flag is used to tell if caller has ever initialized
	the ms-resolution timer. If not, we will do it here and
	then release it on exit. If it HAS been set, the caller
	must call "quit8()" before exiting his program.

	EXAMPLE STARTUP CODE:

	// set up ms resolution timer...
	timer_init_flag = 1;
	init8h( 1000 );
	ticks_8h = 0L;
	atexit( quit8h );

	init70h();
	atexit( quit70h );

*/

VOID delay_ms( UINT16 delay )
/*
	Intercepts timer, SEE NOTES ABOVE!
*/
{
#ifndef USE_PCINT70
	// do standard ms delay using crappy 18/sec tick...
	struct timeb start, now;
	short time1, time2;

	ftime ( &start );
	time2  = 1000 - start.millitm;	// #ms to next second 
	// add ms/tick to guarantee at least the requested delay
	delay += 60;
	while ( 1 )
	{
		ftime ( &now );
		if ( start.time == now.time ) 	// seconds the same...
			time1 = now.millitm - start.millitm;
		else
			time1 = time2 + (short)((now.time - start.time) * 1000) + \
				now.millitm;
		if ( time1 > delay ) break;
	}


#else
	if ( !timer_init_flag )
	{
		init70h();
		atexit ( quit70h );
		timer_init_flag = 1;
	}

	// add 1ms tick to guarantee at least the requested delay
	delay++;
	delay70h( delay );
#endif

}

⌨️ 快捷键说明

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