⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adt600.inc

📁 源代码PC104用户手册PC104用户手册PC104用户手册
💻 INC
字号:
/*
   Science & Technology CO.,LTD.
   Rm814-815,Shangda Plaza, Zhenhua,ShenZhen,GuangDong,P.R.C.

   Tel:   86-755-3224200
   Fax:   86-755-3343187
   Zip:   518031

   Board:       SF93A-01
   Compiler:    Turbo C (r) version 1.0, 1.5, 2.0
                Turbo C++ (r) version 1.0
		Borland C++ (r) version 2.0, 3.0

   Last update: August 19, 1993

   This file contains procedure and functions used by the sample programs
   provided with your ADT600  The procedures are well documented and should
   be helpful in learning how to program your ADT600
*/

#include <dos.h>


#define ENABLED  1
#define DISABLED 0

#define BIPOLAR 1
#define UNIPOLAR 0

#define INPUT  1
#define OUTPUT  0

#define TRUE 1
#define FALSE 0

#define HIGH 1
#define LOW 0

unsigned char Channel_IRQ;

unsigned BaseAddress;

float VoltageRange,
      DACSlope,
      ConversionFactor,
      Baseline ;

int   DACOffset;


/**************************

 InitializeBoardSettings

 The InitializeBoardSettings procedure is used to set the Base address
 variable and calculate the conversion factor for converting between digital
 values and volts.  Since the base address variable is not set until this
 procedure is called, make certain that you call this procedure before
 any others in this file.

*******************/

void InitializeBoardSettings(unsigned BA, float Range, char Polarity)
{
  BaseAddress = BA;
  Channel_IRQ = 0;
  VoltageRange = Range;
  ConversionFactor = VoltageRange / 4096.0;
  if (Polarity == BIPOLAR)
   Baseline = 0;
  else
   Baseline = 5.0;
}

/***********

 The Function DigitalToSBS converts a digitized value to a SBS value.
 In these sample programs the conversion factor and baseline
 correspond to converting between digitized values and volts.

***********/

float DigitalToSBS(int DigitalValue)
{
 return(DigitalValue * ConversionFactor + Baseline);
}

/*******************

 ResetBoard

 The ResetBoard procedure is used to reset the ADT600.  The UPD71055 PPI is
 configured so that ports 0,1 and 2 are input, a dummy A-D conversion is
 performed and then the clear board command is sent.

 The channel bits of the Channel Select register are set for channel 0
 The external trigger is disabled, the IRQ source is set to Timer 2 out.

*******************/

void ResetBoard(void)
{
 unsigned char B;

 outportb(BaseAddress + PPI_CTRL, 0x9B);      /* Set PPI Port 0,1,and 2 for input */
 outportb(BaseAddress + CHANNEL_SLCT, 0x00);  /* Not select channel,IRQ disabled */
 Channel_IRQ = 0x00;

 outportb(BaseAddress + START_CONVERSION, 0); /* Start a Dummy conversion */

 while ( (inportb(BaseAddress + STATUS_BYTE) & 1) == 0)
  {
  }                                      /* Wait 'til conversion done */

 B = inportb(BaseAddress + READ_DATA_LSB);
 B = inportb(BaseAddress + READ_DATA_MSB);

 delay(5);                                  /* delay until board is cleared */
}

/*******************

 SetChannel

 The SetChannel procedure is used to set the channel bits, in the CHANNEL
 SELECT register (BA + 12).
 Note how this procedure sets only the channel select bits;
 it does not change the other bits in this register.
 This is important because if you unintentionally clear the other bits it
 can cause unexpected behavior of the ADT600.

*******************/

void SetChannel(unsigned char ChannelNumber)
{
 unsigned char B;

 B = Channel_IRQ;                           /* read current byte */
 B = B & 0x08;
 B = B | ( ChannelNumber & 0x07 );          /* set channel bits */
 if(ChannelNumber <= 7)
   B = B | 0x10;
 else
   B = B | 0x20;

 outportb(BaseAddress + CHANNEL_SLCT, B);  /* write new byte */
 Channel_IRQ = B;
}

/*******************

 SetIRQStatus

 The SetIRQStatus procedure is used to set or clear the IRQ Enable bit
 on the ADT600.  A value of 1 passed to this procedure enables interrupts
 a value of 0 disables interrupts.

*******************/

void SetIRQStatus(char IRQStatus)
{
 unsigned char B;

 B = Channel_IRQ;                       /* read current byte */
 B = B & 0xF7;                          /* clear IRQ bit */
 B = B | IRQStatus * 8;                 /* set IRQ select bit */
 outportb(BaseAddress + IRQ_SLCT, B);   /* write new byte */
 Channel_IRQ = B;                       /* store current channel and IRQ select byte */
}

/*******************

 StartConversion

 The StartConversion procedure is used to start conversions.

*******************/

void StartConversion(void)
{
 outportb(BaseAddress + START_CONVERSION, 0);
}

/*******************

 ConversionDone

 The ConversionDone function returns TRUE if a conversion is complete, FALSE
 if a conversion is in progress.

*******************/

char ConversionDone(void)
{
 unsigned char Status;

 Status = inportb(BaseAddress + STATUS_BYTE);    /* read board status */
 if ( (Status & 1) == 1)
  return(TRUE);                           /* if B0 is set return TRUE */
 else
  return(FALSE);                     /* if B0 is not set return FALSE */
}

/*******************

 ReadData

 The ReadData function retrieves two bytes from the converter and combines
 them into an integer value.

*******************/

int ReadData(void)
{
 int MSB, LSB;

 MSB = inportb(BaseAddress + READ_DATA_MSB) * 16;
 LSB = inportb(BaseAddress + READ_DATA_LSB) / 16;

 return(MSB + LSB - 2048);
}

/*******************

 ClockMode

 The ClockMode procedure is used to set the mode of a designated counter
 on the UPD71054 programmable interval timer (PIT).

*******************/

void ClockMode(unsigned char Clock, unsigned char Mode)
{
 unsigned char StatusByte;

 StatusByte = (Clock * 64) + (Mode * 2) + 48;
 outportb(BaseAddress + TIMER_CTRL, StatusByte);
}

/*******************

 ClockDivisor

 The ClockDivisor procedure is used to set the divisor of a designated
 counter on the UPD71054 programmable interval timer (PIT).  This procedure
 assumes that the counter has already been set to receive the least
 significant byte (LSB) of the divisor followed by the most significant
 byte (MSB).

*******************/

void ClockDivisor(unsigned char Clock, unsigned int Divisor)
{
 unsigned char MSB, LSB;
 unsigned int PortID;

 PortID = BaseAddress + TIMER_A + Clock;
 LSB = Divisor % 256;
 MSB = Divisor / 256;
 outportb(PortID, LSB);
 outportb(PortID, MSB);
}

/***********

 SetUserClock

 The SetUserClock procedure is used to set the programmable interval
 timer (PIT) on the ADT600 such that the output of counter 2 goes high
 at the specified rate.  The maximum attainable rate this procedure, as
 written, is 500,000 Hz although you can easily change this by  adjusting
 the divisors accordingly.

***********/

void SetUserClock(float Rate)
{
  ClockMode(0, 2);
  ClockDivisor(0, 8);

  ClockMode(1, 2);
  ClockDivisor(1, (500000.0 / Rate));

  ClockMode(2, 2);
  ClockDivisor(2, 2);
}

/*******************

 ClockDone

*******************/

char ClockDone(unsigned char Timer)
{
 unsigned long CounterValue;
 unsigned char LSB, MSB;

 outportb(BaseAddress+TIMER_CTRL,Timer*64);
 LSB = inportb(BaseAddress + TIMER_A + Timer);
 MSB = inportb(BaseAddress + TIMER_A + Timer);

 CounterValue = (MSB * 256) + LSB;

 if (CounterValue > 1)
  return(FALSE);
 else
  return(TRUE);
}

/***********
  Read_PIT_Status

************/
char Read_PIT_Status(unsigned char Timer)
{
  unsigned char status;

  switch(Timer){
    case 0:{  outportb(BaseAddress+TIMER_CTRL,0xe2);
	     break;
	   }
    case 1:{  outportb(BaseAddress+TIMER_CTRL,0xe4);
	     break;
	   }
    default:{ outportb(BaseAddress+TIMER_CTRL,0xe8);
	     break;
	   }
  }
  status= inportb(BaseAddress + TIMER_A + Timer);
  if(status & 0x80)
    return(HIGH);
  else
    return(LOW);
}
/***********

 Read DigitalIO

 The ReadDigitalIO function returns the value of the specified digital
 input port.  Each digital input line is represented by a bit of the
 return value. Digital in 0 is bit 0, digital in 1 is bit 1, and so on.

***********/

unsigned char ReadDigitalIO(unsigned char InputPort)
{
 return(inportb(BaseAddress + PPI_0 + InputPort));
}

/***********

 WriteDigitalIO

 The WriteDigitalIO function sets the value of the digital output port to
 equal the value passed as parameter v.  Each digital output line is
 represented by a bit of v.  Digital out 0 is bit 0, digital out 1 is bit 1,
 and so on.

***********/

void WriteDigitalIO(unsigned char OutputPort, unsigned char v)
{
 outportb(BaseAddress + PPI_0 + OutputPort, v);
}

/*****************

 ConfigureIOPorts

 The ConfigureIOPorts procedure is used to configure the ports 0 and 2 on
 the UPD71055 PPI for either input or output.
 A value of 1 means input, a value of 0 is for output.
 It is advisable to use the INPUT and OUTPUT constants defined in this file.

*****************/

void ConfigureIOPorts(unsigned char Port0, unsigned char Port1,unsigned char Port2)
{
 unsigned char ControlByte;

 ControlByte = 128 + (Port0 * 16) + (Port1 * 2)+(Port2 * 8)+ Port2;
 outportb(BaseAddress+PPI_CTRL, ControlByte);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -