DECLARE FUNCTION AskForBaseAddress (OldOne AS INTEGER) '************************************************************************* '* This sample program will sequentially turn on all bits in port a and * '* then seqencially turn them off. Each time it sets a new bit, both * '* port a and port b 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 8255 chip. If the port a pins are jumpered to the port b pins, * '* then a board test program results, with port b being used to verify * '* what has been written to port a. The program will use port 0 of cards * '* with mulitple 8255's. * '************************************************************************* ' DIM CURRENT%(3) ' 'print the string display ' CLS PRINT " SAMPLE 1.BAS : Read/Write" PRINT PRINT "This sample program will sequentially turn on all bits in port a and" PRINT "then seqencially turn them off. This demonstrates how to read and" PRINT "write to a port, and to use the read back function of the 8255 chip." LOCATE 7, 1 Address% = AskForBaseAddress(&H300) CLS PRINT PRINT PRINT "Board Configuration" PRINT PRINT " -- Base Address is "; HEX$(Address%); " hex" PRINT " -- The IRQ5 jumper should be installed (required)" PRINT " -- The TST/BEN jumper should be in the BEN position (required)" PRINT " -- All other jumper settings are irrelevant." PRINT PRINT PRINT PRINT "Press a key to continue" a$ = INPUT$(1) CLS LOCATE 1, 15 PRINT " I O D C A R D S A M P L E P R O G R A M " LOCATE 4, 15 PRINT "Connect a loopback cable from PORT A to PORT B of PPI0." LOCATE 13, 28 PRINT "PRESS ANY KEY TO CONTINUE." a$ = INPUT$(1) LOCATE 9, 17 PRINT " PORT A OUTPUT PORT A INPUT PORT B INPUT " LOCATE 10, 17 PRINT " ------------- ------------ ------------ " LOCATE 13, 28 PRINT " PRESS F1 TO EXIT PROGRAM " ' 'main control loop ' OUT Address% + 3, &H8B 'send the control byte 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 port a CURRENT%(1) = INP(Address%) 'read back back what we wrote to port A CURRENT%(2) = INP(Address% +1 ) 'read the data on port B ' 'write the data to the screen ' X = 20 '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 11, X VALUE1% = VALUE% MOD 2 IF VALUE1% = 1 THEN PRINT "1" ELSE PRINT "0" IF VALUE1% = 1 THEN VALUE% = (VALUE% - 1) / 2 ELSE VALUE% = VALUE% / 2 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