DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) ' ' This program allows any relay to be turned on or off ' ' This program exects an IOD-24E board to be connected ' to a ROB-8 relay board. ' ' Set up the variables ' DIM RELAYS%(8) ' mask for each relay RELSTATE% = 255 ' start all HI which is off RELAYS%(1) = 1 ' first relay mask FOR I = 1 TO 7 ' set up the relay masks RELAYS%(I + 1) = RELAYS%(I) * 2 ' shift prev one left NEXT I ' Now initialize the board CWORD% = &H8B ' port A is OUT others are IN PORTA% = &H300 ' port address CADDR% = &H303 ' address for control word OUT CADDR%, CWORD% ' program the ports OUT PORTA%, RELSTATE%' turn off all relays ' Do menu selection here MENU: CLS PRINT " SAMPLE 1.BAS : ROB-08" PRINT PRINT "This program expects an IDO-24E board to be connected to a ROB-08." PRINT "This program has the ability to toggle any relay to the on or off" PRINT "positons." LOCATE 7, 1 PORTA% = AskForBaseAddress!(&H2A8) CADDR% = PORTA% + 3 CLS PRINT PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(PORTA%); " hex." PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT PRINT "Press a key to continue." ch$ = INPUT$(1) CLS CLS PRINT PRINT PRINT " RELAY DEMONSTRATION PROGRAM" PRINT PRINT PRINT " 1 Toggle any relay" PRINT " 2 RUN a simple sequence" PRINT " 3 Quit" PRINT SELCT: LOCATE 10, 1 INPUT " Please enter your selection:"; PICK PRINT "" IF PICK >= 1 AND PICK <= 3 THEN GOTO CONT PRINT " OUT OF RANGE, TRY AGAIN." GOTO SELCT CONT: ON PICK GOSUB TOGGLE, SEQUENCE, QUIT GOTO MENU ' This section will toggle a relay TOGGLE: CLS PRINT PRINT RETRY: INPUT "Enter relay number to toggle:"; REL IF REL >= 1 OR REL <= 8 THEN GOTO DOIT PRINT "Invalid relay number, try again." GOTO RETRY DOIT: TEMP% = NOT RELSTATE% RELSTATE% = NOT (TEMP% XOR RELAYS%(REL)) OUT PORTA%, RELSTATE% RETURN SEQUENCE: 'Performs a simple sequence by turn all relays off, then 'turning them on, one by one, then turning them off one by one RELSTATE% = 255 ' turn off the relays OUT PORTA%, RELSTATE% FOR REL = 1 TO 8 GOSUB DOIT ' turn on the relay FOR I = 1 TO 5000 NEXT I NEXT REL FOR I1 = 0 TO 7 REL = 8 - I1 GOSUB DOIT ' turn off the relay FOR I = 1 TO 5000 NEXT I NEXT I1 RETURN QUIT: ' Program exit 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