MFC 中怎么实现微秒级的延时
2012-10-12 11:24
471 查看
转自百度文库:
DelayUs
如果你看懂了上述函数,还可以用它里面的部分代码来测试很多函数的执行时间。
当然,这个函数还是有点隐患,如果在一个延时期间,定时器溢出,那么这个值就有可能不准,需要你小心处理。
如:if (dfMinus < 0)
break;
这个假设硬件定时器是以增加的方式计数的。
DelayUs
void DelayUs(int uDelay) { LARGE_INTEGER litmp; LONGLONG QPart1,QPart2; double dfMinus,dfFreq,dfTim; /* Pointer to a variable that the function sets, in counts per second, to the current performance-counter frequency. If the installed hardware does not support a high-resolution performance counter, the value passed back through this pointer can be zero. */ QueryPerformanceFrequency(&litmp); dfFreq = (double)litmp.QuadPart; /* Pointer to a variable that the function sets, in counts, to the current performance-counter value. */ QueryPerformanceCounter(&litmp); QPart1 = litmp.QuadPart; do { QueryPerformanceCounter(&litmp); QPart2 = litmp.QuadPart; dfMinus = (double)(QPart2-QPart1); dfTim = dfMinus/dfFreq; }while(dfTim<0.000001 * uDelay); }
如果你看懂了上述函数,还可以用它里面的部分代码来测试很多函数的执行时间。
当然,这个函数还是有点隐患,如果在一个延时期间,定时器溢出,那么这个值就有可能不准,需要你小心处理。
如:if (dfMinus < 0)
break;
这个假设硬件定时器是以增加的方式计数的。
相关文章推荐
- 如图所示的界面用MFC 怎么设计实现
- 用QueryPerformanceCounter实现Windows XP 下微秒级延时
- QueryPerformanceCounter实现Windows微秒级延时
- MFC延时功能GetTickCount的实现
- QueryPerformanceCounter实现Windows微秒级延时
- 在MFC编程中怎么实现对话框的伸缩
- 怎么用MFC实现浏览器收藏的功能
- STM32Cubemx下实现通用定时器微秒级延时
- 怎么用MFC实现换行
- [转]windows下实现微秒级的延时
- windows下实现微秒级的延时
- 怎么实现MFC窗口的最大化以及控件随最大化发生位置变动原因
- Windows编程微秒级延时的实现
- 请教怎么实现MFC Dlg界面多语言界面,急等
- windows下实现微秒级的延时
- windows下实现微秒级延时
- windows下实现微秒级的延时
- VC++/MFC怎么实现局域网里下载FTP服务器上的文件?
- windows下实现微秒级的延时
- VC++ MFC怎么实现“多线程”