CS-401 Computer Architecture & Assembly Language Programming Lecture-38 Serial Port Programming
Serial Port
Serial Port Connector 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)
Frame Format data bits (5-8) Start bit (1) parity bit (1) Stop bits (1-2)
Connection Diagram TD RD Ground TD RD Ground
Transmission setting
int 0x14 Serial Initialize Port AH = 0x00 AL = port parameters DX = port number (0x00 – 0x03) Return AH = line status Al = modem status
Port Parameters - AL baud rate 000-110 001-150 010-300 011-600 7 6 5 4 3 2 1 baud rate 000-110 001-150 010-300 011-600 100-1200 101-2400 110-4800 111-9600 parity 00-N 10-N 01-O 11-E data bits 00-5 01-6 10-7 11-8 stop bits 0-1 1-2
Write Character to Port int 0x14 Serial Write Character to Port AH = 0x01 AL = character DX = port number (0x00 – 0x03) Return AH (bit 7)= set on error AH (bits 0-6)= port status
Read Character from Port int 0x14 Serial Read Character from Port AH = 0x02 AL = character DX = port number (0x00 – 0x03) Return AH = line status AL = received character (AH bit 7 clear)
int 0x14 Serial Get Port Status AH = 0x03 AL = character DX = port number (0x00 – 0x03) Return AH = line status AL = modem status
Line Status 7 6 5 4 3 2 1 0 rx ready time out tx shift register empty 7 6 5 4 3 2 1 0 time out rx ready tx shift register empty over run tx holding register empty parity error break detect framing error
Serial Ports IO ports
Serial Port I/O Ports COM1: 0x03F8-0x03FF COM2: 0x02F8-0x02FF
Serial Port I/O Ports Port 0x3F8/0x2F8 Transmit Holding Register (THR) Receiver Buffer Register (RBR)
Serial Port I/O Ports Port 0x3F9/0x2F9 Interrupt Enable Register (IER) Bit 0 = Received Data Available Bit 1 = Transmitter Holding Register Empty
Interrupt Identification Register Serial Port I/O Ports Port 0x3FA/0x2FA Interrupt Identification Register Bit 0 = Interrupt Pending Status (0) Interrupt Pending (1) Interrupt Not Pending Bit 1-3 = Pending Interrupt Source (001) THR Empty (010) Received a Character
Serial Port I/O Ports Port 0x3FB/0x2FB Line Control Register (LCR) 7 6 5 4 3 2 1 0 DLAB data bits set break enable stop bit parity
Serial Port I/O Ports Port 0x3FD/0x2FD Line Status Register (LCR) 7 6 5 4 3 2 1 0 reserved data ready tx shift register empty over run tx holding register empty parity error break detect framing error