53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
// 本程序演示目的:如何获取中断事件,只有改变DI0的状态时才会产生中断事件,可以通过板上XF1的1-2跨接选择
|
||
// DI0为上边沿是中断,2-3跨接为下边沿中断
|
||
|
||
#include "stdafx.h"
|
||
#include "windows.h"
|
||
#include "stdio.h"
|
||
#include "conio.h"
|
||
|
||
#include "PCI2312.h"
|
||
|
||
int main(int argc, char* argv[])
|
||
{
|
||
HANDLE hDevice, hEventInt;
|
||
int DeviceID;
|
||
DeviceID = 0;
|
||
int inIntCount = 0; // 内部中断计数
|
||
int outIntCount = 0; // 外部中断计数
|
||
hDevice = PCI2312_CreateDevice( DeviceID ); // 创建设备对象
|
||
if(hDevice == INVALID_HANDLE_VALUE)
|
||
{
|
||
printf("CreateDevice Error...\n");
|
||
_getch();
|
||
goto Exit;
|
||
}
|
||
|
||
hEventInt = PCI2312_CreateSystemEvent(); // 创建中断事件句柄
|
||
if(hEventInt == INVALID_HANDLE_VALUE)
|
||
{
|
||
printf("CreateSystemEvent Error...\n");
|
||
_getch();
|
||
goto Exit;
|
||
}
|
||
|
||
PCI2312_InitDeviceInt(hDevice, hEventInt); // 初始化中断
|
||
printf("Wait....\n");
|
||
while(!_kbhit())
|
||
{
|
||
while(1)
|
||
{
|
||
if(WaitForSingleObject(hEventInt, 100) == WAIT_OBJECT_0) // 等待中断发生
|
||
break;
|
||
if(_kbhit()) break;
|
||
}
|
||
outIntCount++; // 外部中断计数
|
||
inIntCount = PCI2312_GetDeviceIntCount(hDevice); // 获得内部中断计数
|
||
printf("outIntCount=%d, inIntCount=%d\n", outIntCount, inIntCount);
|
||
}
|
||
|
||
Exit:
|
||
PCI2312_ReleaseDeviceInt(hDevice); // 释放中断资源
|
||
PCI2312_ReleaseDevice(hDevice); // 释放设备对象
|
||
return 0;
|
||
} |