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

📄 836demo3.c

📁 研华工控卡PCL836的一些例程序
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *          836DEMO3.C - Example of  PCL-836  counter  card                  *
 *                       Pulse Output (PWM) 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);

/*=============================================================*/
/*   Main program                                              */
/*=============================================================*/
main(void)
{
     unsigned short usBaseAddress, usDeviceNumber;
     unsigned short usCounter;
     unsigned long  retCode;
     unsigned int keyin;
     float fPeriod, fUpCycle;

     // default base address & device number
     usBaseAddress = 0x240;
     usDeviceNumber = 0x00;
     fPeriod  = 0.2;
     fUpCycle = 0.05;
     usCounter = 0x0;

     // display demo program description
     clrscr();
     dis_main();

     // Open device driver
     retCode = DeviceOpen(usDeviceNumber, usBaseAddress);
     if (retCode != 0L)
     {
        ShowErrorMessage(retCode);
        return;
     }

     // start pulse output function
     retCode = CounterPulseStart(usDeviceNumber, usCounter, fPeriod, fUpCycle);
     if (retCode != 0L)
     {
        ShowErrorMessage(retCode);
        return;
     }

     // frequency measurement start
     while(1)
     {
       do
       {
           // show value of freqnency
           gotoxy(10,13);
           printf("Period = 0.2, UpCycle = 0.05");
           gotoxy(10,15);
           printf("Pulse output(PWM0) is in Progressing ......");

       } 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 3  ***** ");
     gotoxy(10,5);
     printf("The demo program uses pulse output(PWM) function");
     gotoxy(10,6);
     printf("This Base Address is set to 0x240 and connect PWM0 (output pin).");
     gotoxy(10,7);
     printf("Its Period is 0.2ms   , Its UpCycle is 0.05ms ");
}

/*=============================================================*/
/*     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 + -