?? 836demo5.c
字號:
/*****************************************************************************
* *
* 836DEMO5.C - Example of PCL-836 counter card *
* Freq Measurement with filter demo program *
* Advantech Co,.Ltd. 2/24/97 *
*****************************************************************************
*/
#include <dos.h>
#include <stdio.h>
#include <bios.h>
#include <conio.h>
#include <stdlib.h>
#include "..\driver.h"
void ShowErrorMessage(unsigned long ErrorCode);
void dis_main(void);
unsigned int keyin;
/*=============================================================*/
/* Main program */
/*=============================================================*/
main(void)
{
unsigned short usBaseAddress, usDeviceNumber;
unsigned short usCounter;
unsigned long retCode;
float Freq;
// default base address & device number
usBaseAddress = 0x240;
usDeviceNumber = 0x00;
usCounter = 0x00;
// display demo program description
clrscr();
dis_main();
// check "Q" or "q" charachters
if ((keyin == 0x51) || (keyin == 0x71))
return;
// Open device driver
retCode = DeviceOpen(usDeviceNumber, usBaseAddress);
if (retCode != 0L)
{
ShowErrorMessage(retCode);
return;
}
// Configure : count edge is positive edge, MaxInFreq = 300K
retCode = CounterConfig(usDeviceNumber, usCounter, 0, 300000);
// initilize counter function
retCode = CounterFreqStart(usDeviceNumber, usCounter);
if (retCode != 0L)
{
ShowErrorMessage(retCode);
return;
}
// frequency measurement start
while(1)
{
do
{
CounterFreqRead(usDeviceNumber, usCounter, (keyin-0x30),
&Freq);
// show value of freqnency
gotoxy(10,15);
printf("Frequency Value = %10.0f", Freq);
} while(!bioskey(1));
keyin = bioskey(0);
if((keyin &= 0x0ff) == 27)
break;
gotoxy(15,20);
printf(" Press ESC to ABORT, other key to CONTINUE !");
if((bioskey(0) & 0x0ff) == 27)
break;
}
CounterReset(usDeviceNumber, usCounter);
DeviceClose(usDeviceNumber);
return;
}
/*=============================================================*/
/* display description */
/*=============================================================*/
void dis_main(void)
{
gotoxy(25,3);
printf("****** PCL836DEMO 5 ***** ");
gotoxy(10,5);
printf("The demo program uses frequency measurement");
gotoxy(10,6);
printf("This Base Address is set to 0x240 and connect CLK0 (measure source).");
gotoxy(10,7);
printf("Your source of frequency must is set below 300K (Over 300K is noise)");
gotoxy(10,9);
printf(" Please input range of frequency measurement:");
gotoxy(10,10);
printf(" <0> 1 HZ to 65K HZ (Driver spends 1s to measure)");
gotoxy(10,11);
printf(" <1> 10K HZ to 650K HZ (Driver spends 100ms to measure)");
gotoxy(10,12);
printf(" <2>100K HZ to 6.5M HZ (Driver spends 10ms to measure)");
gotoxy(10,13);
printf(" <Q> Exit");
gotoxy(10,14);
printf(" Select : _____");
while(1)
{
do
{
gotoxy(22,14);
} while(!bioskey(1));
keyin = bioskey(0);
keyin &= 0xff;
printf("%c", keyin);
// check input "0", "1", "2", "Q", "q" characters ?
if((keyin == 0x30) || (keyin == 0x31) || (keyin == 0x32) ||
(keyin == 0x71) || (keyin == 0x51))
break;
}
}
/*=============================================================*/
/* show error message */
/*=============================================================*/
void ShowErrorMessage(unsigned long ErrorCode)
{
char szErrorMsg[10][80]=
{
{"DeviceNumber is out of range ,its range is from 0 to 9."},
{"Invalid Base Address."},
{"This DeviceNumber is in use !"},
{"Invalid Base Address, DeviceOpen must be called before any other functions."},
{"Illegal Channel"},
{"Illegal Input Param"},
{"The freqence of calling the function is too high."},
{"FOUT frequency is out of range "},
{"Invalid Port Channel"}
};
gotoxy(10,24);
if ((ErrorCode > (unsigned long)MaxErrorCode) || (ErrorCode == 0L))
printf("No Error");
else
printf("%s\n",&szErrorMsg[ErrorCode-1][0]);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -