{***************************************************************************** * SAMPLE5.PAS : DIGITAL OUTPUT * * * * This is a demonstration program to be used with the AD12-16 A/D * * board. The program will prompt the user for a digital value between 0 * * 15. The program will output this value to digital output bits and then * * read it back on the digital input channels. This demos setting the * * digital output bits(task 13)and reading the digital input bits(task 14). * * * * The board should be set as follows: * * -- IRQ5 is used for interrupts * * -- Polarity set to bipolar * * -- DMA channel 1 * * -- On board clock set to 1 MHz * * Also, the following jumps should be installed. * * -- OP0 pin 23 to IP0 pin 25 * * -- OP1 pin 4 to IP1 pin 6 * * -- OP2 pin 22 to IP2 pin 24 * * -- OP3 pin 3 to IP3 pin 5 * * * * LAST MODIFICATION: 2/3/98 * * * *****************************************************************************} program startup; {$L a16drv} {$F+} USES crt; type param_array = array[1..5] of integer; { all of the parameters passed to the A16DRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; params : param_array; ch : char; procedure a16drv(t_off:word;p_off:word;st_off:word);external; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (0000-FFFF) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if (error=0) then begin Success := 1; Dummy := NewOne; end else if (Msg = '') then begin GotoXY(AddrInputPosX, AddrInputPosY); WriteLn(OldOne); Msg := OldOne; Success := 1; Val('$' + Msg, Dummy, Error); end; until (Success = 1); AskForBaseAddress := Dummy; end; { end of AskForBaseAddress } {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a16drv - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; var t_off,p_off,st_off : word; begin { this section extracts the offset of the parameters that we will pass to the assembly driver } t_off := ofs(task); p_off := ofs(params[1]); st_off := ofs(status); status := 0; a16drv(t_off,p_off,st_off); { this section checks for an error code } if status > 0 then begin WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * *****************************************************************************} procedure setup(Address:word); var I :integer; begin { initialize the board } task := 0; params[1] := Address; { starting board address } params[2] := 5; { IRQ5 } params[3] := 1; { DMA channel 1 } call_driver; { call routine to call ext module } if status <> 0 then exit; end; {procedure setup } {***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: Prompts for a digital value, writes it then reads it back. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * *****************************************************************************} procedure get_readings; var I :integer; begin ClrScr; { fetch the digital value to output} WriteLn;WriteLn; write('Enter the digital value to output(0 - 15): '); readln(params[1]); { write the counts to the digital outputs } task := 13; call_driver; { call routine to call ext module } if status <> 0 then exit; { if status > 0 then error } { delay for a little } I := 0; while I < 1000 do I:=I+1; { read the digital inputs} task := 14; call_driver; { now display the digital inputs } WriteLn; WriteLn('The value read back is:',params[1]); end; { get_readings } {************************************************************************** * PROCEDURE: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - write and read the digital values. * * * * OUTPUT: None. * * * **************************************************************************} var Address:word; BEGIN ClrScr; WriteLn(' SAMPLE5.PAS : DIGITAL OUTPUT '); WriteLn; WriteLn('This is a demonstration program to be used with the AD12-16 A/D '); WriteLn('board. The program will prompt the user for a digital value between 0 '); WriteLn('15. The program will output this value to digital output bits and then '); WriteLn('read it back on the digital input channels. This demos setting the '); WriteLn('digital output bits(task 13)and reading the digital input bits(task 14). '); WriteLn; WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- IRQ5 is used for interrupts (required)'); WriteLn(' -- Polarity set to bipolar (required)'); WriteLn(' -- DMA channel 1 (required)'); WriteLn(' -- On board clock set to 1 MHz (required)'); WriteLn(' -- Also, the following jumps should be installed.'); WriteLn(' -- OP0 pin 23 to IP0 pin 25'); WriteLn(' -- OP1 pin 4 to IP1 pin 6'); WriteLn(' -- OP2 pin 22 to IP2 pin 24'); WriteLn(' -- OP3 pin 3 to IP3 pin 5'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press any key to continue, or press E to exit.'); ch := ReadKey; setup(Address); { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin { display current values for the 8 channels } get_readings; if status = 0 then begin { if status > 0 then error } { check for program exit } WriteLn; WriteLn('Press E to exit the program. Press any other key to rescan the data...'); ch:=ReadKey; { wait for key press } end; end; END. { main program }