DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT "***************************************************************************" PRINT "* QuickBASIC SAMPLE #2: QSAMPLE2.BAS *" PRINT "* *" PRINT "* This sample will generate 3 different wave forms, sine, triangle and *" PRINT "* saw tooth. The user has the choice of base address, DAC number and the*" PRINT "* number of points per cycle. *" PRINT "* *" PRINT "* Board Configuration: *" PRINT "* -- Base address should be set to the address which will be entered *" PRINT "* during program execution. *" PRINT "* -- All remaining jumper settings are irrelevant. *" PRINT "* *" '* LAST MODIFICATION: 2/5/98 * '* * PRINT "***************************************************************************" PRINT : PRINT : PRINT INPUT "Press ENTER to continue"; Msg$ '*************************************************************************** '* * '* FUNCTION: main - local routine * '* * '* PURPOSE: Controls program execution. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** CONST PI = 3.1415927# DIM progstruct&(10000) ' buffer to hold points CLS DO GOSUB menulist ' display menu IF menuchoice$ = "1" THEN GOSUB setparms ' fetch system params ELSEIF menuchoice$ = "2" THEN GOSUB sinecurve ' generate sine wave ELSEIF menuchoice$ = "3" THEN GOSUB trianglecurve ' generate triangle wave ELSEIF menuchoice$ = "4" THEN GOSUB sawcurve ' generate saw tooth wave END IF LOOP UNTIL menuchoice$ = "5" END '*************************************************************************** '* * '* FUNCTION: menulist - local routine * '* * '* PURPOSE: Display the menu choise on the screen. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** menulist: CLS PRINT PRINT PRINT PRINT "Your menu selections are: " PRINT "1. Input Board Data (do this first)" PRINT "2. Sine curve" PRINT "3. Triangle curve " PRINT "4. Saw curve" PRINT "5. End program, return to DOS" PRINT "Input Choice: " menuchoice$ = INPUT$(1) RETURN '*************************************************************************** '* * '* FUNCTION: setparams - local routine * '* * '* PURPOSE: Prompts the user for DAC number, base address and the number * '* of points per cycle. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** setparms: CLS CLS Address% = AskForBaseAddress!(&H350) PRINT : PRINT : PRINT PRINT "Enter the DAC number (0 through 5 only): " DO LOCATE 7, 42 PRINT " " dacnum$ = INPUT$(1) LOCATE 7, 42 PRINT dacnum$ dacnum = VAL(dacnum$) LOOP WHILE dacnum < 0 OR dacnum > 5 PRINT : PRINT : PRINT PRINT "Enter the number of points you wish to calculate per cycle," INPUT ; "(10000 maximum, program will use modulus if needed): "; counts& counts& = counts& MOD 10001 RETURN '*************************************************************************** '* * '* FUNCTION: sinecurve - local routine * '* * '* PURPOSE: Calculate the points for creating a sine wave. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '***************************************************************************) sinecurve: IF counts& = 0 THEN RETURN ' no point -- no curve CLS PRINT "Calculating sine wave points....." rads# = 2! * PI / counts& ' rad per count FOR i& = 1 TO counts& sine# = (SIN(rads# * (i& - 1)) + 1!) * 2047 progstruct&(i&) = sine# NEXT i& CLS PRINT "Generating sine wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* * '* FUNCTION: trianglecurve - local routine * '* * '* PURPOSE: Calculate the points for creating a triangle wave. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** trianglecurve: IF counts& = 0 THEN RETURN ' no counts -- no curve CLS PRINT "Calculating triangle wave points....." slope# = 4095! / counts& * 2! ' wave form slope FOR i& = 1 TO counts& / 2 temp# = INT(slope# * i&) progstruct&(i&) = temp# progstruct&(i& + INT(counts& / 2)) = (4095 - temp#) NEXT i& CLS PRINT "Generating triangle wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* * '* FUNCTION: sawcurve - local routine * '* * '* PURPOSE: Calculate the points for creating a saw tooth wave. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** sawcurve: IF counts& = 0 THEN RETURN CLS PRINT "Calculating saw tooth wave points....." slope# = 4095 / counts& ' saw tooth slope FOR i& = 1 TO counts& progstruct&(i&) = INT(slope# * i&) NEXT i& CLS PRINT "Generating saw tooth wave, press any key to stop...." GOSUB sendtoport RETURN '*************************************************************************** '* * '* FUNCTION: sendtoport - local routine * '* * '* PURPOSE: Writes the point buffer to the DAC until a key is pressed. * '* * '* INPUT: None. * '* * '* CALLS: None. * '* * '* OUTPUT: None. * '* * '*************************************************************************** sendtoport: ' each point is broken into the hi byte and low byte, and then written to ' the DAC into two seperate bytes. *) DO FOR i& = 1 TO counts& temp# = INT(progstruct&(i&) MOD 256) lowbyte% = temp# temp# = INT(progstruct&(i&) / 256) hibyte% = temp# OUT Address% + dacnum * 2, lowbyte% OUT Address% + (dacnum * 2 + 1), hibyte% NEXT i& LOOP UNTIL INKEY$ <> "" OUT Address% + dacnum * 2, 0 ' set DAC to 0 output OUT Address% + (dacnum * 2 + 1), 0 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