DECLARE FUNCTION AskForBaseAddress% (OldOne AS INTEGER) DECLARE FUNCTION Deci% (DS AS STRING) DECLARE SUB WaitForUser () 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 *" PRINT "* and output the voltage to the desired DAC channel. *" PRINT "* *" PRINT "* The following setup of the board is expected: *" PRINT "* þ All DAC voltage ranges should be set to 0v-10v unipolar. *" PRINT "* *" PRINT "****************************************************************************" WaitForUser '**************************************************************************** '* * '* FUNCTION: main program - global routine * '* * '* PURPOSE: Controls overall program execution and determines exit. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '**************************************************************************** ' ' Prompt user for card's base address BaseAddr% = AskForBaseAddress(&H350) ' ' Set all channels initially to zero FOR channelnum = 0 TO 16 ' set all 16 buffers to 0 OUT BaseAddr% + (2 * channelnum), &H80 OUT BaseAddr% + (2 * channelnum + 1), &H8 NEXT channelnum ' ' Release zero latch PortVal = INP(BaseAddr% + 15) ' ' Exit Simultaneous Update mode and update all channels channelnum = INP(BaseAddr% + 10) ' ' Program DAC ProgCh: CLS GOSUB writeDAC ' ' Prompt user if done ... ProgAgain: CLS PRINT "" PRINT "Would you like to program another DAC value (Y or N)? " Key$ = INPUT$(1) Key$ = UCASE$(Key$) IF Key$ = "Y" THEN GOTO ProgCh ELSEIF Key$ <> "N" THEN BEEP GOTO ProgAgain END IF CLS PRINT "" PRINT "Quick Basic sample #1 complete." 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: CLS GetDAC: INPUT "Enter DAC nunber (0 - 15): ", DACnumber% PRINT IF (DACnumber% > 15) OR (DACnumber% < 0) THEN BEEP PRINT "Invalid DAC number! Please try again." PRINT GOTO GetDAC END IF GetVoltage: INPUT "Enter a voltage between 0.000v to 9.997v: ", voltage# PRINT IF (voltage# < 0!) OR (voltage# > 9.998) THEN BEEP PRINT "Invalid voltage! Please try again." GOTO GetVoltage END IF ' Compute the digital output needed for this value and the actual voltage ' that will be expected, and display the voltage. counts# = voltage# / .002442 cnts& = counts# expected# = cnts& * .002442 PRINT PRINT "DAC has been programmed." 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 BaseAddr% + (2 * DACnumber), lowbyte% OUT BaseAddr% + (2 * DACnumber) + 1, hibyte% WaitForUser 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% IF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION FUNCTION Deci% (DS AS STRING) Deci% = VAL("&H" + DS) END FUNCTION SUB WaitForUser LOCATE 23, 1 PRINT "Press any key to continue ... " Key$ = "" WHILE Key$ = "" Key$ = INKEY$ WEND END SUB