📄 ab_t1.hpp
字号:
///////////////////////////////////////////////////////////////////////////////
// //
// Library Name : AB_T1.HPP //
// Date : 2001/05/01 //
// Author : Huang, Biing-Huang //
// //
///////////////////////////////////////////////////////////////////////////////
#include<dos.h>
#include<string.h>
#if !defined __AB_T1__
# define __AB_T1__
# define __SLOT_CTL 0x30
# define __SLOT_EXT_A 0x20
# define __SLOT_EXT_B 0x21
# define __SLOT_EXT_C 0x22
# define __SLOT_EXT_D 0x23
# define __SLOT_PIN_01 0x10
# define __SLOT_PIN_02 0x11
# define __SLOT_PIN_03 0x12
# define __SLOT_PIN_04 0x13
# define __SLOT_PIN_05 0x14
# define __SLOT_PIN_06 0x15
# define __SLOT_PIN_07 0x16
# define __SLOT_PIN_08 0x17
# define __SLOT_PIN_09 0x18
# define __SLOT_PIN_10 0x19
# define __SLOT_PIN_11 0x1A
# define __SLOT_PIN_12 0x1B
# define __SLOT_PIN_13 0x1C
# define __SLOT_PIN_14 0x1D
# define __SLOT_PIN_15 0x1E
# define __SLOT_PIN_16 0x1F
//=< AB_T1 >=================================================================//
// //
// //
// //
// //
//===========================================================================//
class AB_T1 {
public:
AB_T1 ( void );
AB_T1 ( unsigned int P );
void RST ( void );
unsigned C_ID ( unsigned S );
char * C_Name ( unsigned S, char *Name );
char * C_Name ( unsigned S );
unsigned RD ( unsigned S, unsigned A );
void WR ( unsigned S, unsigned A, unsigned D );
int ERR_NO ( void );
unsigned int PORT ( void );
protected:
void S ( unsigned S );
unsigned R ( unsigned A );
void W ( unsigned A, unsigned D );
int ID;
unsigned int Port;
static int Err [11];
private:
void CheckIn ( unsigned int P );
void WaitEcho ( int CLK );
static unsigned int Port_Used [11];
static unsigned Sel [11];
static unsigned int Port_List [ 9];
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
int AB_T1::Err [11] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
unsigned int AB_T1::Port_Used [11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
unsigned AB_T1::Sel [11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
unsigned int AB_T1::Port_List [ 9] = { 0x0378,0x0278,0x0368,0x0268,
0x0358,0x0258,0x0348,0x0248,
0x03BC };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
AB_T1::AB_T1 ( void )
{
AB_T1::Port = 0;
for( int i=0; (AB_T1::Port == 0)&&(i<9) ; i++ )
{
AB_T1::CheckIn( AB_T1::Port_List[i] );
if( AB_T1::Err[ AB_T1::ID ] )
{
AB_T1::Port_Used[ AB_T1::ID ] = 0;
AB_T1::ID = 10;
AB_T1::Port = 0;
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
AB_T1::AB_T1 ( unsigned int P )
{
if( P != 0 )
AB_T1::CheckIn( P );
else
AB_T1::ID = 10;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::RST ( void )
{
if( AB_T1::ID != 10 )
{
AB_T1::Err[AB_T1::ID] = 0;
AB_T1::W( 0x0, 0x0 );
AB_T1::W( 0x0, 0x0 );
AB_T1::Err[AB_T1::ID] = ( AB_T1::Err[AB_T1::ID] ) ? 1 : 0;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
unsigned AB_T1::C_ID ( unsigned S )
{
AB_T1::S( S );
return( AB_T1::R( 0x0 ) );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
char * AB_T1::C_Name ( unsigned S, char *Name )
{
switch( AB_T1::C_ID( S ) )
{
case 0x01: strcpy( Name, "AB_T1C1 " ); break;
case 0x05: strcpy( Name, "AB_T1P1 " ); break;
case 0x06: strcpy( Name, "AB_T1P2 " ); break;
case 0x08: strcpy( Name, "AB_T1H1 " ); break;
case 0x09: strcpy( Name, "AB_T1H1+" ); break;
case 0x0D: strcpy( Name, "AB_T1O1 " ); break;
case 0x0E: strcpy( Name, "AB_T1W1 " ); break;
case 0x0F: strcpy( Name, "Empty " ); break;
default : strcpy( Name, "Unknow " );
}
return( Name );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
char * AB_T1::C_Name ( unsigned S )
{
static char Name[10];
AB_T1::C_Name( S, Name );
return( Name );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
unsigned AB_T1::RD ( unsigned S, unsigned A )
{
AB_T1::S( S );
return( AB_T1::R( A ) );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::WR ( unsigned S, unsigned A, unsigned D )
{
AB_T1::S( S );
AB_T1::W( A, D );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
int AB_T1::ERR_NO ( void )
{
return( AB_T1::Err[AB_T1::ID] );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
unsigned int AB_T1::PORT ( void )
{
return( AB_T1::Port );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::S ( unsigned S )
{
if( (!AB_T1::Err[AB_T1::ID]) && (S != AB_T1::Sel[AB_T1::ID]) && (S & 0x30) )
{
S &= 0x3F;
AB_T1::Sel[AB_T1::ID] = S;
outportb( AB_T1::Port, S ); AB_T1::WaitEcho( 0 );
outportb( AB_T1::Port, S | 0x80 ); AB_T1::WaitEcho( 1 );
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
unsigned AB_T1::R ( unsigned A )
{
unsigned D = 0;
if( !AB_T1::Err[AB_T1::ID] )
{
A &= 0x0F;
outportb( AB_T1::Port, A ); AB_T1::WaitEcho( 0 );
outportb( AB_T1::Port, A | 0x80 ); AB_T1::WaitEcho( 1 );
D = ( inportb( AB_T1::Port + 1 ) >> 3 ) & 0x0F;
}
return( D );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::W ( unsigned A, unsigned D )
{
if( !AB_T1::Err[AB_T1::ID] )
{
A &= 0x0F;
D &= 0x0F;
outportb( AB_T1::Port+2, D );
outportb( AB_T1::Port, A | 0x40 ); AB_T1::WaitEcho( 0 );
outportb( AB_T1::Port, A | 0xC0 ); AB_T1::WaitEcho( 1 );
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::CheckIn ( unsigned int P )
{
for( AB_T1::ID=0;
(AB_T1::Port_Used[AB_T1::ID] != 0)&&(AB_T1::Port_Used[AB_T1::ID] != P);
AB_T1::ID++ );
if( AB_T1::ID < 10 )
{
AB_T1::Port = P;
if( AB_T1::Port_Used[AB_T1::ID] == 0 )
{
AB_T1::Port_Used[AB_T1::ID] = P;
AB_T1::RST();
AB_T1::Err[AB_T1::ID] = ( AB_T1::Err[AB_T1::ID] ) ? 1 : 0;
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1::WaitEcho ( int CLK )
{
int Times = 0; // counter for retry
int Arrive = 0; // the echo signal is arrive
if( !AB_T1::Err[AB_T1::ID] )
{
for( Times=0 ; !Arrive && (Times<1000); Times++ )
{
Arrive = ( ( ( inportb(AB_T1::Port+1) & 0x80 ) >> 7 ) ^ CLK );
}
if( !Arrive ) AB_T1::Err[AB_T1::ID] = 2;
}
}
//=< AB_T1C1A >==============================================================//
// //
// //
// //
// //
//===========================================================================//
class AB_T1C1A : public AB_T1 {
public:
AB_T1C1A ( unsigned int P );
void INIT ( );
int VR_Adj ( int I );
void DA_Cal ( );
void AD_Cal ( );
void DA ( float V );
float AD ( );
float V ( );
int ERR_NO ( );
protected:
void DA_12bit ( unsigned int D );
unsigned int AD_12bit ( );
void AD_Path ( unsigned PATH );
static float DA_DH[11];
static float DA_DL[11];
static float DA_AH[11];
static float DA_AL[11];
static float AD_AH[11];
static float AD_AL[11];
static float AD_DH[11];
static float AD_DL[11];
static int Err [11];
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
float AB_T1C1A::DA_DH[11] = { 3072.0, 3072.0, 3072.0, 3072.0, 3072.0,
3072.0, 3072.0, 3072.0, 3072.0, 3072.0,
3072.0 };
float AB_T1C1A::DA_DL[11] = { 1024.0, 1024.0, 1024.0, 1024.0, 1024.0,
1024.0, 1024.0, 1024.0, 1024.0, 1024.0,
1024.0 };
float AB_T1C1A::DA_AH[11] = { 10.0, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0, 10.0,
10.0 };
float AB_T1C1A::DA_AL[11] = { 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0 };
float AB_T1C1A::AD_AH[11] = { 10.0, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0, 10.0,
10.0 };
float AB_T1C1A::AD_AL[11] = { 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0 };
float AB_T1C1A::AD_DH[11] = { 3072.0, 3072.0, 3072.0, 3072.0, 3072.0,
3072.0, 3072.0, 3072.0, 3072.0, 3072.0,
3072.0 };
float AB_T1C1A::AD_DL[11] = { 1024.0, 1024.0, 1024.0, 1024.0, 1024.0,
1024.0, 1024.0, 1024.0, 1024.0, 1024.0,
1024.0 };
int AB_T1C1A::Err [11] = { 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0 };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
AB_T1C1A::AB_T1C1A ( unsigned int P )
:AB_T1 ( P )
{
AB_T1C1A::INIT( );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1C1A::INIT ( )
{
AB_T1C1A::DA_DH[AB_T1::ID] = 3072.0;
AB_T1C1A::DA_DL[AB_T1::ID] = 1024.0;
AB_T1C1A::DA_AH[AB_T1::ID] = 10.0;
AB_T1C1A::DA_AL[AB_T1::ID] = 0.0;
AB_T1C1A::AD_AH[AB_T1::ID] = 10.0;
AB_T1C1A::AD_AL[AB_T1::ID] = 0.0;
AB_T1C1A::AD_DH[AB_T1::ID] = 3072.0;
AB_T1C1A::AD_DL[AB_T1::ID] = 1024.0;
AB_T1C1A::Err [AB_T1::ID] = 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
int AB_T1C1A::VR_Adj ( int I )
{
int Diff = 0;
if( !AB_T1::Err[AB_T1::ID] )
{
AB_T1::RST( );
switch( I )
{
case 1: AB_T1C1A::AD_Path( 0x2 );
AB_T1C1A::DA_12bit( 0x0400 ); delay(1);
Diff = (int) AB_T1C1A::AD_12bit( );
Diff -= (int) 0x0400;
break;
case 2: AB_T1C1A::AD_Path( 0x2 );
AB_T1C1A::DA_12bit( 0x0C00 ); delay(1);
Diff = (int) AB_T1C1A::AD_12bit( );
AB_T1C1A::DA_12bit( 0x0400 ); delay(1);
Diff -= (int) AB_T1C1A::AD_12bit( );
Diff -= (int) 0x0800;
break;
case 3: AB_T1C1A::AD_Path( 0x8 ); delay(1);
Diff = (int) AB_T1C1A::AD_12bit( );
AB_T1C1A::AD_Path( 0x4 ); delay(1);
Diff -= (int) AB_T1C1A::AD_12bit( );
Diff -= (int) 0x0800;
break;
case 4: AB_T1C1A::AD_Path( 0x4 ); delay(1);
Diff = (int) AB_T1C1A::AD_12bit( );
Diff -= (int) 0x0400;
break;
default : Diff = 0;
}
AB_T1::RST( );
}
return ( Diff );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1C1A::DA_Cal ( )
{
float H, L;
if( !AB_T1::Err[AB_T1::ID] )
{
AB_T1::RST( );
AB_T1C1A::AD_Path( 0x2 );
AB_T1C1A::DA_12bit( 0x0C00 ); delay(1);
H = AB_T1C1A::AD( );
AB_T1C1A::DA_12bit( 0x0400 ); delay(1);
L = AB_T1C1A::AD( );
AB_T1C1A::DA_AH[AB_T1::ID] = H;
AB_T1C1A::DA_AL[AB_T1::ID] = L;
AB_T1C1A::DA_DH[AB_T1::ID] = (float) 0x0C00;
AB_T1C1A::DA_DL[AB_T1::ID] = (float) 0x0400;
AB_T1::RST( );
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1C1A::AD_Cal ( )
{
if( !AB_T1::Err[AB_T1::ID] )
{
AB_T1::RST( );
AB_T1C1A::AD_AH[AB_T1::ID] = 10.0;
AB_T1C1A::AD_AL[AB_T1::ID] = 0.0;
AB_T1C1A::AD_Path( 0x8 ); delay(1);
AB_T1C1A::AD_DH[AB_T1::ID] = (float) AB_T1C1A::AD_12bit( );
AB_T1C1A::AD_Path( 0x4 ); delay(1);
AB_T1C1A::AD_DL[AB_T1::ID] = (float) AB_T1C1A::AD_12bit( );
AB_T1::RST( );
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
void AB_T1C1A::DA ( float V )
{
unsigned int DA;
if( DA_AH[AB_T1::ID] == DA_AL[AB_T1::ID] ) AB_T1C1A::Err[AB_T1::ID] |= 0x20;
if( !AB_T1C1A::Err[AB_T1::ID] )
{
DA = (unsigned int)((((V-DA_AL[AB_T1::ID])*(DA_DH[AB_T1::ID]-DA_DL[AB_T1::ID]))/(DA_AH[AB_T1::ID]-DA_AL[AB_T1::ID]))+DA_DL[AB_T1::ID]+0.5);
AB_T1C1A::DA_12bit( DA );
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
float AB_T1C1A::AD ( )
{
float AD, V = 0;
if( AD_DH[AB_T1::ID] == AD_DL[AB_T1::ID] ) AB_T1C1A::Err[AB_T1::ID] |= 0x10;
if( !AB_T1C1A::Err[AB_T1::ID] )
{
AD = (float) AB_T1C1A::AD_12bit();
V = (((AD-AD_DL[AB_T1::ID])*(AD_AH[AB_T1::ID]-AD_AL[AB_T1::ID]))/(AD_DH[AB_T1::ID]-AD_DL[AB_T1::ID]))+AD_AL[AB_T1::ID];
}
return ( V );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -