Serial Port and Serial Communication-Microprocessor and Assembly Language Programming-Lecture Notes, Study notes of Microprocessor and Assembly Language Programming

This lecture handout was provided at Quaid-i-Azam University for Microprocessor and Assembly Language Programming course by Prof. Saleem Raza. Its main points are: Serial, Port, Indicator, Communication, jump, Transmitted, Received, Carrier

Typology: Study notes

2011/2012

Uploaded on 08/04/2012

saqqi
saqqi ๐Ÿ‡ต๐Ÿ‡ฐ

4

(33)

40 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Serial port is a way of communication among two devices just like the
parallel port. The basic difference is that whole bytes are sent from one place
to another in case of parallel port while the bits are sent one by one on the
serial port in a specially formatted fashion. The serial port connection is a
9pin DB-9 connector with pins assigned as shown below.
We have made a wire that connects signal ground of the two connectors,
the TD of one to the RD of the other and the RD of one to the TD of the other.
This three wire connection is sufficient for full duplex serial communication.
The data on the serial port is sent in a standard format called RS232
communication. The data starts with a 1 bit called the start bit, then five to
eight data bits, an optional parity bit, and one to two 0 bits called stop bits.
The number of data bits, parity bits, and the number of stop bits have to be
configured at both ends. Also the duration of a bit must be precisely known
at both ends called the baud rate of the communication.
The BIOS INT 14 provides serial port services. We will use a mix of BIOS
services and direct port access for our example. A major limitation in using
BIOS is that it does not allows interrupt driven data transfer, i.e. we are
interrupted whenever a byte is ready to be read or a byte can be transferred
since the previous transmission has completed. To achieve this we have to
resort to direct port access. Important BIOS services regarding the serial port
are discussed below.
INT 14 - SERIAL - INITIALIZE PORT
AH = 00h
AL = port parameters
DX = port number (00h-03h)
Return:
AH = line status
AL = modem status
Every bit of line status conveys different information. From most
significant to least significant, the meanings are timeout, transmitter shift
register empty, transmitter holding register empty, break detect, receiver
ready, overrun, parity error, and framing error. Modem status is not used in
direct serial communication. The port parameters in AL consist of the baud
1โ€“Carrier Detect
(CD)
2โ€“ Received Data
(RD)
3โ€“Transmitted
Data (TD)
4โ€“Data Terminal
Ready
(DTR)
5โ€“ Signal Ground
6โ€“ Data Set
Ready
(DSR)
7โ€“ Request to
Send (RTS)
8โ€“ Clear to Send
(CTS)
9โ€“ Ring Indicator
(RI)
pf3
pf4

Partial preview of the text

Download Serial Port and Serial Communication-Microprocessor and Assembly Language Programming-Lecture Notes and more Study notes Microprocessor and Assembly Language Programming in PDF only on Docsity!

Serial port is a way of communication among two devices just like the

parallel port. The basic difference is that whole bytes are sent from one place

to another in case of parallel port while the bits are sent one by one on the

serial port in a specially formatted fashion. The serial port connection is a

9pin DB-9 connector with pins assigned as shown below.

We have made a wire that connects signal ground of the two connectors,

the TD of one to the RD of the other and the RD of one to the TD of the other.

This three wire connection is sufficient for full duplex serial communication.

The data on the serial port is sent in a standard format called RS

communication. The data starts with a 1 bit called the start bit, then five to

eight data bits, an optional parity bit, and one to two 0 bits called stop bits.

The number of data bits, parity bits, and the number of stop bits have to be

configured at both ends. Also the duration of a bit must be precisely known

at both ends called the baud rate of the communication.

The BIOS INT 14 provides serial port services. We will use a mix of BIOS

services and direct port access for our example. A major limitation in using

BIOS is that it does not allows interrupt driven data transfer, i.e. we are

interrupted whenever a byte is ready to be read or a byte can be transferred

since the previous transmission has completed. To achieve this we have to

resort to direct port access. Important BIOS services regarding the serial port

are discussed below.

INT 14 - SERIAL - INITIALIZE PORT

AH = 00h AL = port parameters DX = port number (00h-03h) Return: AH = line status AL = modem status

Every bit of line status conveys different information. From most

significant to least significant, the meanings are timeout, transmitter shift

register empty, transmitter holding register empty, break detect, receiver

ready, overrun, parity error, and framing error. Modem status is not used in

direct serial communication. The port parameters in AL consist of the baud

1 โ€“ Carrier Detect

(CD)

2 โ€“ Received Data

(RD)

3 โ€“ Transmitted

Data (TD)

4 โ€“ Data Terminal

Ready

(DTR)

5 โ€“ Signal Ground

6 โ€“ Data Set

Ready

(DSR)

7 โ€“ Request to

Send (RTS)

8 โ€“ Clear to Send

(CTS)

9 โ€“ Ring Indicator

(RI)

rate, parity scheme, number of stop bits, and number of data bits. The

description of various bits is as under.

INT 14 - SERIAL - WRITE CHARACTER TO PORT

AH = 01h AL = character to write DX = port number (00h-03h) Return: AH bit 7 = error flag AH bits 6-0 = port status INT 14 - SERIAL - READ CHARACTER FROM PORT AH = 02h DX = port number (00h-03h) Return: AH = line status AL = received character if AH bit 7 clear INT 14 - SERIAL - GET PORT STATUS AH = 03h DX = port number (00h-03h) Return: AH = line status AL = modem status

Serial port is also accessible via I/O ports. COM1 is accessible via ports

3F8-3FF while COM2 is accessible via 2F8-2FF. The first register at 3F8 (or

2F8 for the other port) is the transmitter holding register if written to and the

receiver buffer register if read from. Other registers of our interest include

3F9 whose bit 0 must be set to enable received data available interrupt and

bit 1 must be set to enable transmitter holding register empty interrupt. Bit 0

of 3FA is set if an interrupt is pending and its bits 1-3 identify the cause of

the interrupt. The three bit causes are as follows.

110 (16550, 82510) timeout interrupt pending 101 (82510) timer interrupt 100 (82510) transmit machine 011 receiver line status interrupt. priority=highest 010 received data available register interrupt. priority=second 001 transmitter holding register empty interrupt. priority=third 000 modem status interrupt. priority=fourth

The register at 3FB is line control register while the one at 3FD is line

status register. The line status register has the same bits as returned in line

status by the get port status BIOS interrupt however the most significant bit

baud rate

parity

00-N

10-N

01-O

11-E

data bits

stop bits

start: call clrscr ; clear the screen

mov ah, 0 ; initialize port service mov al, 0xE3 ; line settings = 9600, 8, N, 1 xor dx, dx ; port = COM int 0x14 ; BIOS serial port services

xor ax, ax mov es, ax ; point es to IVT base mov word [es:0x0C4], serial mov [es:0x0C4+2], cs ; hook serial port interrupt

mov dx, 0x3FC ; modem control register in al, dx ; read register or al, 8 ; enable bit 3 (OUT2) out dx, al ; write back to register

mov dx, 0x3F9 ; interrupt enable register in al, dx ; read register or al, 1 ; receiver data interrupt enable out dx, al ; write back to register

in al, 0x21 ; read interrupt mask register and al, 0xEF ; enable IRQ 4 out 0x21, al ; write back to register

main: mov ah, 0 ; read key service int 0x16 ; BIOS keybaord services push ax ; save key for later use

retest: mov ah, 3 ; get line status xor dx, dx ; port = COM int 0x14 ; BIOS keyboard services and ah, 32 ; trasmitter holding register empty jz retest ; no, test again

pop ax ; load saved key mov dx, 0x3F8 ; data port out dx, al ; send on serial port

jmp main