'*************************************************************************** '* * '* 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. * '* * '* LAST MODIFIED: 2/5/98 * '*************************************************************************** DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) 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 " Sample1.BAS : Internal Loopback Test" 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." PRINT PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(Address%); " hex" PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT INPUT "Press Enter to Continue "; Msg$ ' 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 Address% + LINECTRL, &H80 OUT Address% + LDIVISOR, &HC OUT Address% + 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 Address% + 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 Address% + 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(Address% + RECEIVE) ' clear rx registers FOR x% = 1 TO 4 ' Acts as a delay between OUT's NEXT x% ch% = INP(Address% + 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 Address% + TRANSMIT, ch% ' send character to UART DO ch1% = INP(Address% + LINESTAT) ' poll line control register LOOP UNTIL (ch1% AND 1) > 0 ch1% = INP(Address% + 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 CLS PRINT : PRINT : PRINT : PRINT : PRINT 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