home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10776 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  7.9 KB

  1. Xref: sparky comp.os.msdos.programmer:10776 comp.sys.ibm.pc.programmer:595
  2. Path: sparky!uunet!icd.ab.com!iccgcc.decnet.ab.com!gardner
  3. From: gardner@iccgcc.decnet.ab.com
  4. Newsgroups: comp.os.msdos.programmer,comp.sys.ibm.pc.programmer
  5. Subject: H E L P!!! Serial Communications Blues... (UART).
  6. Message-ID: <1992Nov19.143345.9313@iccgcc.decnet.ab.com>
  7. Date: 19 Nov 92 14:33:45 EST
  8. Lines: 301
  9.  
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;Hello,
  12. ;
  13. ;I was torn about whether to ZOO and UUENCODE the following little program, 
  14. ;but I really need help and didn't want to proclude anyone from assisting by
  15. ;requiring special software tools.  So, to those of you who are upset by my
  16. ;loading a 5K file with this message, I apologize.
  17. ;
  18. ;Now, for the question...
  19. ;
  20. ; I am teaching myself about the 8250 UART and am having problems doing
  21. ; somthing that "appears" to be very easy...  All I want to do is create
  22. ; a TSR (no problem) that is kicked every time a byte arrives in COM2.
  23. ; The interrupt service routine that is invoked by the 0BH (COM2) vector
  24. ; will retrieve the byte from the RECEIVER REGISTER and display it directly 
  25. ; to video memory (I've implemented the video code but haven't tested it).
  26. ; The program that follows is my attempt at doing this.  When I loaded this
  27. ; TSR and ran a separate program to send a byte to COM2.  It appears that 
  28. ; the UART knows a byte has arrived and raises the RECEIVED DATA INTERRUPT.
  29. ; However, the PIC never generates an interrupt to my COM2 isr...
  30. ;
  31. ; W H Y ?!?!?!?!?!?!?!?!?!?!
  32. ;
  33. ; The separate program that sends data to COM2 simply OUT's the byte to
  34. ; the COM2 transmit register (2F8H) and waits 10 seconds and then sends
  35. ; another.
  36. ;
  37. ; I've compared what I am doing with several programs that are published
  38. ; in books...  I must be missing something very simple...  Any ideas?
  39. ;
  40. ; I'd appreciate any help that you may offer...  Frankly, this has been
  41. ; driving me nuts!
  42. ;
  43. ; Thanks,
  44. ;
  45. ;       Mike Gardner
  46. ;
  47. ; P.S. I wrote this using Turbo Assembler.
  48. ;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50.  
  51. title COM2 TSR Program
  52. %PAGESIZE 60,132
  53. ideal
  54.  
  55. ;*****************************************************************************
  56. ; AUTHOR:      Mike Gardner
  57. ; CREATED:     19-NOV-1992
  58. ;*****************************************************************************
  59.  
  60. ; Various boolean values...
  61. FALSE          equ     0
  62. OFF            equ     0
  63. ON             equ     1
  64. TRUE           equ     1
  65.  
  66. ; The COM port address
  67. COM              =      2F8H
  68. TXR              =      COM+0
  69. RXR              =      COM+0
  70. DLL              =      COM+0
  71. DLH              =      COM+1
  72. IER              =      COM+1
  73. IIR              =      COM+2
  74. LCR              =      COM+3
  75. MCR              =      COM+4
  76. LSR              =      COM+5
  77. MSR              =      COM+6
  78.  
  79. ; The PIC port address
  80. PIC_CONTROL     equ     20H
  81. PIC_MASK        equ     21H
  82. END_OF_INTERRUPT equ    20H
  83.  
  84. ; The COM communication parameters
  85. C9600BAUD_MSB   equ     0CH
  86. C9600BAUD_LSB   equ     00H
  87. C8_1_NO         equ     03H
  88. C7_1_NO         equ     02H
  89.  
  90. ; The various UART int sources
  91. MODEM_STATUS    equ     0
  92. TX_REG_EMPTY    equ     2
  93. RX_DATA_READY   equ     4
  94. RLINE_STATUS    equ     6
  95.  
  96. macro IO_DELAY n
  97.         rept n
  98.         local IO_DELAY_TARGET
  99.         jmp short IO_DELAY_TARGET
  100. IO_DELAY_TARGET:
  101.         endm
  102. endm
  103.  
  104. macro OUTCH ch
  105.         ASSUME ES:VIDEO_SEGMENT
  106.         push    es
  107.         push    ax
  108.         mov     ax, VIDEO_SEGMENT
  109.         mov     es, ax
  110.         pop     ax
  111.         mov     [cmd], ch
  112.         mov     [attr], 7H
  113.         ASSUME ES:VECTORS_SEGMENT
  114.         pop     es
  115. endm
  116.  
  117. ; The video segment...  It assumes VGA/CGA.
  118. SEGMENT VIDEO_SEGMENT AT 0H
  119.     ORG 0B800H
  120.     cmd db ?
  121.     attr db ?
  122. ENDS
  123.  
  124. ; A segment to access the interrupt table vector entry
  125. SEGMENT VECTORS_SEGMENT AT 0H
  126.     ORG 0BH * 4         ; COM2 communications interrupt vector
  127.     int0BOff            dw      ?
  128.     int0BSeg            dw      ?
  129. ENDS
  130.  
  131.  
  132. SEGMENT CODE_SEGMENT
  133.         ASSUME CS:CODE_SEGMENT, DS:CODE_SEGMENT, ES:VECTORS_SEGMENT
  134.         ORG     100H
  135.  
  136. START:  
  137.         ; Initialize and launch the tsr...
  138.         jmp     LAUNCH
  139.  
  140.        ; Original COM2 interrupt vector.
  141.        label oldint0B dword
  142.        oldint0BOff    dw  0
  143.        oldint0BSeg    dw  0
  144.  
  145.        ; The received byte
  146.        theChar        db  0
  147.  
  148. ; The COM2 isr...
  149. proc int0Bisr near
  150.         push    ax
  151.         push    bx
  152.         push    cx
  153.         push    dx
  154.         push    si
  155.         push    di
  156.         push    bp
  157.         push    ds
  158.         push    es
  159.  
  160.         ; Set up my data segment.
  161.         push    cs
  162.         pop     ds
  163.  
  164.     ; See if there are any interrupts pending in the IIR.  
  165.     ; I am only really interested (and have only enabled)
  166.     ; the received data interrupt.
  167.  
  168. @@ANY_INTS_PENDING:
  169.         mov     dx, IIR
  170.         in      al, dx  ; See if any interrupts have arrived in IIR
  171.         mov     cl, al
  172.         test    al, 1
  173.         jnz      @@EXIT_SERIAL_INT
  174.  
  175.         ; Read and place the character into the buffer
  176.         IO_DELAY 2
  177.         mov     dx, RXR
  178.         in      al, dx
  179.         mov     ah, 0
  180.  
  181.     ; The real version will do buffering...  For now
  182.     ; just store the byte...
  183.     mov    [theChar], al
  184.  
  185.         ; And display it.
  186.         OUTCH al
  187.  
  188.         jmp     @@ANY_INTS_PENDING
  189.  
  190. @@EXIT_SERIAL_INT:
  191.  
  192.     ; Inform the PIC that we are done with the COM interrupt
  193.         mov     dx, 20H
  194.         mov     al, 20H
  195.         out     dx, al
  196.  
  197.         pop     es
  198.         pop     ds
  199.         pop     bp
  200.         pop     di
  201.         pop     si
  202.         pop     dx
  203.         pop     cx
  204.         pop     bx
  205.         pop     ax
  206.  
  207.         iret
  208. endp
  209.  
  210.  
  211. ;*****************************************************************************
  212. LAUNCH:
  213.         jmp START_LAUNCH
  214.  
  215.        ; Disposable data
  216.  
  217.        ; Our startup message
  218.         label ABMsg  byte
  219.         db  13, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7, 7, 7, 7, 7
  220.         db  10, 13, "              *******************************************"
  221.         db  10, 13, "              *           A TEST OF A COM2 TSR          *"
  222.         db  10, 13, "              *                Version 1.00             *"
  223.         db  10, 13, "              *******************************************"
  224.         db  10, 13, 10, 10, 10, 10, 10, 10, '$'
  225.  
  226. START_LAUNCH:
  227.         push    cs
  228.         pop     ds
  229.         mov     ax, VECTORS_SEGMENT
  230.         mov     es, ax
  231.  
  232.     ; lets say hello
  233.     lea        dx,[ABMsg]
  234.     mov        ah,9
  235.     int        21h
  236. OUTCH 'Z'
  237.     cli
  238.  
  239.     ; Get the original COM2 vector    
  240.     mov       ax,[int0BOff]
  241.     mov       [oldint0BOff],ax
  242.     mov       ax,[int0BSeg]
  243.     mov       [oldint0BSeg],ax
  244.  
  245.     ; lets set our new COM2 vector
  246.     lea       ax,[int0Bisr]
  247.     mov       [int0BOff],ax
  248.     mov       [int0BSeg],cs
  249.  
  250.  
  251.     ; Initialize the COM port
  252.     mov al, 80H
  253.     mov dx, LCR
  254.     out dx,al   ; Turn on DLAB to set the baud rate
  255.  
  256.     IO_DELAY 3
  257.     mov dx, DLL
  258.     mov al, C9600BAUD_MSB
  259.     out dx,al
  260.     IO_DELAY 3
  261.     mov dx, DLH
  262.     mov al, C9600BAUD_LSB
  263.     out dx,al   ; Set the baud rate to 9600
  264.  
  265.     IO_DELAY 3
  266.     mov dx, LCR
  267.     mov al, C8_1_NO
  268.     out dx, al  ; Set the port to 8 bits, 1 stop, no parity
  269.  
  270.     IO_DELAY 3
  271.     in  al, dx
  272.     and al, 7FH
  273.     IO_DELAY 3
  274.     out dx, al  ; Turn off the DLAB ... Done setting baud rate.
  275.  
  276.     ; Enable receiver interrupts from the COM port, DTR, RTS
  277.     IO_DELAY 3
  278.     mov dx, MCR
  279.     mov al, 0BH
  280.     out dx, al  ; Turn on OUT2, DTR, RTS to enable communication interrupts
  281.  
  282.     IO_DELAY 3
  283.     mov dx, IER
  284.     mov al, 01H
  285.     out dx, al  ; Turn on the received data interrupt
  286.  
  287.     ; Read the receiver register to make sure any garbage is removed.
  288.     IO_DELAY 3
  289.     mov dx, RXR
  290.     in al, dx
  291.  
  292.     ; Enable the PIC to generate COM interrupt
  293.     IO_DELAY 3
  294.     mov dx, PIC_MASK
  295.     in al, dx
  296.     and al, 0F7H
  297.     IO_DELAY 3
  298.     out dx, al  ; Permit the generation of COM interrupt
  299.  
  300.     sti
  301.  
  302.  
  303.     ; Go tsr...  Jettison everything from the LAUNCH label to the end...
  304.     mov         dx, offset LAUNCH
  305.     int         27H
  306.  
  307. ENDS
  308.  
  309. END START
  310.