DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '************************************************************************* '* MODULE: SAMPLE8.BAS * '* * '* 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. * '* * '* LAST MODIFICATION: May 2, 1996 * '* * '************************************************************************* ' DIM CURRENT%(3) ' 'print the string display ' CLS PRINT " 8255 Digital I/O Sample Program " PRINT PRINT "This sample program will sequentially turn on all bits in port a and" PRINT "then seqencially turn them off. Each time it sets a new bit, both" PRINT "port a and port b are read and the data displayed. This demonstrates" PRINT "how to read and write to a port, and to use the read back function of" PRINT "the 8255 chip. If the port a pins are jumpered to the port b pins," PRINT "then a board test program results, with port b being used to verify" PRINT "what has been written to port a. The program will use port 0 of cards" PRINT "with mulitple 8255's." PRINT : PRINT Address% = AskForBaseAddress!(&H340) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT "Base Address is "; HEX$(Address%); " hex" PRINT "Connect a loopback cable from PORT A to PORT B of PPI0." PRINT : PRINT : PRINT : PRINT PRINT "PRESS ANY KEY TO CONTINUE." A$ = INPUT$(1) CLS LOCATE 9, 17 PRINT " PORT A OUTPUT PORT A INPUT PORT B INPUT " LOCATE 10, 17 PRINT " ------------- ------------ ------------ " LOCATE 17, 25 PRINT " PRESS F1 TO EXIT THE PROGRAM " ' 'main control loop ' OUT Address% + 19, &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% + 16, CURRENT%(0) 'write value to port a CURRENT%(1) = INP(Address% + 16)'read back back what we wrote to port A CURRENT%(2) = INP(Address% + 17)'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% ELSEIF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION