DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '*************************************************************************** '* * '* SAMPLE 1 * '* LOOP BACK TEST PROGRAM * '* * '* This program uses the loop back feature of the 16450 chip to transmit * '* a sequence of characters and in turn receive them. No external jumpers * '* are required to run this program. * '* * '* * '*************************************************************************** RECEIVE = 0 ' Receiver buffer register TRANSMIT = 0 ' Transmitter holding register LDIVISOR = 0 ' Divisor latch, least significant byte UDIVISOR = 1 ' Divisor latch, most significant byte INTENB = 1 ' Interrupt enable register INTID = 2 ' Interupt identification register LINECTRL = 3 ' Line control register MODEMCTRL = 4 ' Modem control register LINESTAT = 5 ' Line status register MODEMSTAT = 6 ' Modem status register ch% = 0 ch1% = 0 CLS PRINT " SAMPLE 1.BAS : Loop back test program." PRINT PRINT "This program uses the loop back feature of the 16450 chip to transmit" PRINT "a sequence of characters and in turn receive them. No external jumpers" PRINT "are required to run this program. All other settings are irrelevant." LOCATE 7, 1 BaseAddr% = AskForBaseAddress(&H2A8) CLS PRINT PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(BaseAddr%); " hex." PRINT " -- Disable jumpers should not be jumpered (required)" PRINT " -- Invert jumpers should not be jumpered (required)" PRINT " -- CTR0/CTR2 and CTR0/CTR1 should not be jumpered (required)" PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT PRINT "Press a key to continue." ch$ = INPUT$(1) CLS ' First, set up the divisor latches for 9600 baud. A divisor of 12 is ' required since the 1.8432 clock is used. The upper divisor is set to ' 0 and the lower to 12. OUT BaseAddr% + LINECTRL, &H80 OUT BaseAddr% + LDIVISOR, &HC OUT BaseAddr% + UDIVISOR, &H0 ' Now set the line control register for the following communications ' protocol: ' bit0, bit1 = 1 -- character is eight bits ' bit2 = 0 -- one stop bit ' bit3 = 0 -- no parity is enabled ' bit4 = 0 - -doesn't matter with parity disabled ' bit5 = 0 - -doesn't matter with parity disabled ' bit6 = 0 -- disable break control ' bit7 = 0 -- DLAB bit, 0 disables divisor latches OUT BaseAddr% + LINECTRL, &H3 ' Enable the loop back feature of the chip with bit 4 of modem control ' register, now all transmitted characters will be looped back to the ' receiver, without external connections. OUT BaseAddr% + MODEMCTRL, &H10 ' These inputs are just to insure that both the receiver buffer register ' and receiver shift register are clear. FOR x% = 1 TO 4 ' Acts as a delay between OUT's NEXT x% ch% = INP(BaseAddr% + RECEIVE) ' clear rx registers FOR x% = 1 TO 4 ' Acts as a delay between OUT's NEXT x% ch% = INP(BaseAddr% + RECEIVE) '*********************************************************** '* * '* Transmit the letters 'A' through 'Z', and in turn, * '* receive the characters, and check if the correct char * '* is received. The program will print an error message * '* for each bad character received. If no errors occur, * '* the program will indicate so at the end of program * '* execution. * '* * '*********************************************************** flag = 0 FOR ch% = 65 TO 90 ' ASCII codes for A to Z OUT BaseAddr% + TRANSMIT, ch% ' send character to UART DO ch1% = INP(BaseAddr% + LINESTAT) ' poll line control register LOOP UNTIL (ch1% AND 1) > 0 ch1% = INP(BaseAddr% + RECEIVE) ' read the input char ' check if char received is the one we sent IF ch1% <> ch% THEN PRINT "error with character "; CHR$(ch%); ", received char "; CHR$(ch1%); "." flag = 1 END IF NEXT IF (flag = 0) THEN ' then no errors occured PRINT "All characters were transmitted without error." END IF 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