https://static.assets-stash.eet-china.com/album/old-resources/2010/6/9/e96ab0d3-4fba-4337-aa1d-dd8d0a6f5731.RAR//*********************************************************
// Labwindows/cvi8.5 同步/异步定时器的使用
// LED闪烁指示
// szlihongtao
// 2010-06-09
//*********************************************************
#include <cvirte.h>
#include <userint.h>
#include "1.h"
#include "asynctmr.h"
//*****************************************************************************
static int panelHandle;
static unsigned int Timer_ID;
static unsigned int f_led,f_led_red;
static unsigned int cnt_tmr,cnt_tmr1;
//*****************************************************************************
// 异步定时器函数
// 周期为10ms
//*****************************************************************************
int CVICALLBACK FunctionName (int reserved, int timerId, int event,
void *callbackData, int eventData1, int eventData2)
{
static unsigned int t;
if (++t<10)
return 0;
t=0; // 周期为100ms
SetCtrlVal (panelHandle, PANEL_NUMERIC_2,++cnt_tmr1);
++f_led_red;
f_led_red&=1;
SetCtrlVal (panelHandle, PANEL_LED_RED,f_led_red);
return 0;
}
//*****************************************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "1.uir", PANEL)) < 0)
return -1;
Timer_ID=NewAsyncTimer (0.01, -1, 1, FunctionName, 0); // 创建异步定时器
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
DiscardAsyncTimer (-1); // 删除异步定时器
return 0;
}
//*****************************************************************************
int CVICALLBACK callback_tmr (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
{
++f_led;
f_led&=0x01;
SetCtrlVal (panelHandle, PANEL_LED_2,f_led);
SetCtrlVal (panelHandle, PANEL_NUMERIC_3,++cnt_tmr);
break;
}
}
return 0;
}
//*****************************************************************************
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
//******************************************************************************
//******************************************************************************
//******************************************************************************
文章评论(0条评论)
登录后参与讨论