DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT "****************************************************************************" PRINT "* QuickBASIC SAMPLE #1: QSAMPLE1.BAS *" PRINT "* *" PRINT "* This sample will prompt the user for a voltage between 0 and 10 volts, *" PRINT "* then calculate the actual voltage based on the resolution of the DAC and*" PRINT "* output the voltage to the desired DAC channel. *" PRINT "* *" PRINT "* *" '* LAST MODIFICATION: February 5, 1996 * '* * PRINT "****************************************************************************" '**************************************************************************** '* * '* FUNCTION: main program - global routine * '* * '* PURPOSE: Controls overall program execution and determines exit. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '**************************************************************************** PRINT "Board Configuration:" PRINT PRINT "--The Base Address should be set to the address which will be" PRINT " entered during program execution." PRINT "--DACs must be placed in the 10V unipolar mode." PRINT "--2's complement jumper should be removed." PRINT : PRINT : PRINT Address% = AskForBaseAddress!(&H340) PRINT : PRINT DO CLS PRINT : PRINT : PRINT GOSUB writeDAC PRINT : PRINT : PRINT : PRINT PRINT "Would you like to output another value (Y or N)? " key$ = INPUT$(1) LOOP UNTIL key$ = "N" OR key$ = "n" OUT Address% + 8 + (2 * DACnumber), 0 OUT Address% + 8 + (2 * DACnumber + 1), 0 CLS END ' PROGRAM '**************************************************************************** '* * '* FUNCTION: writeDAC - local routine * '* * '* PURPOSE: Prompts the user for DAC number and voltage, then calculates * '* the actual output voltage based on resolution, displays it * '* and writes the value to the DAC. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '**************************************************************************** writeDAC: ' prompt for the DAC number and desired voltage. CLS PRINT : PRINT : PRINT PRINT "Enter the DAC number (0 through 1 only): " DO LOCATE 4, 42 PRINT " " DACnumber$ = INPUT$(1) LOCATE 4, 42 PRINT DACnumber$ DACnumber = VAL(DACnumber$) LOOP WHILE DACnumber < 0 OR DACnumber > 1 PRINT : PRINT : PRINT : PRINT : PRINT INPUT "Enter a voltage between 0.000v to 9.997v: ", voltage# WHILE voltage# < 0 OR voltage# > 9.997 LOCATE 10, 43 PRINT " " LOCATE 10, 43 INPUT ; voltage# WEND PRINT PRINT ' compute the digital output needed for this value and the actual voltage ' that will be expected, and display the voltage. counts# = voltage# / .002441 cnts& = counts# expected# = cnts& * .002441 PRINT : PRINT PRINT "Due to the 12-bit resolution of the DAC, you should expect " PRINT USING "to see a voltage of #.### "; expected# ' Prepare and write values to control word lowbyte% = cnts& MOD 256 hibyte% = INT(cnts& / 256) OUT Address% + 8 + (2 * DACnumber), lowbyte% OUT Address% + 8 + (2 * DACnumber + 1), hibyte% RETURN FUNCTION AskForBaseAddress (OldOne AS INTEGER) Msg$ = "" NewOne% = 0: Success = 0: Dummy% = 0 AddrInputPosX = 0: AddrInputPosY = 0 PRINT "Please enter the Base Address (0000-FFFF) for your card (in hex)" PRINT "or press ENTER for "; HEX$(OldOne%); "." PRINT ">"; AddrInputPosX = POS(0): AddrInputPosY = CSRLIN WHILE Success = 0 LOCATE AddrInputPosY, AddrInputPosX PRINT " " LOCATE AddrInputPosY, AddrInputPosX LINE INPUT Msg$ NewOne% = VAL("&H0" + LEFT$(Msg$, 4)) Success = 1 Dummy% = NewOne% ELSEIF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION