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

📄 836demo2.c

📁 研华工控卡PCL836的一些例程序
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *          836DEMO2.C - Example of  PCL-836  counter  card                  *
 *                       Freq Measurement without 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;
     }

     // 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 2  ***** ");
     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,8);
     printf(" Please input range of frequency measurement:");
     gotoxy(10,9);
     printf(" <0>   1 HZ to 65K  HZ (Driver spends 1s    to measure)");
     gotoxy(10,10);
     printf(" <1> 10K HZ to 650K HZ (Driver spends 100ms to measure)");
     gotoxy(10,11);
     printf(" <2>100K HZ to 6.5M HZ (Driver spends 10ms  to measure)");
     gotoxy(10,12);
     printf(" <Q> Exit");
     gotoxy(10,13);
     printf(" Select : _____");

     while(1)
     {
       do
       {
       gotoxy(22,13);
       } 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 + -