EE2007 Tutorial Notes Prepared by Pan Yan What are we going to do with the UART? Transmit or receive data – Continuous data stream Control the protocol parameters – Initialization Control the baud rate - Initialization Handshaking – Checking & Asserting [To MOV MOV OUT Write to a Port] AL, data DX, portnum DX, AL [To Read From a Port] MOV DX, portnum IN AL, DX Registers for Serial Port (IO Port, Not CPU Registers) Eight I/O bytes are used for each UART to access its registers. The switch bit DLAB can be found in the line control register LCR as bit 7 at I/O address base + 3. I/O port Base (3F8h) or (2F8h) base + 1 base + 2 Register to port map DLAB = 0 Read Write RBR☆ Receiver buffer IER interrupt enable IIR Interrupt identification base + 3 base + 4 base + 5 base + 6 base + 7 LSR☆ Line status MSR☆ Modem status DLAB = 1 Read Write THR☆ Transmitter holding DLL (divisor latch LSB) IER interrupt enable DLM (divisor latch MSB) IIR Interrupt identification LCR☆ line control MCR☆ modem control factory LSR test Line status not MSR used Modem status SCR scratch FCR FIFO control FCR FIFO control factory test not used The communication between the processor and the UART is completely controlled by the 12 registers in the I/O address area. RBR : Receiver buffer register (RO) – Data Buffer THR : Transmitter holding register (WO) – Data Buffer MSR: Modem status register (RO) – Status - Handshaking MCR: Modem control register (R/W) – Control - Handshaking Email : panyan@gmail.com Go to http://ee2007.cjb.net for more on EE2007 -1- EE2007 Tutorial Notes Prepared by Pan Yan LSR: Line status register (RO) - Status – Error and Transmission LCR : Line control register (R/W) - Control - Initiallization Bit 0,1 2 3,4,5 6 7 Bit 0 1 2 3 4 5 6 7 LCR : line control register Comment Bit 1 Bit 0 Data word length 0 0 5 bits 0 1 6 bits 1 0 7 bits 1 1 8 bits 0 1 stop bit 1 1.5 stop bits (5 bits word) 2 stop bits (6,7 or 8 bits word) Bit 5 Bit 4 Bit 3 X x 0 No parity 0 0 1 Odd parity 0 1 1 Even parity 1 0 1 High parity (stick) 1 1 1 Low parity (stick) 0 Break signal disabled 1 Break signal enabled 0 DLAB : RBR, THR and IER accessible 1 DLAB : DLL and DLM accessible Value LSR : Line status register Comment Data available Overrun error Parity error Framing error Break signal received THR is empty THR empty, line idle Erroneous data in FIFO MSR : Modem status register Bit Comment 0 delta Clear to send 1 delta Data set ready 2 trailing edge Ring indicator 3 delta Carrier detect 4 Clear to send 5 Data set ready 6 Ring indicator 7 Carrier detect MCR : Modem control register Bit Comment 0 Data terminal ready 1 Request to send 2 Auxiliary output 1 3 Auxiliary output 2 4 Loopback mode 5 Autoflow control 6 Reserved 7 Reserved Refer to Sect#22.3 of AoALP for Serial Port Example Programs Baud & Bits Per Second (BPS) The two most corrupted terms in telecommunications. Baud is the number of signal level changes per second in a line, regardless of the information content of those signals. Bits per second is the rate of transfer of information bits. The ratio of BPS to baud depends on the information coding scheme that you are using. For example, each character in asynchronous RS-232 coding includes a start and stop bit that are not counted as information bits, so the BPS rate is actually less than the baud rate. Present-day modems, on the other hand, use a set of discrete amplitude and phase values to encode multiple bits with each signal change. This technique, along with compression schemes and other tricks, allows BPS rates of 14,400 and higher on lines that support relatively low signal change rates (about 2400 baud for phone lines). Devisor Setting: Divisor value = Input frequency / (baud rate * 16) Email : panyan@gmail.com Go to http://ee2007.cjb.net for more on EE2007 -2- EE2007 Tutorial Notes Prepared by Pan Yan Interrupt of 8086/8088 The 8086 series of microprocessors has an Interrupt Vector Table situated at 0000:0000 which extends for 1024 bytes. The Interrupt Vector table holds the address of the Interrupt Service Routines (ISR), all four bytes in length. This gives us room for the 256 Interrupt Vectors. INT (Hex) 00 - 01 02 03 - 07 IRQ Exception Handlers Non-Maskable IRQ Exception Handlers 08-0F Hardware IRQ0~7 10 - 6F Software Interrupts 70 - 77 Hardware IRQ8~15 78 - FF Software Interrupts Common Uses Non-Maskable IRQ (Parity Errors) System Timer, Keyboard, Serial Comms, Sound Card, FD Ctrl, Parallel Comms. (DOS INT, e.g. 21H) Real Time Clock, Mouse, HD Drive, Co-Processor - Go online for BIOS and DOS ISR list: http://ee2007.cjb.net/onlinepages.html Example Description Int 21/AH=01h: READ CHARACTER FROM STDIN, WITH ECHO AH = 01h Return: AL = character read Notes: ^C/^Break are checked, and INT 23 executed if read. … CODE: MOV AH, 01h INT 21H MOV DL, AL Parallel Port is more straight-forward Port Register value mapped directly to connector pins (0V or 5V) Bit ComRead proc Push dx D0 D1 D2 D3 D4 D5 D6 D7 Data Port (378h) Func. Pin. Data0 2 Data1 3 Data2 4 Data3 5 Data4 6 Data5 7 Data6 8 Data7 9 Status Port (379h) Func. Pin Not Used Not Used Not Used /ERROR 15 /SLCT 17 PE 12 /ACK 10 /BUSY 11 Control Port (37Ah) Func. Pin STROBE 1 Auto FD 14 /INIT 16 /SLCT_IN 17 IRQ7 Not Used Not Used Not Used - Email : panyan@gmail.com Go to http://ee2007.cjb.net for more on EE2007 -3- EE2007 Call Push And Call WaitForChar: Call Test Jz Mov In Mov Pop Call Mov Pop ret ComRead endp ComWrite proc Push Push Mov Call Push And Call WaitForXmtr: Call Test Jz Mov Mov Out Pop Call Pop Pop Ret ComWrite endp ComGetLCR proc Push Mov In Pop Ret ComGetLCR endp ComSetLCR proc Push Mov Out Pop Ret ComSetLCR endp Tutorial Notes GetLCRCom ax al, 7fh SetLCRCom Prepared by Pan Yan ;Save DLAB. ;Select normal ports. ;Write LCR to turn off DLAB GetLSRCom ;Get LSR Register al, 00000001b ;Data Available? WaitForChar ;Loop until data available. dx, comport ;Read from the input port. al, dx dl, al ;Save character ax ;Restore DLAB SetLCRCom ;Write it back to LCR. al, dl ;Restore output character. dx dx ax dl, al GetLCRCom ax al, 7fh SetLCRCom ;Save character to output ;Switch to output register. ;Save divisor latch access bit. ;Select normal i/o ports ; rather than divisor reg. GetLSRCom ;Read LSR for xmit empty bit. al, 00100000b ;Xmtr buffer empty? WaitForXmtr ;Loop until empty. al, dl ;Get output character. dx, ComPort ;Store it in the ouput port to dx, al ; get it on its way. ax ;Restore divisor access bit. SetLCRCom ax dx ;Return LCR value in AL. dx dx, comLCR al, dx dx ;Point at LCR register. ;Read and return LCR value. ;Write a new value to the LCR. dx dx, comLCR dx, al dx ;Point at LCR register. ;Write value in AL to the LCR. Email : panyan@gmail.com Go to http://ee2007.cjb.net for more on EE2007 -4-