DECLARE FUNCTION AskForBaseAddress% (OldOne AS INTEGER) DECLARE FUNCTION Deci% (DS AS STRING) DECLARE SUB WaitForUser () 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 "* *" PRINT "***************************************************************************" WaitForUser '*************************************************************************** '* * '* 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 ' ' Prompt user for card's base address and set global base variable ' accordingly. ' BaseAddr% = AskForBaseAddress(&H350) PRINT "SET BUFFERS " FOR channelnum = 0 TO 16 ' set all 16 buffers to 0 OUT BaseAddr% + (2 * channelnum), &H0 OUT BaseAddr% + (2 * channelnum + 1), &H0 NEXT channelnum channelnum = INP(BaseAddr% + 10) ' remove from simultaneous ' mode and update all ' channels channelnum = INP(BaseAddr% + 15) ' Release zero latch PRINT "MENU" 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" CLS PRINT "" PRINT "Quick Basic sample #2 complete." 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 PRINT INPUT ; "Enter the DAC number you wish to output to (0 through 15): "; dacnum% dacnum% = dacnum% MOD 16 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 BaseAddr% + dacnum * 2, lowbyte% OUT BaseAddr% + (dacnum * 2 + 1), hibyte% NEXT i& LOOP UNTIL INKEY$ <> "" OUT BaseAddr% + dacnum * 2, 0 ' set DAC to 0 output OUT BaseAddr% + (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 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