4. Using the I/O Address Map
38
ADI16-4(FIT)GY
Sample program
/*===========================================================================
=
Sample program 1
DEVICE ID:
0
Mode:
Software Mode, Multi-Channel
Channel:
0 to 3ch
Range:
-10 to 10V
Internal Clock:
N/A
Interrupt:
N/A
===========================================================================
*/
#include <stdio.h>
#include <conio.h>
/* ----- Constant ----------------------------------------------------------
*/
#define
ADR
0x0800
/* I/O address */
/* ----- Prototype ---------------------------------------------------------
*/
void main( void );
/* ----- Main --------------------------------------------------------------
*/
void main( void )
{
unsigned char
UpperData, LowerData;
unsigned char
GainData, OffsetData;
unsigned int
i, j;
outp( ADR+0x18, 0x00 );
/* Initialize */
outp( ADR+0x18, 0x02 );
/* Sampling Mode */
outp( ADR+0x1c, 0x04 );
/* Software */
outp( ADR+0x18, 0x03 );
/* Range */
outp( ADR+0x1c, 0x00 );
/* -10 to 10V */
outp( ADR+0x18, 0xb );
/* Factory Setting(Gain) */
outp( ADR+0x1c, 0x20 );
while( inp( ADR+0x17 ) & 0x4 );
GainData = (unsigned char)inp( ADR+0x1c );
outp( ADR+0x18, 0xa );
/* set Gain Data*/
outp( ADR+0x1c, 0x0 );
outp( ADR+0x1d, GainData );
while( inp( ADR+0x17 ) & 0x8 );
outp( ADR+0x18, 0xb );
/* Factory Setting(Offset)
*/
outp( ADR+0x1c, 0x21 );
while( inp( ADR+0x17 ) & 0x4 );
OffsetData = (unsigned char)inp( ADR+0x1c );
outp( ADR+0x18, 0xa );
/* set Offset Data*/
outp( ADR+0x1c, 0x1 );
outp( ADR+0x1d, OffsetData );
while( inp( ADR+0x17 ) & 0x8 );
outp( ADR+0x18, 0x07 );
/* FIFO Flag */
outp( ADR+0x1c, 0x20 );
for(i = 0; i < 4; i++) {
outp( ADR+0x12, 0x3 );
/* Channel data & Conversion Start
*/
while( !( inp( ADR+0x16 ) & 0x01 ) );
for(j = 0; j < 4; j++) {
LowerData = (unsigned char)inp( ADR+0x10 );
UpperData = (unsigned char)inp( ADR+0x11 );
printf("%01dch %02x%02x ", j, UpperData, LowerData);
}