4. Using the I/O Address Map
34
CNT16-8(FIT)GY,
CNT16-8L(FIT)GY
Sample Program
/*
===========================================================================
Sample program 2
DEVICE
ID:
0
Initial
Data: 0000H
Channel:
0 to 3ch
Digital
Filter
1024
usec
Interrupt:
IRQ5 10 times
===========================================================================
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
/* ----- Constant ---------------------------------------------------------- */
#define
ADR
0x0800
/* I/O address */
#define CH
4
/*
channel
*/
#define IRQ5 0
/* IRQ5 */
#define IRQ7 1
/* IRQ7 */
#define IRQ9 2
/* IRQ9 */
/* ----- 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;
volatile int
intcnt = 0;
/*
interrupt counter */
volatile unsigned char intstatus = 0;
/* interrupt status */
volatile int
IrqLevel
=
IRQ5;
/* interrupt level */
int
OrgMasterImr,
OrgSlaveImr;
/* original IMR */
unsigned char
IntVector[3] = { 0x0d, 0x0f, 0x71 };
/*
interruput
vector
*/
unsigned char
PicMask[3] = { 0xdf, 0x7f, 0xfd };
/* mask bit */
unsigned char
IsrClear[3] = { 0x65, 0x67, 0x61 };
/*
ISR
clear
*/
unsigned char
IntEnable[3] = { 0x81, 0x82, 0x84 };
/*
interrupt
enable
*/
/* ----- Prototype ----------------------------------------------------------
*/
void main(
void
);
void
Initialize( unsigned char );
/* initialize */
void
ChgVect( void );
/* change vector */