Skip to content. | Skip to navigation

Personal tools

lcu/admax197.c

lcu/admax197.c

lcu/admax197.c

/////////////////////////////////////////////////////////////////////////////
//  ADMAX197.C
//
//  Last updated: 1/16/2005
//
//  Analog Input Routines for the SBC1190 with 8 Channel A/D option
//
//  This program can poll the A/D convertor
//  until the conversion is complete or can use an
//  interrupt to signal completion of the conversion.
//
/////////////////////////////////////////////////////////////////////////

#include <conio.h>

//#define INTDRIVEN        /* comment this line out for polled conversion */

#define INTCTRLLD       0
#define RANGE5V         0
#define RANGE10V        1
#define UNIPOLAR        0
#define BIPOLAR         1

/*
#ifdef __TURBOC__
#ifndef inpw
#define inpw            inport
#endif
#ifndef outpw
#define outpw           outport
#endif
#ifndef _dos_setvect
#define _dos_setvect    setvect
#endif
#endif
*/

#define ADCTRL               0xFE44          /* write only */
#define ADDATA               0xFE44          /* read only  */
#define ADDATALO             0xFE44          /* read only  */
#define ADDATAHI             0xFE45          /* read only  */

#define PCB          0xFF00        /*  default base address after reset */
#define EOI          PCB+0x002
#define IMASK        PCB+0x008
#define P2PIN        PCB+0x05A

int advalue;
int convdone;
unsigned int controlbyte = 0;

/////////////////////////////////////////////////////////////////////////
void far interrupt adinthndlr(void)
{
  advalue = inpw(ADDATA);            /* read the data   */
  convdone = 1;
  outpw(EOI, 0x8000);
}

/////////////////////////////////////////////////////////////////////////
// AnalogRd(int chan)
// This function reads analog input in the range set by ConfigADC()
// given a channel number of 0 to 7.
int AnalogRd(int chan)
// Return value : Integer {-2047 to +2048} (bipolar mode) or {0 to 4095} (unipolar mode)
{
  int value;

  if ((chan<0) || (chan >7))
    return(-999);

  convdone = 0;

  outp(ADDATA, controlbyte | chan);   /* write control word   */
                                      /* and start conversion */
  #ifdef INTDRIVEN
    while (!convdone)
    ;
    convdone = 0;                   /* reset convdone */
    value = advalue;
  #else  /* POLLED */
    while (!(inp(P2PIN) & 4))        /* wait for signal to rise */
    ;
    value = inpw(ADDATA);            /* read the data   */
  #endif

  return(value);
}


/////////////////////////////////////////////////////////////////////////
// ConfigADC(int acqmod, int rng, int bip)
// This function configures the ADC for mode of acquisition,
// range, and polarity.
// Send a 0 or 1 to the function variables as follows:
// acqmod = 0 ---> internally controlled acquisition
// acqmod = 1 ---> externally controlled acquisition
// RNG    = 0 ---> 5V range
// RNG    = 1 ---> 10V range
// BIP    = 0 ---> + RNG range
// BIP    = 1 ---> +/- RNG range
void ConfigADC(int acqmod, int rng, int bip)
{
  controlbyte = 0x40;

  if (acqmod)
    controlbyte = controlbyte | 0x20;

  if (rng)
    controlbyte = controlbyte | 0x10;

  if (bip)
    controlbyte = controlbyte | 0x08;
}

Generated by GNU Enscript 1.6.5.2.
Document Actions