4. Using the I/O Address Map
44
ADI16-4(FIT)GY
/*===========================================================================
=
Sample program 3
DEVICE ID:
0
Mode:
Clock Mode, Multi-Channel
Channel:
0 to 3ch
Range:
-10 to 10V
Internal Clock:
1sec (250ns x 4,000,000)
Interrupt:
IRQ5 10 times
===========================================================================
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
/* ----- Constant ----------------------------------------------------------
*/
#define
ADR
0x0800
/* I/O address */
#define
CH
4
/* Channels */
#define
NUM
10
/* Sampling Times */
#define
IRQ5
0
/* IRQ5 */
#define
IRQ7
1
/* IRQ7 */
#define
IRQ9
2
/* IRQ9 */
volatile unsigned int AdData[CH][NUM];
/* A/D Data */
volatile int
intcnt = 0;
/* interrupt counter */
volatile int
IrqLevel = IRQ5;
/* interrupt level */
int
OrgMasterImr, OrgSlaveImr;
/* original IMR */
unsigned char
IntVector[3] = { 0x0d, 0x0f, 0x71 };
/* interrupt 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( void );
/* initialize */
void ChgVect( void );
/* change vector */
void ResVect( void );
/* restore vector */
void _interrupt _far inthandler( void );
/* interrupt handler */
void ( _interrupt _far *OrgVect)();
/* original interrupt vector
*/
/* ----- Initialize ---------------------------------------------------------
- */
void Initialize( void )
{
unsigned char
GainData, OffsetData;
outp( ADR+0x18, 0x00 );
/* Initialize */
outp( ADR+0x18, 0x02 );
/* Sampling Mode */
outp( ADR+0x1c, 0x05 );
/* Clock */
outp( ADR+0x18, 0x07 );
/* FIFO Flag */
outp( ADR+0x1c, 0x20 );
outp( ADR+0x18, 0x03 );
/* Range */
outp( ADR+0x1c, 0x00 );
/* -10 to 10V */