Tektronix User Guide for the PCF-M5 Language Drivers 24413A (UNSUPPORTED) User guide

PCF-MS
Keithley MetraByte Corporation
* * * * *
User Guide
for the
PCF-M5
Copyright Keithley MetraByte Corp. 1991
KEITHLEY METRABYTE CORPORATION
440 MYLES STANDISH BLVD., Taunton, MA 02780
R&vision A - April 1991
Part Number: 24413
TEL. 508/880-3000, FAX 508/880-0179
. . .
- /I/ -
Warranty Information
All products manufactured by Keithley MetraByte are warranted against defective materials and worksmanship for a period of one year from the date of delivery to the original purchaser. Any product that is found to be defective within the warranty period will, at the option of Keith@ MetraByte, be repaired or replaced. This warranty does not apply to products damaged by improper use.
Warning
Keithley MetraByte assumes no liability for damages
consequent to the use of this product. This product is not
designed with components of a level of reliability suitable
for use in life support or critical applications.
Disclaimer
Information furnished by Keithley MetraByte is believed to be accurate and reliable. However, the Keithley MetraByte Corporation assumes no responsibility for the use of such information nor for any infringements of patents or other rights of third parties that may result from its use. No license is granted by implication or otherwise under any patent rights of Keithley MetraByte Corporation.
Notes
Keithley MetraByte/Asyst/DAC is also referred to here-in as Keith@ MetroByte.
BasicTM is a trademark of Dartmouth College.
IBM@ is a registered trademark of International Business Machines Corporation.
PC, XT, AT, PS/2, and Micro Channel Architecture@ (MCA) are trademarks of
International Business Machines Corporation.
Microsoft* is a registered trademark of Microsoft Corporation.
Turbo C@ is a registered trademark of Borland International.
- iv -
Contents
CHAPTER 1
1.1
1.2
CHAPTER 2
2.1
2.2
2.3
2.4
2.5
2.6
INTRODUCTION Overview
Implementation
INTERFACE DRIVERS Microsoft C & QuickC
Small Model .....................................
Medium Model ....................................
Large Model
Microsoft C Example. ...............................
Borland Turbo
Small Model
Medium Model ....................................
Large Model., Turbo C Example.
Microsoft PASCAL.
Medium Model Microsoft PASCAL Example.
Borland Turbo PASCAL.
Compact Model..
Large Model
Turbo PASCAL Example.
Microsoft FORTRAN.
Large Model Integer (Default) Function Or Subroutine.
Microsoft FORTRAN Example. ..........................
MSTEP.LIB General Purpose Library.
........................................
.................................... .1,-l
.................................. .2-l
..................................... .2-3
......................................
..................................... .2-
................................... .2-7
................................. .2-8
................................... 2-l 1
.................................... 2-l 1
........................... 2-12
............................... 2-13
................................. 2-13
..................................... 2-l 4
............................. 2-15
................................. 2-17
..................................... 2-l 7
........................ 2-20
....................
l-l
.2-l .2-2
.2-4 .2-6
.2-7
2-18 2-18
CHAPTER 3
3.1
3.2
BASIC INTERFACE DRIVERS Interpreted BASIC (GW, Compaq, IBM, etc.)
QuickBASIC. .....................................
....................
.3-l .3-2
-v-
* * * * *
- vi -
CHAPTER
INTRODUCTION
1 .I OVERVIEW
MetraByte’s PCF-M5 is for Pascal, C, and Fortran programmers writing data acquisition and control routines for the MSTEP-5 Board. languages;
l Microsoft C fV4.0 - 6.0)
l Microsoft QuickC (Vl .O - 2.0) l Borland Turbo C (Vl .O - 2.0) l Microsoft PASCAL W3.0 - 4.0) l Borland Turbo PASCAL (V3.0 - 5.0) l Microsoft FORTRAN (V4.0 - 4.1)
The PCF-MS supports all memory models for the following
1
The PCF-M5 consists of several assembly language drivers for the various supported languages along with example programs for each language. This manual is structured to illustrate memory model usage for each of the above languages and to include a brief example program at the end of each language section. Full source listings are included on the supplied disk.
This manual is not an introduction or operating guide to the supported MSTEPS boards. You should be familiar with the boards’ various operating MODES, PARAMETERS, and ERROR codes before attempting PCF-MS implementation. Refer to the main sections of this manual supplied with your MSTEP-5 MetraByte board for a complete discussion of hardware and related functionality.
PCF-M5 Distribution Software is furnished on a 5.25” floppy diskette. A 3.5” diskette version is available as an option.
Al .2 IMPLEMENTATION
Before working with this interface package, you are urged to become familiar with MSTEP-5 board functions and specifications. Example programs herein do not assume any knowledge of these boards since the programs are general in nature and do not actually implement features of any specific board. They are limited to the actual language interface for the various languages supported.
In the following chapter, each interface driver (implemented via a CALL statement) consists of three
position-dependent parameters. These are MODE, ARGUMENT (or PARAM), STPNUM, and FLAG, as follows:
l-l
PCF-M5 USER GUIDE
MODE
PARAM
STl’NUM
FLAG
Type of function to be executed by the MSTEP-5.
Function-dependent arguments required for execution.
Step Number, which is a long integer that specifies the direction and number of steps to travel, or it returns optical shaft encoder counts. The sign indicates direction (+ = clockwise, - = counter-clockwise). Not all MODES use StpNum data, but it must always be included in the CALL parameter list.
Error number, if any, corresponding to selected MODE
* * * * *
1-2
INTERFACE
2.1 MICROSOFT C (V4.0 - 6.0) & QUICKC (Vi .O - 2.0)
Small Model
CHAPTER
2
DRIVERS
Model: Passes: Sequence:
Default Calling
Convention:
Example:
‘c’ Call: ‘c’ Declaration:
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
-mscs-mstep proc near push bp
mw~ W,sp
.
POP bp
ret ; return
-xnscs-mstep endp
Small (“/AS”) switch on command line word size pointers (offset, no DS register) Arguments Passed Right to Left
Arguments Passed by Value (Passing pointers to a subroutine is considered pass-by-value convention)
mscs-mstep &Mode, Param, &StpNum, &Flag); extern void mscs-mstepfint*,unsigned long *, int*l;
save base pointer
;
save stack pointer
; ; [bpt4] holds offset of Mode ; [bpt6] holds offset of Param ; [bpt8] holds offset of StpNum ; [bptlo] holds offset of Flag
Program execution here
;
I
;
*restore bp & sp prior to exit
I
Other:
This information is provided for those wishing to create their own drivers:
.
-mscs-mstep is declared “PUBLIC” in the .ASM file
l mscs-mstep is declared “extern” in the “C” file
2-1
PCF-MS USER GUIDE
l The .ASM file contains the “.model small” directive (MASM & TASM only) l Add leading underscore “-‘I to all mscs-mstep occurrences in .ASM file l mscs-mstep is a near call l mscs-mstep must be in a segment fname-TEXT (where fname is the name of the file where
mscs-mstep resides) if .ASM file contains mixed model procedures.
Medium Model
Model: Passes: Sequence:
Medium (“/AM”) switch on command line Word-size pointers (offset, no DS register) Arguments Passed Right to Left
Default Calling
Convention:
Arguments Passed by Value
Example
‘c’ Call: ‘c’ Declaration:
mscm-mstep f&Mode, Param, &StpNum, &Flag); extern void mscm-mstep(int*,unsigned long*,int*l;
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
-mscm_mstep proc far push bp mew bptw
. . .
far CALL (dword return address)
;
save base pointer
;
save stack pointer
; ; [bp+C] holds offset of Mode ; [bpt8] holds offset of Param ; [bptlO] holds offset of StpNum ; [bpt12] holds offset of Flag
Program execution here
;
.
I
restore bp & sp prior to exit
POP bp
ret
;return
;
-mscm_mstep endp
Other:
This information is provided for those wishing to create their own drivers:
.
-mscm-mstep is declared “PUBLIC” in the .ASM file
l mscm-mstep is declared “extem” in the “c” file l The .ASM file contains the “.model medium” directive (MASM & TASM only) l Add leading underscore “-” to all mscm-mstep occurrences in .ASM file l mscm-mstep is a far call
2-2
CHAPTER 2: INTERFACE DRIVERS
l mscm_mstep must be in a segment fname_TEXT (where fname is the name of the file where
mscm-mstep resides), else Linker returns an error.
Large Model
Model: Passes: Sequence:
Large (“/AL”) switch on command line dword size pointers (offset and DS register) Arguments Passed Right to Left
Default Calling
Convention:
Arguments Passed by Value
Example
‘c’ Call: ‘c’ Declaration:
mscl-mstep (&Mode, Param, &StpNum, &Flag);
extem void mscl-mstep(int*, unsigned long*, int?;
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
-mscl-mstep proc far push bp
mov bprsp
far CALL (dword return address)
;
save base pointer
;
save stack pointer
;
; [bpt6] holds offset of Mode . . . .
; [bptlO] holds offset of Param
; [bptll] holds offset of StpNum
; [bpt18] holds offset of Flag
Program execution here
;
; .
POP bp
ret
;return
;
*restore bp & sp prior to exit
,
-mscl-mstep endp
Other:
This information is provided for those wishing to create their own drivers:
-mscl-mstep is declared “PUBLIC” in the .ASM file mscl-mstep is declared “extern” in the “c” file The .ASM file contains the “.model large” directive (MASM & TASM only) Add leading underscore
“-” to all mscl-mstep occurrences in .ASM file Both code and data use dword (segment/offset) pointers mscl-mstep must be in a segment fname_TEXT (where fname is the name of the file where
mscl-mstep resides), else Linker returns an error.
2-3
PCF-M5 USER GUIDE
Microsoft ‘C’ Example /*
/*
/* /* /* /* /*
#include <stdio.H> #include <stdlib.H>
#&fine Beep printf("%s","\7")
#define TRYAGAIN #define REV-VIDEO #define DEF-VIDEO #define READY #define ON #define OFF
/************************************************************************/ /*
/*
/* /* /* /* /* /* /*
/*********************~******k****k******~***~***********~***********/
extern
The Following are the function Calls for different models:
mscs-mstep(&Mode,Param,&StpNum,&Flag) : Microsoft C mall Model. */ mscm-mstep(&Mode,Param,&StpNum, &Flag) : mscl~mstep(&Mode,Param,&StpNum,&Flag) : Microsoft C large Model. */
This Program Uses the Small Model Function Call
mscs-mstep(int *,unsigned *,long *,int *);
Demonstration Program for WSTEP-5 Keithley Metrabyte Corporation
Language: Microsoft "C" File:
MSCSDEM0.C
/* make a beep sound */
1 7 0 1 1 0
Microsoft C medium Model.*/
/* DECLARE CALL structure */
*/ */ f/ */ */ */ */
*/
*/ */
*/ */ */
/************************************************************************/
int modeO(void); int mo&l(void); int mode2(void); int mode3(void); int mode4(void); int modeS(void); int mode6(void);
int mode7(void);
/*mode0 */ /* mode 1 */ /* mode 2 */ /* mode 3 */ /* mode 4 */ /* mode 5 */ /* mode 6 */ /* mode 7 */
int modee(void); /* mode 8 */ int modeg(void); /* mode 9 */ int modelO(void); int mo&ll(void);
/* mode 10 */
/* mode 11 */ int model2(void); /* mode 12 */ int setchannel(void); int ErrWandler(int); int
int GetLongInp(int,int,char *,long *);
MenuHandler(void); /* menu handler
void GetIntInp(int,int,char *,unsigned *);
/* select channel
/* error handler
/* input get long integer
/* input unsigned integer */ void printat(int,int,int,char *); /* formatted print function */
2-4
*/ */ */
*/
CHAPTER 2: INTERFACE DRIVERS
void ShowChannel (void); void EraseLine(int);
/* print current channel /* erase line
*/ */
/*******~*****************x*************~~*******~*************~************~
int
Mode=12,Flag=O,IntLev=7,Interrupt=OFF;
unsigned Param[lO],TP[lO];
long
StpNusn;
/*********************************k*X**********~********************~********/ /*
/*
Main program
/* /**********************************************************~**************/
-inO I
int option,status=!TRYAGAIN;
/* default setup for MSTEP-5 */
TP LOI TP 111 TPVI
‘JP 131 TP [41
TP [51 TP t61 TP t71 TP t81 TP [91
=
0;
= 255;
= 100; = 200;
=
2;
=
0;
=
0;
=
0;
=
0;
= 768;
// select channel A // start up rate,
49 pps // high speed run rate // acceleration/deceleration pulse count
// 4 phase // full step // inverted Sl-5 outputs // internal clock // switching off at standstill // base address
*/
*/
*/
/***********************************************~**********~*******~****~**/ /*
/*
Mode 12: Initialization.
1" /*Arguments
/* /*
---------
None
/* /*
Return values
------------­1: repeat this mode*/
0: no repeat
*/
*/
again
/* /*******************************************************~*****************/
int model2()
I
*/
*/ */
*/ */ */
2-5
PCF-M5 USER GUIDE
2.2 BORLAND TURBO ‘C’ (VI .O - 2.0)
Small Model
Model: Passes: Sequence:
Small (“-ms”) switch on command line word size pointers (offset, no DS register) Arguments Passed Right to Left
Default Calling
Convention:
Arguments Passed by Value
Example
‘c’ Call: ‘c’ Declaration:
tcs-mstep &Mode,Param,&StpNum, &Flag); extern void tcs-mstepfint*,unsigned long*,int*l;
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
-tcs-mstep proc near push bp
mov bp,sp
save base pointer
:
save stack pointer
: ; [bp+4] holds offset of Mode
. .
.
. .
POP bp
; [bp+6] holds offset of Param ; [bp+8] holds offset of StpNum
; [bp+lO] holds offset of Flag
Program execution here
; ; ;
*restore bp & sp prior to exit
I
ret ; return
_tcs-mstep endp
Other:
This information is provided for those wishing to create their own drivers:
.
-tcs-mstep is declared “PUBLIC” in the .ASM file
l tcs-mstep is declared “extern” in the “c” file l The .ASM file contains the “.model small” directive (MASM & TASM only) l Add leading underscore “-” to all tcs-mstep occurrences in .ASM file l tcs-mstep is a near call l tcs-mstep must he in a segment fname_TEXT (where fname is the name of the file where tcs-mstep
resides), else Linker returns an error.
2-6
Medium Model
CHAPTER 2: INTERFACE DRIVERS
Model: Passes: Sequence:
Medium (“-mm”) switch on command line word size pointers (offset, no DS register) Arguments Passed Right to Left
Default Calling
Convention:
Arguments Passed by Value
Example
‘c’ Call: ‘c’ Declaration:
tan-mstep (&Mode, Param, &StpNum, &Flag);
extern void tcm-mstepfint*,unsigned long*, int*);
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
-tom-nstep proc far push bp
mov bp,sp
dword pointer return address
;
save base pointer
:
save stack pointer
:
; [bp+C] holds off set of Mode . .
.
.
; [bp+8] holds offset of Param
; [bp+lO] holds offset of StpNum
; [bp+12] holds offset of Flag
Program execution here
;
;
;
-restore bp & sp prior to exit
POP bp
ret
; return
,
-toxn_mstep endp
Other:
This information is provided for those wishing to create their own drivers:
.
-tcm-mstep is declared “PUBLIC” in the .ASM file
l tcm-mstep is declared “extern” in the “C” file l The .ASM file contains the “.model medium” directive (MASM & TASM only) l Add leading underscore l tcm-mstep must be in a segment fnameTEXT (where fname is the name of the file where
“-” to all tcm-mstep occurrences in .ASM file
tcm-mstep resides), else Linker returns an error.
Large Model
Model: Passes: Sequence:
Large (“-ml”) switch on command line dword size pointers (offset and DS register) Arguments Passed Right to Left
2-7
PCF-M5 USER GUIDE
Default Calling
Convention:
Example
Arguments Passed by Value
‘c’ Call: ‘c’ Declaration:
tcl-mstep (&Mode, Pawn, &StpNum, &Flag); extern void tcl-mstep(int*, unsigned long*, int?;
. ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
_tcl-mstep proc far
push bp mov bprsp
dword pointer return address
:
save base pointer
;
save stack pointer
: ; [bp+6] holds offset of Mode
.
.
; [bp+lO] holds offset of Param ; [bp+14] holds offset of StpNum ; [bp+18] holds offset of Flag
.
.
POP bp
ret
;return
Program execution here
;
I
*restore bp C sp prior to exit
I
_tcl-xnstep endp
Other:
This information is provided for those wishing to create their own drivers:
.
-tcl-mstep is declared “PUBLIC” in the .ASM file
l tcl-mstep is declared “extern” in the “C” file l The .ASM file contains the “.model large” directive (MASM & TASM only) l Add leading underscore “-”
l Both code & data use dword (segment/offset) pointers
l tcl-mstep must be in a segment fname_TEXT (where fname is the name of the file where tcl-mstep
to all tcl-mstep occurrences in .ASM file
resides), else Linker returns an error.
Turbo C Example
/* 1”
/* /* /* /* /*
Demonstration Program for MSTEP-5
Keithley Metrabyte Corporation
Language:
Borland Turbo "C"
File: TCSDEM0.C
*/ */ “1 */ */ */ */
2-8
#include <stdio.H> #include <stdlib.H> #include <string.H>
CHAPTER 2: INTERFACE DRIVERS
#&fine Beep printf("%s","\7")
#&fine TRYAGAIN 1 #&fine W-VIDEO 7 #define DEF-VIDEO 0 #define FUZADY 1 #&fine ON 1
#&fine OFF 0
/* make a beep sound */
/**********************************************************************/ /*
1”
/* /* /* /* /* /* /*
/**********************************************************************/
extern tcs-mstep(int *,unsigned *,long *,int *);
/*************************************************************************/
int modeO(void); int mo&l(void); int mode2 (void); int mode3 (void); int model(void); int mode5jvoid); int mode6(void); int mode7(void); int mode8(void); int modeg(void); int modelO(void); int modell(void); int model2(void); /* mode 12 */ int setchannel(void); int ErrHandler(int); int int CetLongInp(int,int,char *,long *);
void GetIntInp(int,int,char *,unsigned *);
voidprintat(int,int,int,char *); void ShowChannel(void); void EraseLine(int);
/**************************************************************~***************~
The Following are the function Calls for different models:
tcs-mstep(&Mode,Param,&StpNum,&Flag) tcm~mstep(&Mo&,Param,&StpNum,&Flag) tcl~mstep(&Mode,Param,&StpNum,&Flag)
This Program Uses the Small Model Function Call
/* DECLARE CALL structure */
MenuHandler(void);
: Turbo C small Model. */ : Turbo C medium Model. */ : Turbo C large Model. */
/* mode 0 */ /* mode 1 */ /* mode 2 */ /* mode 3 */ /* mode 4 */ /* mode 5 */ /* mode 6 */ /* mode 7 */ /* mode 8 */ /* mode 9 */ /* mode 10 */ /* mode 11 */
/* select channel /* error handler /* menu handler /* input get long integer /* input unsigned integer*/ /* formatted print function */ /* print current channel */ /* erase line
*/
*/ */
*/ "/ */
*/ */ */
*/
*/
int Mode=12,Flag=O,IntLev=7,Interrupt=OFF;
unsigned Param[lO],TP[lO];
long StpNuin;
2-9
PCF-M5 USER GUIDE
/*************************************************************************/ /*
/*
Main program
/* /*************************************f***********~~***~********~*********/
main0
I
int option,status=!TRYAGAIN;
/* default setup for MSTEP-5 */
*/
*/ */
TP[O] = 0;
TP Ill
TPVI
TP C31
= 255; = 100;
= 200; TP[4] = 2; TP[5] = 0; TP[6] = 0; TP[7] = 0; TP[I] = 0;
TP 191
= 768;
.
.
/* select channel A /* start up rate, 49 pps /* high speed run rate
*/ */ */
/* acceleration/deceleration pulse count */ /* 4 phase
/* full step /* inverted Sl-5 outputs /* internal clock /* switching off at standstill
/* base address
*/ */ */ */ */ */
/*************************************************************************/ /*
/*
Mode 12: Initialization.
/*
/*Arguments /*
/*
---------
None /* /*
Return values
-------------
*/
*/
1: repeat this mode */
again
0: no repeat
/* /**********************************************************~****************~
*/ */ */
"1 */ */
int model20
(
2-10
.
2.3 MICROSOFT PASCAL (V3.0 - 4.0)
Medium Model
CHAPTER 2: INTERFACE DRIVERS
Model: Passes: Sequence:
Medium word size pointers (offset address only) Arguments Passed Left to Right
Default Calling
Convention:
Arguments Passed by Value
Example
PASCAL Call: Result: PASCAL Declaration: PROCEDURE:
msp-mstep (Mode, Param,StpNum,Rlag) type darray = array[O-91 of word; msp-mstep(VAR Mode: integer; VAR param; darray; VAR StpNum:
integer4; VAR Flag: integer):extemal;
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
msp_mstep proc far :
push bp
mov bP,sP
far call (dword return address)
save base pointer
;
save stack pointer
:
; [bp+G] holds offset of Flag ; [bp+8] holds offset of StpNum
. . . . .
mov ax,n
POP bp ret 8 ;
return and pop bp & 3p values prior to exit
; [bp+lO] holds offset of Param ; [bp+12] holds offset of Mode
Program execution here
; ; :
Return Value for Function In ax register
;
;
msp-nstep endp
Other:
This information is provided for those wishing to create their own drivers:
l mspmstep is declared “PUBLIC” in the .ASM file l msp-mstep is declared external in the calling program l msp-mstep resides in segment-TEXT (default of the .model command)
2-11
PCF-M5 USER GUIDE
Microsoft PASCAL Example
PROGRAM MSPDEMO(Input,Output);
(*************************************************************************) (* Demonstration program for MSTEP-5
(* Keithley Metrabyte Corporation (*
(* Language: (* File: MSPDFMO.PAS
(* "1 (* To Compile:
(*
(” “1 (********k****************************************************************)
TYPE DARRAY =
FUNCTION TICS:WORD;EXTERN; FUNCTION KEYRD:WORD;EXTERN;
PROCEDURE MSP-MSTEP( VAR Mode:INTEGER;VAR Param:DARRAY;VAR StpNum:INTEGERI;VAR Flag:INTEGER);EXTERN;
Microsoft Pascal
Type: PL MSPDEWO.PAS ;
ARRAY[O..9] of WORD;
"1 "1 "1 "1 "1
*I
“1
(************X************************************************************) (*
(*Mode 12: Initialization
“1
*I
(" "1 (***t*********************************************************************)
PROCEDURE ModelP;
VAR count,option:INTEGER;
BEGIN
END;
.
(******x******************************************************************) (" *I
(" ("
Main
"1 *I
(*******************************************************************~*****)
2-12
BEGIN
CHAPTER 2: INTERFACE DRIVERS
TP[O] := 0;
TP Ill
TP [21
TP t31
:= 255;
:= 100; := 200;
TP[4] := 2;
TP[S] := 0;
TP[6] := 0;
TP[7] := 0;
TP[8] := 0;
TP t91
StpNum
:= 768;
:= 0;Flag
(* select channel A (* start up rate, 49 pps (* high speed run rate (* acceleration/deceleration pulse count *) (* 4 phase (* full step (* inverted Sl-5 outputs (* internal clock (* switching off at standstill (* base address
:= 0;IntLev := 7;
*I *I "1
*I *I "1 "1 *I *I
2.4 BORLAND TURBO PASCAL (VER 3.0 - 4.0)
Borland's Turbo PASCAL supports a compact and a large memory model. The compact model supports one code segment and multiple data segments. In this model, the code segment is limited to f54K with assembly routine calls being near calls. The data segment is unlimited. The large model permits unlimited code and data segments with assembly calls and data access being far calls.
The program (TINST.EXE) shipped with TURBO PASCAL can change the calling convention so that the user may not know which convention they are using. The default state is “OFF” or compact mode. In order to ascertain which mode you are using, run the “TINST.EXE” program.
Compact Model
Model: Passes: Sequence:
Default Calling
Convention:
Example
PASCAL Call: PASCAL Declaration: PROCEDURE:
Compact (Forces far call “OFF” in TINST.EXE) dword size pointers (offset and segment) Arguments Passed Left to Right
Arguments Passed by Value
tp-mstep (Mode, Param, StpNum, Flag); type darray = array[O-91 of word; tp-mstep(VAR M
o d e: integer;VAR Param: darray;VAR StpNum:
integer4;VAR Flag: integer):external;
2-13
PCF-MS USER GUIDE
.ASM Subroutine:
(Either Model)
The following assembly code shows how the driver handles user arguments:
tp-mstep proc near
push bp mov bp,sp
. .
.
near call (single word return address)
;
save base pointer
;
save stack pointer
; ; [bp+4] holds offset of Flag ; [bp+8] holds offset of StpNuxn ; [bp+12] holds offset of Param ; [bp+16] holds offset of Mode
.
.
mov ax,n
Program execution here
:
i
return Value for Function In ax register
:
POP bp
ret 16
return 6 pop values prior to exit
;
tp-mstep endp
Other:
This information is provided for those wishing to create their own drivers:
. Use the $L ‘Metacommand’ to link the object file containing external function tp-mstep, i.e. {$l
turbopas} (Link to file turbopas.obj).
. The VAR declarative forces pass by reference (address of variable) in the function declaration.
Default is pass by value (pushing the actual integer value onto the stack).
l tp-mstep is declared external in the calling program . Remember that in PASCAL, functions return
a value whereas procedures never do.
l The .ASM file contains an explicit declaration of the code segment containing tp-mstep. Turbo
PASCAL handles segments in a primitive manner which is not compatible with the ‘.model’ statements available in MASM or TASM. The function tp-mstep must reside in a segment called ‘CODE’! Turbo PASCAL will not accept any other segment name. If tp-mstep is not in segment “CODE”, the linker returns an “unresolved external” error. The Segment Declaration for “CODE” in the .ASM file must appear as:
CODE SEGMENT WORD PUBLIC ASSUME CS:CODE . .
; CODE GOES HERE
;~ODE ENDS
Large Model
Model: Passes: Sequence:
Large (Forces far call “ON” in TINST.EXE) dword size pointers (offset and segment) Arguments Passed Left to Right
2-14
Default Calling
Convention:
Example
CHAPTER 2: INTERFACE DRIVERS
Arguments Passed by Value
PASCAL Call: PASCAL Declaration: PROCEDURE:
tp-mstep (Mode, Param, StpNum, Flag); type darray = array[O-91 of word;
tp-mstep(VAR Mode: integer;VAR Param: darray;VAR StpNum:
integer4;VAR Flag: integer):external;
.ASM Subroutlne:
(Either Model)
The following assembly code shows how the driver handles user arguments:
tp_mstep proc far
push bp mov bptsp
far call (dword return address)
;
save base pointer
;
- save stack pointer
. ; [bp+6] holds dwo:d of VAR4
- [bp+lO] holds dword of VAR3
. ,
[bp+14] holds dword of VAR2
. ;
- [bp+18] holds dword of VARl
. ,
Program execution here
. ;
. i . ;
mov ax,n
return Value for Function In ax register
;
POP bp
ret 16
return & pop values prior to exit
;
tp-mstep endp
Other:
This information is provided for those wishing to create their own drivers:
l Use the $L ‘Metacommand’ to link the object file containing external function tp-mstep. For
example; ($1 turbopas) (Link file turbopas.obj).
. The VAR declarative forces pass by reference (address of variable) in the function declaration.
Default is pass by value (pushing the actual integer value onto the stack).
l tp-mstep is declared external in the calling program along with the type of return value (integer).
Remember, in PASCAL, functions return a value procedures don’t.
. The ASM file contains an explicit declaration of the code segment containing tp-mstep.
Turbo PASCAL Example
PROGRAM TP-DEMO(Input,Output);
{$L TURBOPAS) ($1-1
USES CRT,DOS;
2-15
PCF-M5 USER GUIDE
(*******************R******************************************)
(* Demonstration program for MSTEP-5 (* Keithley Metrabyte Corporation
(" (* Language:
Borland Turbo Pascal
(* File: TP-DEMO.PAS t*
(* To Compile: (*
Type:
TPC TP-DEMO.PAS ;
i* (*********k***************************************************)
TYPE DARRAY = ARRAY[O..g] of WORD; LABEL CONTINUE,QUIT; PROCEDURE TP_MSTEP(
VAR Mode:INTEGER;VAR Param:DARRAY;VAR StpNum:LONGINT;VAR
Flag:INTEGER);EXTERNAL;
(****************R********************************************) (*
(*Mode 12: Initialization
t* (*k***********************************************************)
PROCEDURE Model2;
LABEL BREAKOUT;
VAR count,option:INTEGER;
DONE
: BOOLEAN;
BEGIN
*I "1 *I "1 "1 "1 *I *I "I
*I
"1
*I
.
END;
(********************************************************~**~*) t*
("
Main
t* (*************************************************************)
2-16
*I "1 *I
BEGIN
CHAPTER 2: INTERFACE DRIVERS
TPCOI
TP Ill ‘J!P t21
TP 131 TPC41 TP [51 TPC61 ‘JX’C71 TPC81
TPC91
StpNum
:=
0;
:= 255;
:= 100; := 200;
:=
2;
:=
0;
:=
0;
:'
0;
:=
0;
:= 768;
:= 0;Flag
(* select channel A (* start up rate, 49 pps (* high speed run rate (* acceleration/deceleration pulse count *) (* 4 phase (* full step (* inverted Sl-5 outputs (* internal clock (* switching off at standstill (* base address
:= 0;IntLev := 7;
END.
2.5 MICROSOFT FORTRAN (V4.0 AND UP)
*I *) *I
"1 *) "1 *I *I "1
Large Model
Model: Passes:
Sequence:
Default Calling
Convention:
Example
FORTRAN Call: FORTRAN Declaration:
.ASM Subroutines:
NOTE: FORTRAN integer functions (beginning with letters i, j, or k) return results in the ax
register whereas non-integer functions reserve 4 bytes on the calling stack for a far pointer to the result. Non-integer functions pass their arguments starting at location bp+18 after the “push bp” and “mov bp,sp” instructions have been executed. Keithley MetraByte’s FORTRAN <--> Assembly routines predominantly use type integer to avoid the non-integer problem. pointers, floating point results, long integers, etc. The user should use the IMPLICIT
INTEGER (A-Z) declaration causing all Functions and Variables to be implicitly type
Large dword size pointers (offset and DS register)
Arguments Passed Left to Right
Arguments Passed by Reference
call fmstep(Mode, Param( StpNum, Flag); None necessary in FORTRAN source file (Fortran assumes that
undeclared subroutines or functions are external. It is left to the linking process to provide the required .LIB or .OBJ files. However, the function name should conform to ANSI FORTRAN rules for integer functions.
Using non-integer functions may be a problem when returning
2- 17
PCF-M5 USER GUIDE
integer unless declared otherwise. Also note that FORTRAN calls by Reference. This method places the address of the passed parameters (rather than the parameters themselves) onto the stack at the time of the call to any function or subroutine. As a convenience, PCF-M5 provides functions UNBYT and OUTBYT) for directly addressing the registers and (KEYHOT and KEYRD) for checking Hot Key and reading a key from the keyboard.
Integer (Default) Function or Subroutine
The following assembly code shows how the driver handles user arguments:
frnstep proc far
push bp mcv bprsp
. . .
dword pointer return address
;
save base pointer
;
save stack pointer
; ; [bp+6] holds offset of Flag ; [bp+lO] holds offset of StpNum ; [bp+14] holds offset of Param ; [bp+18] holds offset of Mode
.
mov ax,n
Program execution here
;
.
I
i
return Value for Function In ax register
;
POP bp
ret ;
fmstep endp
NOTES:
1.
VAR3 = Return Value of Function
2. Function fmstep must be declared as an integer * 2 fucntion.
Microsoft FORTRAN Example
C************************************************************~***** c
C C C C C C
c****************************************************************
Demonstration program for MSTEP-5
Keithley Metrabyte Corporation
Language:
Microsoft Fortran
File: MSFDEMO.FOR
program msfdemc
2-18
characterNULL,ESC,ch integer*2 key,Mode,Flag,IntLev,Param(lO),TemPar(lO) integer*4 StpNum
COMMON COMMON COMMON
COMMON
/ASCII/NULL,ESC /ARG/Mode,Flag,Param,StpNum
/TEMPL?iTE/TemPar
/INTERRUPT/IntLev
CHAPTER 2: INTERFACE DRIVERS
C
C
C
C
C
C
C
C
C
C
ESC NULL
= char(27) = char(O)
select channel A
TemPar(1) = 0
start up rate, 49 pps
TemPar (2) = 255
high speed run rate
TemPar(3)
= 100
acceleration/deceleration pulse count
TemPar(4) = 200
4 phase
TemPar(5) = 2
full step
TmPar(6) = 0
inverted Sl-5 outputs
TemPar(7) = 0
internal clock
TemPar(8) = 0
switching off at standstill
TemPar(9) = 0
base address
TemPar(l0) = 768
end
c*************************************************************** C
C
MO& 12: Initialization
C c****************************************************************
subroutine model2(*)
integer*2 Flag,Param(lO),Mode,TemPar (lo), index,i
integer*4 StpNum COMMON COMMON
/ARG/Mode,Flag,Param,StpNum /TEMPLATE/TexnPar
Mode=12
Flag=0
end
2 - 19
PCF-M5 USER GUIDE
2.6 MSTEP.LIB GENERAL PURPOSE LIBRARY
mstep.LIB
This is a general purpose library file which provides control of the MSTEP-5 boards. This file can be linked with programs written in C, PASCAL, or FORTRAN to provide access to the MSTEP-5 operating modes.
NOTE: This library cannot be used with TurboPASCAL. However, TurboPASCAL may be
used with Turbops.obj (see below).
The following is a brief description of the available call routines:
mscs-mstep(mode,param,stpnum,flag)
: Call from Microsoft C Small Model
mscm_mstep(mode,param,stpnum,flag1 . Call from Microsoft C Medium Model mscl-mstep(mode,param,stpnum,flag) tcs-mstep(mode,param,stpnum,fIag) tcm-mstep(mode,param,stpnum,flag)
:
Call from Microsoft C Large Model Call from Turbo C Small Model
Call from Turbo C Medium Model tcl-mstep(mode,param,stpnum,flag) Call from Turbo C Large Model msp-mstep(mode,param,stpnum,flag)
Call from Microsoft PASCAL fmstep(mode,param,stpnum,flag) Call from Microsoft FORTRAN
Linking the Library “mstep.lib” to the user program is accomplished after program compilation by including it in the link line as follows:
link userprog.obj,userprog,,user.lib_mstep.LIB;
userprog.obj is an object module produced by compilation of the user program. userprog should be used for the resultant executable .EXE file. user.lib is any other user library, if applicable.
To create the MSTE.LIB Library for PASCAL, C, or FORTRAN:
MASM /DBIN=O MSTEP.ASM MASM /DBIN=O MSTEPPCF.ASM
LIB MSTEP+MSTEPtMSTEPPCF:
To create the MSTEP.QLB library for QuickBASIC 4.5:
MASM /DBIN=O MSTEP.ASM
MASM /DBIN=O MSTEPPCF.ASM
LINK /Q MSTEP.OBJ QBX.LIB,,,QBXQLB.LIB
To create the MSTE.BIN for BASIC:
MAIM /DBIN=~ MSTE.ASM MASM /DBIN=~ MSTEPPCF.ASM
2-20
LINK MSTEPPCF t MSTE,MSTEP; EXEPBIN MSTEP.EXE MSTEP.COM
MAKEBIN MSTEP.COM
For TurboPASCAL, the entry point is:
CHAPTER 2: INTERFACE DRIVERS
tp-rastep (mode,param,stpnum,flag)
:Call from TurboPASCAL program
The user program should have the directive
{$L turbopas}
at the beginning of the user program. This directive will ensure that the TPC compiler/linker will include the proper interface object.
TURBOPAS.OBJ
(from the PCF-PIOINT disk)
2 - 21
PCF-M5 USER GUIDE
* * * * *
2-22
CHAPTER
BASIC INTERFACE DRIVERS
3.1 INTERPRETED BASIC (GW, COMPAQ, IBM, ETC.)
Medium Model (Only Model Available)
3
Model: Passes: Sequence:
Default Calling
Convention:
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
Location 0 (Beginning of Code Segment)
mstep proc far
push bp mcv bprsp
Medium (Far Calls, Single Data)
word size pointers (offset and no DS Register) Arguments Passed Left to Right
Arguments Passed by Reference
far call (dword return address)
;
save base pointer
;
save stack pointer
; ; [bpt6] holds offset of Flag%
[bpt8] holds offset of STP#
;
[bptlO] holds offset of D%
; ; [bpt12] holds offset of MD%
Program execution here
;
restore bp 6 sp prior to exit
POP bp
ret
mstep endp
Example:
Refer to Section 4.15 of the MSTEP-5 User Guide.
NOTE BASIC requires that the .BIN file containing the callable subroutine “mstep(Mode%,
D%(O), STP#, Flag%)’ reside at location 0 in the .ASM segment or to “jmp” (unconditional jump) to the .BIN file. A BASIC “jmp ” will always jump to location 0 in the .ASM code
segment.
:
3-1
PCF-M5 USER GUIDE
Creation of a .BIN file is accomplished as follows:
1. Create the .ASM Source Code File ‘EXAMPLE.ASM’
2. Assemble ‘EXAMPLE.ASM’ thus creating ‘EXAMPLE.OBJ Link ‘EXAMPLE.OBJ’ to create ‘EXAMPLE.EXE
3.
4. Run EXE2BIN on ‘EXAMPLE.EXE’ (DOS Utility) to create ‘EXAMPLE.COM
5. Run MAKEBNEXE (Keithley MetraByte Utility) on ‘EXAMPLE.COM’ to create
‘EXAMPLE.BlN
3.2 QUICKBASIC
MASM EXAMPLE ; LINK EXAMPLE ; EXEZBIN EXAMPLE.EXE EXAMPLECOM MAKEBIN EXAMPLE.COM
Medium Model (Only Model Available)
Model: Medium (far Calls, Single Data). Passes: Word-size pointers (Offset and no DS Register). Sequence: Arguments passed left-to-right. Default Calling
Convention: Arguments passed by reference.
.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:
QBPIOINT proc far
push bp mmr bp,sp
.
. .
far call (dword return address)
;
save base pointer
;
save stack pointer
;
; [bpt6] holds offset of Flag% ; [bp+8] holds offset of D%
[bp+lO] holds offset of STP#
; ; [bptlP] holds offset of MD%
Program execution here
;
POP bp
ret
QBPIOINT endp
3-2
restore bp & sp prior to exit
;
Example:
Refer to Section 4.16 of the MSTEP-5 User Guide.
CHAPTER 3: BASIC INTERFACE DRIVERS
NOTE
When creating a .QLB file, it is good practice to make a .LIB of the same version as a backup file.
Creation of a .QLB file is accomplished as follows:
1. Create the .ASM Source Code File ‘EXAMPLE.ASM
2. Assemble ‘EXAMPLE.ASM’ thus creating ‘EXAMPLE.OBJ’
Link ‘EXAMPLE.OBJ’ with the “/q” option to create ‘EXAMPLE.QLB
3.
MASM EXAMPLE ; LINK /q EXAMPLE ;
A .LIB file is created by:
1. Create the .ASM Source Code File ‘EXAMPLE.ASM
2. Assemble ‘EXAMPLE.ASM’ thus creating ‘EXAMPLE.OBJ’
Use Utility LIB.EXE to add EXAMPLE.OBJ to ‘EXAMPLE.LIB’
3.
(Remove old EXAMPLE.OBJ from Library)
LIB EXAMPLE.LIB -EXAMPLE
(Create New .OBJ)
(Add New .OBJ to Library)
To use the .QLB file in the QB integrated environment/editor, invoke QB.EXE with
4.
MASM EXAMPLE ; LIB EXAMPLE,LIB +EXAMPLE ;
the /l option (QB /l qlbname.qlb,) where qlbname.qlb is the file containing BASICsub.
5. To use the .LIB file with the command line complier (BC.EXE), simply specify “EXAMPLE.LIB” in the link process.
3-3
PCF-MS USER GUIDE
* * * * *
3-4
Loading...