1 of 28

Programming 8251 USART Controller

Dr A Sahu

Dept of Comp Sc & Engg.

IIT Guwahati

2 of 28

Hierarchy of I/O Control Devices

8155

I/O + Timer

8255

I/O

8253/54

Timer

2 Port (A,B),

No Bidirectional

HS mode (C)

4 mode timer

2 Port (A,B)

A is Bidirectional

HS mode (C)

Extra controls

6 mode timer

8259

Interrupt controller

8237

DMA controller

8251

Serial I/O USART controller

3 of 28

Outline

  • Asynchronous Communication
  • 8251 USART Architecture
  • USART Registers
  • Programming UART
  • RS 232 Port
  • Interfacing CRT Monitor using a UART and RS-232 port

​

​

4 of 28

Data Comm: Serial Vs Parallel

  • Serial
    • Cheaper
    • Slower
  • Parallel
    • Faster
    • Data skew
    • Limited to small distances

Data Transmission

Parallel

Serial

Synchronous

ASynchronous

5 of 28

Type of Serial Communication

Sender

Sender

Receiver

Receiver

Data

Data

Data

Data

Data

Data

Data

Data

a

Transmission Gaps

Asynchronous transmission

Synchronous transmission

CLK

6 of 28

Framing in Asynchronous

  • Character oriented
  • Each character carried start bit and stop bits
  • When No data are being transmitted
    • Receiver stay at logic 1 called mark, logic 0 is Space
  • Framing:
    • Transmission begins with one start bit (low/0)
    • Followed by DATA (8bit) and
    • Stop bits (1 or 2 bits of logic high)

​

​

7 of 28

Type of Serial Communication

Asynchronous transmission

8 bit Data

Start Bit

Start Bits

1 0 0 0 1 1 1 0

LSB MSB

Time

1 start

bit

1 or 2 Stop

bit

Source data

8 of 28

8085 Serial I/O lines

  • Serial Input Data (SID)
  • Serial Output Data (SOD)
    • Instruction SIM is necessary to output data
    • Interpretations (ACC contents)

​

​

​

D7

D6

D5

D4

D3

D2

D1

D0

SOD

SDE (0/1

Dis/Ena SOD)

X

For interrupts

MVI A, 80 ; Set D7 in the ACC=1

RAR ;Set D6 =1 and bring carry into D7

SIM ; output D7

9 of 28

Data transmission Program on SOD

  • Transmit an ASCII Char stored in Register B

MVI B ASCIIDatabyte ; get data byte in B

MVI C,0BH ; set up counter for 11 bits

XRA A ; reset carry to 0

NXTbit: MVI A,80H ;set D7=1 in ACC

RAR ;bring Carry in D7 and set D6=1

SIM ;output D7

CALL DELAYBittime ;wait for fixed time (BWT)

STC ;set Carry 1

MOV A,B ;Place ASIII car in acc

RAR ; place ASCII D0 in Carry

;and shift 1 in D7

MOV B,A ;Save B

DCR C

JNZ NXTbit

RET

10 of 28

Hardware control Serial I/O

  • Programmable chip 8251
  • Requirement of HW control serial I/O
    • An input/output port are required for interfacing
    • Converts data bits in to Parallel to serial & vice versa
    • Data transfer to be synchronized between I/O
    • USART (Universal Synchronous Asynchronous Receiver and Transmitter )

11 of 28

UART/USART

  • Writing a program compatible with all different serial communication protocols is difficult and it is an inefficient use of microprocessor.
  • UART: Universal Asynchronous Receiver/Transmitter chip.
  • USART: Universal Synchronous/Asynchronous Receiver/Transmitter chip.
  • The microprocessor sends/receives the data to the UART in parallel, while with I/O, the UART transmits/receive data serially.
  • 8251 functions are integrated into standard PC interface chip.

​

12 of 28

UART / CPU interface

CPU

8251

status

(8 bit)

data

(8 bit)

serial

port

xmit/

rcv

  • UART/USART
    • 8251 USART
    • 8250/16450 UART is a newer version of 8251.
    • 16550 is the latest version UART.

13 of 28

8251 Block Diagram

Data Bus

Buffer

Transmit

Buffer

Receive

Buffer

Transmit

Control

Receive

Control

R/W

Control

Logic

Modem Control

Internal

​

Line

D7-D0

RESET

CLK

C/Db

RDb

WRb

CSb

DSRb

DTRb

CTSb

RTSb

TXD

TXRDY

TXE

TXC

RXD

RXRDY

RXC

SYBDET/BD

14 of 28

8251 Registers

CSb

C/Db

RDb

WRb

Meaning

1

X

X

X

Data Bus Tri-state

0

X

1

1

Data Bus Tri-state

0

1

0

1

Status 🡪 CPU

0

1

1

0

Control Word🡨 CPU

0

0

0

1

Data 🡪 CPU (accept data from Data Buffer)

0

0

1

0

Data 🡨 CPU (Out put data to Data buffer)

15 of 28

Control Logic & Registers

R/W

Control

Logic

RESET

CLK

C/Db

RDb

WRb

CSb

Data Buffer register

D7-D0

C/Db=0

RDb or WRb

Control Register

16 bit

Status Register

8 bit

C/Db=1

WRb=0

C/Db=1

RDb=0

Internal

Data

​

Bus

Transmitter

Receiver

16 of 28

Transmitter and Receiver

Data

Buffer

Register

D0

​

​

D7

​

Internal

​

Data

Bus

Transmitter

Buffer

Register

Receiver

Buffer

Register

Out put

Register

Input

Register

Transmitter

Control Logic

Receiver

Control Logic

TxD

​

TxCb

​

TxRDY

TxE

RxD

​

​

​

RxCb

RxRDY

17 of 28

8251: Command Register

(Mode word format)

D7

D6

D5

D4

D3

D2

D1

D0

Framing Control

# of Stop bits

00: invalid

01: 1 bit

10: 1.5 bits

11: 2 bits

Parity Control

X0=No Parity

01: Even

11: Odd

Character length

00: 5 bits

01: 6 bits

10: 7 bits

11: 8 bits

Baud Rate

00: Syn. Mode

01: x1 clock

10: x16 clock

11: x64 clock

18 of 28

Command Register

(Command Word Format)

EH

IR

RTS

ER

SBRK

RxE

DTR

TxE

TxE: transmit enable (0/1 Enable Disable)

DTR: data terminal ready (1=ENABLE DTR)

RxE: receiver enable (1/0=EN/DISABLE)

SBPRK: send break character 1= force TxD low

ER: error reset (Reset Flags: Parity ,Over run, Framing Error of Status Word)

RTS: request to send (1= Enable Request to send)

IR: internal reset (Reset 8251 to mode)

EH: enter hunt mode (1=search for Sync Character)

19 of 28

8251: Status Regsiter

DSR

SYN

DET

FE

OE

PE

Tx

EMPTY

RxRDY

TxRDY

TxRDY transmit ready (DB Buffer is empty)

RxRDY receiver ready

TxEMPTY transmitter empty

PE parity error (1=when PE detected)

OE overrun error

FE framing error (Aynsc only, Valid stop bit not detected)

SYNDET sync. character detected

DSR data set ready (DSR set at 0 level)

20 of 28

RS 232 (Recommended Standard)

  • RS232: Data transmitted as Voltage to terminal
    • 20KBps, 50Mters only
    • Improved to RS 422A (9 pine), RS 423A (15 pin-VGA)
  • Modem (Data transmitted by Frequency)

Data Terminal Equipment

​

(DTE)

CPU

Data Communication

Equipment

​

(DCE)

I/O

2

​

​

3

​

​

7

​

2

​

​

3

​

​

7

RS-232 Cable

Transmit

Transmit

Receive

Receive

+9V

-9V

+9V

-9V

+3V

-0.2V

3V

0.2V

21 of 28

RS-232: Mostly used for Monitor

Pin

Signal

Function

2

TxD: transmitted Data

Output CPU to I/O

3

RxD :Received Data

Input I/O receive from CPU

4

RTS :Request to Send

Output from I/0

5

CTS :Clear to send

Input to I/O, HS signal

6

DSR: Data set ready

CPU send to I/O is ready

7

GND

Comm. Ref GND

8

DCD: Data Carrier Detect

I/O to disable reception

20

DTR: Data terminal ready

Output to indicate I/O is ready

DB-25 DB9

22 of 28

Interfacing a CRT monitor using RS-232 terminal using 8251

  • Connect a RS 232 port onto a CRT terminal
  • Address the 8251A USART at FF to control transmission
  • Specify initialization instructions and status word to transmit characters
    • Async mode with 9600 buad
    • Character length= 7 bit + 2 stop bit
    • No parity check
  • Write instruction to initialize USART and read status word and Setup a loop until the transmitter is ready

​

23 of 28

Interface Diagram

2

​

​

3

​

​

7

​

2

​

​

3

​

​

7

Transmit

Receive

8251A

TxD

​

RxD

RxCb

TxCb

CLK

CTSb GND

8085

MPU

D7

​

​

​

D0

CSb

​

C/Db

A7

A1

A0

Voltage Converter

IORb

IOWb

Reset Out

CLK Out

RDb

WRb

RESET

CLK

D7

​

​

​

D0

Control & Status Register Address=FFH

​

C/Db line should be high, == > A0 =1

24 of 28

Initialization of UART

D7

D6

D5

D4

D3

D2

D1

D0

1

1

0

0

1

0

1

0

Two Stop bits

No parity

7 bit characters

Baud=TxC/16

=153.6k/16

=9600

D7

D6

D5

D4

D3

D2

D1

D0

X

0

X

1

X

0

X

1

​

​

​

ERR Reset

​

Receive Disable

​

Transmit Enable

Mode

Word

COMMAND WORD

STATUS

CAH

11H

D7

D6

D5

D4

D3

D2

D1

D0

X

X

X

X

X

X

X

1

​

​

​

​

​

​

​

Transmit Ready

01H

25 of 28

Initialization instructions

SETUP: MVI A,CAH ; load mode word

OUT FFH ;Write mode word in control register

MVI A,11H ; load command word to enable TX

OUT FFH ;Enable the transmitter

STATUS: IN FFH ; Read the status register

ANI 01H ; Mask all bit except D0

JZ STATUS ; if D0=0 the TX buffer if full

26 of 28

Display message stored at memory location 2070 to CRT

Message is “HELLO CS421”

  1. 0E ; 13 characters to follow
  2. 48; Letter H
  3. 45; Letter E
  4. 4C; Letter L
  5. 4C ; Letter L
  6. 4F ; Letter H
  7. 20; space
  8. 43; Letter C
  9. 53; Letter S
  10. 34; Digit 4
  11. 32;Digit 2
  12. 31; Digit 1
  13. 0D; Carriage return
  14. 0A; Linefeed

27 of 28

Write a program to display message at CRT terminal

LXI H 2070H ; Meory ptr for Message

MOV C, M ; Set up Ctr register

MVI A,40; Reset 8251

OUT FFH

MVI A,CA; Initialize 82512

OUT FFH

MVI A,11 ; initialize for transmit

OUT FFH

STATUS: IN FFH

ANI 01H ;Ckeck TxRDY

JZ STATUS ; is txRDY 1 ? If not wait

INX H ; Pont to Next Char

MOV A,M ; place the Char in ACC

OUT FEH ; Send the Char to Transmitter

DCR C ; DCr cnt

JNZ STATUS ;Again Send the rest of Char

HLT

28 of 28

Thanks