DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '************************************************************************* '* This sample program will sequentially turn on all bits of the relay * '* output, then seqencially turn them off. Each time it sets a new bit, * * '* both the relay output and the opto input are read and the data * '* displayed. This demonstrates how to read and write to a port, and to * '* use the read back function of the board. * '************************************************************************* ' DIM CURRENT%(3) ' 'print the string display ' CLS LOCATE 1, 4 PRINT " I I R O - 8 C A R D S A M P L E P R O G R A M " PRINT PRINT "This sample program will sequentially turn on all bits of the relay " PRINT "output, then sequentially turn them off. Each time it sets a new bit," PRINT "both the relay output and the opto input are read and the data " PRINT "displayed. This demonstrates how to read and write to a port, and to" PRINT "use the read back function of the board." PRINT : PRINT Address% = AskForBaseAddress!(&H354) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(Address%); " hex" PRINT " -- The IRQ5 jumper should be installed. (required)" PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT PRINT "Press any key to continue" msg$ = INPUT$(1) CLS LOCATE 5, 14 PRINT " RELAY OUTPUT RELAY READBACK OPTO INPUT " LOCATE 6, 14 PRINT " ------------- -------------- ---------- " LOCATE 14, 25 PRINT " PRESS F1 TO EXIT PROGRAM " ' 'main control loop ' CURRENT(0) = 0 SHIFTLEFT% = 1 ON KEY(1) GOSUB QUIT KEY(1) ON ' 'this loop will repeat endlessly until F1 is pressed ' CONT: OUT Address%, CURRENT%(0) 'write value to relay output CURRENT%(1) = INP(Address%) 'read back back what we wrote to relays CURRENT%(2) = INP(Address% + 1)'read the data on opto input ' 'write the data to the screen ' X = 17 'starting x coordinate to write data to screen FOR INDEX = 0 TO 2 'for each array member VALUE% = CURRENT%(INDEX) FOR INDEX1 = 0 TO 7 'for each bit in array member */ LOCATE 8, X VALUE1% = VALUE% MOD 2 IF VALUE1% = 1 THEN PRINT "1" ELSE PRINT "0" VALUE% = (VALUE% - 1) / 2 ' roll next display bit X = X + 1 NEXT INDEX1 X = X + 10 NEXT INDEX ' 'compute value to turn on/off next bit in line ' IF CURRENT%(0) = 0 THEN SHIFTLEFT = 1 IF CURRENT%(0) = 255 THEN SHIFTLEFT = 0 IF SHIFTLEFT = 1 THEN CURRENT%(0) = CURRENT%(0) * 2 + 1 IF SHIFTLEFT = 0 THEN CURRENT%(0) = (CURRENT%(0) - 1) / 2 FOR X = 0 TO 3500: Y = Y + 1: NEXT X GOTO CONT QUIT: CLS END 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