home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_39.arc / SEPOD.FIG < prev   
Text File  |  1987-05-04  |  9KB  |  212 lines

  1. ; sepod.asm rce 5/4/87 Tests COM1 at 4800,8,1,N
  2. ;
  3. ; NOTE: For this test to be successful, the following pins on the
  4. ;       serial port connector MUST be jumpered: Jumper pins 2 and 3,
  5. ;       jumper pins 4 and 5, and jumper pins 6 and 20.
  6. ;
  7. ; With pins jumpered as indicated above, the program will first
  8. ; perform an external looping test that checks the overall
  9. ; performance of the serial port by transmitting and receiving a
  10. ; series of ASCII characters.  If they are received correctly
  11. ; they will be displayed on the screen, followed by a message that
  12. ; the port checks out completely.  If, and only if, an error is
  13. ; detected, an error message is displayed, and an internal loop 
  14. ; test is performed that checks the 8250 UART by looping back
  15. ; internally.  If the first (external) part fails, and the second
  16. ; (internal) part runs, the trouble may be in the transmitter 
  17. ; and/or receiver chips, or with one of the handshaking lines
  18. ; (CTS/RTS or DSR/DTR).  If the second part also fails, the
  19. ; 8250 UART may be bad.
  20. ;
  21. ; NOTE: The overall external loop check will work on all PC's and
  22. ;       clones, since it uses BIOS interrupts.  The internal loop
  23. ;       check, however, addresses hardware registers directly, and
  24. ;       therefore must have the correct register addresses.  Make
  25. ;       sure that the five statements with asterisks in the comment
  26. ;       fields all have the correct register addresses for your 
  27. ;       machines.  If you cannot determine these addresses, you
  28. ;       may want to disable the internal check part of the program
  29. ;       by changing the statement "jna intlp" to "jmp exit" on the
  30. ;       line with "#####".  The register addresses are valid for
  31. ;       the IBM PC, XT, AT and PS/2 Model 50.
  32. ;
  33. data    segment word public 'data'
  34. signon  db 0dh,0ah,'SEPOD Serial Port Diagnostic for COM1:',0dh,0ah
  35.         db 'Copyright 1987, Russell C. Eberhart',0dh,0ah,0dh,0ah
  36.         db 'You MUST have the following pins jumpered on the serial port',0dh,0ah
  37.         db 'connector for this test to be successful:',0dh,0ah
  38.         db 'Jumper pins 2 & 3, 4 & 5, and 6 & 20.',0dh,0ah,0dh,0ah
  39.         db 'Testing overall port performance (external loop):',0dh,0ah,'$'
  40. char    db '0'
  41. errcnt  db 0h
  42. crlf    db 0dh,0ah,0dh,0ah,'$'
  43. exgood  db 'The COM1 serial port checks out completely OK.',0dh,0ah,'$'
  44. ingood  db 'The internal looping check of the 8250 is OK.',0dh,0ah
  45.         db 'You may have a problem with the transmitter',0dh,0ah
  46.         db 'and/or receiver chips, or with the CTS/RTS',0dh,0ah
  47.         db 'and/or DTR/DSR handshaking lines.',0dh,0ah,0dh,0ah,'$'
  48. exerr3  db 'ERROR: Transmitted character not received.    ',0dh,0ah,'$'
  49. exerr1  db 'ERROR associated with character received.     ',0dh,0ah,'$'
  50. exerr2  db 'ERROR: Character received not same as sent.   ',0dh,0ah,'$'
  51. intchk  db 0dh,0ah,'Testing internal loopback performace:',0dh,0ah,'$'
  52. bomb    db 0dh,0ah,'The internal looping check fails.  You may have a bad 8250 UART.',0dh,0ah,'$'
  53. data    ends
  54. ;
  55. dgroup  group data      ;define data group, loaded last
  56. ;
  57. stack   segment para stack 'stack'
  58.         db 256 dup(0)   ;reserve 256 bytes for stack
  59. stack   ends
  60. ;
  61. code    segment byte public 'code'
  62.         assume cs:code, ss:stack, ds:dgroup
  63. ;
  64. main    proc far
  65. ;
  66. ; Set up data segment 
  67. start:  mov ax,data     ;set up data segment
  68.         mov ds,ax       ; into DS
  69. ;
  70. ; Initialize communciations port
  71.         mov ah,00       ;function 0 = initialize port
  72.         mov al,0c3h     ;4800,8,N,1 (0a3h for 2400)
  73.         mov dx,0        ;use COM1
  74.         int 14h         ;serial port service
  75. ;
  76. ; Print sign-on message
  77.         lea dx,signon   ;load address of sign-on message
  78.         mov ah,9        ;print string service
  79.         int 21h         ;DOS function
  80. ;
  81. ; Clean out receiver data and shift registers
  82. ;       mov cx,2        ;set up to loop twice
  83. ;lean:  mov ah,2        ;set up read character
  84. ;       mov dx,0        ;use COM1
  85. ;       int 14h         ;serial port service
  86. ;       loop clean      ;do twice
  87. ;
  88. ; Check external loop, transmit & receive 80 characters
  89. txwait: mov ah,03h      ;serial port status request
  90.         mov dx,0        ;use COM1
  91.         int 14h         ;serial port service
  92.         test ah,20h     ;transmitter hold register empty?
  93.         jz txwait       ;not empty
  94. ;
  95.         mov al,char     ;start with "0" character, then increment
  96.         mov dx,0        ;use COM1
  97.         mov ah,01h      ;write character
  98.         int 14h         ;serial port service
  99. ;
  100.         mov cx,0fffh    ;set up 1-second loop
  101. wait:   mov ah,3        ;status request
  102.         mov dx,0        ;use COM1
  103.         int 14h         ;serial port service
  104.         and ah,01h      ;character ready yet?
  105.         jnz rcv         ;yes, receive it
  106.         loop wait       ;no, try again (for 1 second)
  107.         jmp error3      ;if no success, receive char error
  108. ;
  109. rcv:    mov ah,2        ;yes, read char function
  110.         mov dx,0        ;use COM1
  111.         int 14h         ;serial port service
  112.         and ah,08eh     ;error check (09eh? break also?)
  113.         jc error1       ;handle external receive error
  114. ;
  115.         cmp al,char     ;compare sent with received char
  116.         jnz error2      ;handle garbled transmission error
  117.         mov bx,0        ;page 0
  118.         mov ah,0eh      ;TTY display service
  119.         int 10h         ;video I/O
  120. ;
  121.         inc char        ;next character
  122.         cmp char,7eh    ;last character?
  123.         jnz txwait      ;no, send another char
  124.         lea dx,crlf     ;yes, load cr-lf string
  125.         mov ah,9        ;print string service
  126.         int 21h         ;DOS function
  127.         lea dx,exgood   ;load "success" message
  128.         mov ah,9        ;print string service
  129.         int 21h         ;DOS function
  130. ;
  131. exit:   mov ah,04ch     ;terminate process service
  132.         int 21h         ;DOS function (END program)
  133. ;
  134. ; External receive error reflected in AH
  135. error1: lea dx,exerr1   ;load line status error after rcv message
  136.         jmp errprn      ;jump to print error message
  137. ;
  138. ; Received character not same as that sent
  139. error2: lea dx,exerr2   ;load sent<>received char message
  140.         jmp errprn      ;jump to print error message
  141. ;
  142. ; Received character not available (bit 0 not 1)
  143. error3: lea dx,exerr3    ;load xmttd char not rcd error message
  144. errprn: mov ah,9         ;print string service
  145.         int 21h          ;DOS function interrupt
  146.         inc errcnt       ;add one to the error count
  147.         cmp errcnt,1     ;test to see if previous error
  148.         jna intlp        ;if not, check internal loop #####
  149. ;
  150. ; If internal loop test done with error, print message and exit
  151.         lea dx,bomb      ;load total failure message
  152.         mov ah,9         ;print string service
  153.         int 21h          ;DOS function
  154.         jmp exit         ;go to exit
  155. ;
  156. ; Set up internal loopback and test
  157. intlp:  mov dx,3fch      ;modem control register address *****
  158.         mov al,13h       ;set INTERNAL loopback
  159.         out dx,al        ;do it
  160. ;
  161.         mov char,'0'     ;re-start with character 0
  162. ;
  163.         lea dx,intchk    ;load address of internal check message
  164.         mov ah,9         ;print string service
  165.         int 21h          ;DOS function
  166. ;
  167. intxwt: mov dx,3fdh      ;line status register address *****
  168.         in al,dx         ;put line status in AL
  169.         test al,20h      ;transmitter hold register empty?
  170.         jz intxwt        ;not empty, so loop
  171. ;
  172.         mov al,char      ;start with "0" character, then increment
  173.         mov dx,3f8h      ;transmitter holding register address *****
  174.         out dx,al        ;send the character
  175. ;
  176.         mov cx,0fffh     ;set up 1-second loop
  177. inwait: mov dx,3fdh      ;line status register address *****
  178.         in al,dx         ;put line status in AL
  179.         test al,1eh      ;receive error check
  180.         jnz error1       ;handle external receive error
  181. ;
  182.         test al,01h      ;character ready yet?
  183.         jnz inrcv        ;yes, receive it
  184.         loop inwait      ;no, loop for up to 1 second
  185.         jmp error3       ;if no success, receive char error
  186. ;
  187. inrcv:  mov dx,3f8h      ;receiver data register address *****
  188.         in al,dx         ;put received char in AL
  189.         and al,7fh       ;keep only valid lower 7 bits
  190. ;
  191.         cmp al,char      ;compare sent with received char
  192.         jnz error2       ;handle garbled transmission error
  193.         mov bx,0         ;page 0
  194.         mov ah,0eh       ;TTY display service
  195.         int 10h          ;video I/O
  196. ;
  197.         inc char         ;next character
  198.         cmp char,7eh     ;last character?
  199.         jnz intxwt       ;no, send another char
  200.         lea dx,crlf      ;yes, load cr-lf string
  201.         mov ah,9         ;print string service
  202.         int 21h          ;DOS function
  203.         lea dx,ingood    ;load internal "success" message
  204.         mov ah,9         ;print string service
  205.         int 21h          ;DOS function
  206. ;
  207.         jmp exit         ;all done, exit
  208. ;
  209. main    endp
  210. code    ends
  211.         end start
  212.