/*
  Program       : Timer / Counter test program.

  Description   : You should be input freq. to CLK0, CLK1, CLK2

  Hardware setting: The Jumpers should be set as following :
		    JP1 : Don't care (or default)
		    JP2 : Don't care (or default)
		    JP3 : Don't care (or default) 
		    SW1 : I/O Addres 0x2A0 ( default )

  Note          : This program can be compiled both in Turbo C 2.0 or
		  or Turbo C++ 3.0 and running under DOS environment.
*/
#include        <stdio.h>
#include        <conio.h>
#include        <stdlib.h>
#include        <dos.h>

#pragma inline

#ifdef __cplusplus
   #define __CPPARGS            ...
#else
   #define __CPPARGS
#endif

#define BASE                    0x2A0
#define COUNT0                  0x04
#define COUNT1                  0x05
#define COUNT2                  0x06
#define CW                      0x07
int C0_L,C0_H,C1_L,C1_H,C2_L,C2_H;

void set_8254_0(unsigned int value)
{
   outp(BASE+CW,0x30);                   /* Counter 0 */
   outp(BASE+COUNT0,value & 0xff);
   outp(BASE+COUNT0,(value & 0xff00) >> 8);
}

void set_8254_1(unsigned int value)
{
  outp(BASE+CW,0x70);                    /* Counter 1 */
  outp(BASE+COUNT1,value & 0xff);
  outp(BASE+COUNT1,(value & 0xff00) >> 8);
}
void set_8254_2(unsigned int value)
{
  outp(BASE+CW,0xB0);                    /* Counter 2 */
  outp(BASE+COUNT2,value & 0xff);
  outp(BASE+COUNT2,(value & 0xff00) >> 8);
}


void main(void)
{
  unsigned long i;

  do {
     set_8254_0(0xFF);                  /* Read Counter 0 */
     C0_L=inportb(BASE+COUNT0);
     C0_H=inportb(BASE+COUNT0);

     set_8254_0(0xFF);                  /* Read Counter 1 */
     C1_L=inportb(BASE+COUNT1);
     C1_H=inportb(BASE+COUNT1);

     set_8254_0(0xFF);                  /* Read Counter 2 */
     C2_L=inportb(BASE+COUNT2);
     C2_H=inportb(BASE+COUNT2);

     printf ("Counter 0 = %x\n ",C0_L+C0_H*256);
     printf ("Counter 1 = %x\n ",C1_L+C1_H*256);
     printf ("Counter 2 = %x\n\n ",C2_L+C2_H*256);

  } while((getch()|32)!='q');
  getch();

}
