4. Using the I/O Address Map
CNT16-8(FIT)GY, CNT16-8L(FIT)GY
31
Sample Program
/*
===========================================================================
Sample program 1
DEVICE
ID:
0
Initial
Data: 0000H
Channel:
0ch
Digital
Filter
1024
usec
Interrupt:
N/A
===========================================================================
*/
#include <stdio.h>
#include <conio.h>
/* ----- Constant --------------------------------------------------------- */
#define ADR 0x0800
/* I/O address */
#define CH
8
/* channel */
/* ----- Declarations ------------------------------------------------------ */
struct REGS08
{
/* 8-bit */
unsigned
char
lower;
/* lower */
unsigned
char
upper;
/*
upper*/
};
struct REGS16
{
/* 16-bit */
unsigned
short
count;
};
union ACCESS
{
struct
REGS08 Byte[CH];
/* 8-bit */
struct
REGS16 Whole[CH];
/* 16-bit */
};
union ACCESS
CountData;
/* ----- Prototype --------------------------------------------------------- */
void main(
void
);
void
Initialize( unsigned char );
/* initialize */
void
ReadData( unsigned char, unsigned short *, unsigned char * );
/* read data */
/* ----- Initialize -------------------------------------------------------- */
void
Initialize( unsigned char ch )
{
outp( ADR+0x10, 0x15 );
/* digital filter set */
outp( ADR+0x11, 0x0d );
/* 1024us */
outp( ADR+0x10, 0x12 );
/* sense reset */
outp( ADR+0x11, 0xff );
outp( ADR+0x10, ch);
/* initial data set */
outp( ADR+0x11, CountData.Byte[ch].lower ); /* lower */
outp( ADR+0x11, CountData.Byte[ch].upper ); /* upper */
}