+ All Categories
Home > Documents > Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer...

Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer...

Date post: 02-Apr-2015
Category:
Upload: sheldon-weatherhead
View: 232 times
Download: 5 times
Share this document with a friend
Popular Tags:
28
Programming 8251 USART Controller Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati
Transcript
Page 1: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Programming 8251 USART Controller

Dr A SahuDept of Comp Sc & Engg.

IIT Guwahati

Page 2: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Hierarchy of I/O Control Devices8155

I/O + Timer

8255I/O

8253/54Timer

2 Port (A,B), No BidirectionalHS mode (C)4 mode timer

2 Port (A,B)A is BidirectionalHS mode (C)Extra controls

6 mode timer

8259 Interrupt controller

8237DMA controller

8251Serial I/O USART

controller

Page 3: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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

232 port

Page 4: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Data Comm: Serial Vs Parallel

• Serial – Cheaper – Slower

• Parallel – Faster– Data skew– Limited to small distances

Data Transmission

Parallel Serial

Synchronous ASynchronous

Page 5: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Type of Serial Communication

Sender

Sender

Receiver

ReceiverData Data Data Data Data

Data Data Dataa

Transmission Gaps

Asynchronous transmission

Synchronous transmission

CLK

Page 6: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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)

Page 7: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Type of Serial CommunicationAsynchronous transmission

8 bit Data

Start Bit Start Bits

1 0 0 0 1 1 1 0 LSB MSB

Time

1 startbit

1 or 2 StopbitSource data

Page 8: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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/1Dis/Ena SOD)

X For interrupts

MVI A, 80 ; Set D7 in the ACC=1RAR ;Set D6 =1 and bring carry into

D7

SIM ; output D7

Page 9: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Data transmission Program on SOD

• Transmit an ASCII Char stored in Register B

MVI B ASCIIDatabyte ; get data byte in BMVI C,0BH ; set up counter for 11 bitsXRA A ; reset carry to 0

NXTbit: MVI A,80H ;set D7=1 in ACCRAR ;bring Carry in D7 and set D6=1SIM ;output D7CALL DELAYBittime ;wait for fixed time (BWT)STC ;set Carry 1MOV A,B ;Place ASIII car in accRAR ; place ASCII D0 in Carry

;and shift 1 in D7MOV B,A ;Save BDCR CJNZ NXTbitRET

Page 10: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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 )

Page 11: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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.

Page 12: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

UART / CPU interface

CPU8251

status(8 bit)

data(8 bit)

serialport

xmit/rcv

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

Page 13: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

8251 Block Diagram

Data Bus Buffer

TransmitBuffer

Receive Buffer

TransmitControl

Receive Control

R/W Control

Logic

Modem Control

Internal

Line

D7-D0

RESETCLKC/Db

RDb

WRb

CSb

DSRb

DTRb

CTSb

RTSb

TXD

TXRDYTXETXC

RXD

RXRDYRXCSYBDET/BD

Page 14: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

8251 Registers

CSb C/Db RDb WRb Meaning1 X X X Data Bus Tri-state0 X 1 1 Data Bus Tri-state0 1 0 1 Status CPU0 1 1 0 Control Word CPU0 0 0 1 Data CPU (accept data

from Data Buffer)0 0 1 0 Data CPU (Out put data

to Data buffer)

Page 15: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Control Logic & Registers

R/W Control

Logic

RESETCLKC/Db

RDb

WRb

CSb

Data Buffer register

D7-D0

C/Db=0RDb or WRb

Control Register16 bit

Status Register

8 bit

C/Db=1WRb=0

C/Db=1RDb=0

Internal Data

Bus

Transmitter

Receiver

Page 16: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Transmitter and Receiver

Data Buffer

Register

D0

D7

Internal

Data Bus

Transmitter Buffer

Register

Receiver Buffer

Register

Out put Register

InputRegister

Transmitter Control Logic

Receiver Control Logic

TxD

TxCb

TxRDYTxE

RxD

RxCb

RxRDY

Page 17: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

8251: Command Register (Mode word format)

D7 D6 D5 D4 D3 D2 D1 D0

Framing Control # of Stop bits

00: invalid01: 1 bit10: 1.5 bits11: 2 bits

Parity ControlX0=No Parity01: Even11: Odd

Character length00: 5 bits01: 6 bits10: 7 bits11: 8 bits

Baud Rate00: Syn. Mode01: x1 clock10: x16 clock11: x64 clock

Page 18: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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 lowER: 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)

Page 19: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

8251: Status Regsiter

DSR SYNDET FE OE PE Tx

EMPTYRxRDY TxRDY

TxRDY transmit ready (DB Buffer is empty)RxRDY receiver ready TxEMPTY transmitter emptyPE parity error (1=when PE detected)OE overrun errorFE framing error (Aynsc only, Valid stop bit

not detected)SYNDET sync. character detectedDSR data set ready (DSR set at 0 level)

Page 20: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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

3V0.2V

Page 21: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

RS-232: Mostly used for MonitorPin 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

Page 22: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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

Page 23: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Interface Diagram

2

3

7

2

3

7

Transmit

Receive

8251A

TxD

RxD

RxCb

TxCb

CLKCTSb GND

8085MPU

D7

D0

CSb

C/Db

A7A1

A0Voltage ConverterIORb

IOWb

Reset OutCLK Out

RDb

WRb

RESETCLK

D7

D0

Control & Status Register Address=FFH

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

Page 24: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Initialization of UARTD7 D6 D5 D4 D3 D2 D1 D01 1 0 0 1 0 1 0Two Stop bits No parity 7 bit characters Baud=TxC/16

=153.6k/16=9600

D7 D6 D5 D4 D3 D2 D1 D0X 0 X 1 X 0 X 1

ERR Reset

Receive Disable

Transmit Enable

ModeWord

COMMAND WORD

STATUS

CAH

11H

D7 D6 D5 D4 D3 D2 D1 D0

X X X X X X X 1

Transmit Ready

01H

Page 25: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Initialization instructions

SETUP: MVI A,CAH ; load mode word OUT FFH ;Write mode word in control

registerMVI A,11H ; load command word to enable TXOUT FFH ;Enable the transmitter

STATUS: IN FFH ; Read the status registerANI 01H ; Mask all bit except D0JZ STATUS ; if D0=0 the TX buffer if full

Page 26: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Display message stored at memory location 2070 to CRT

Message is “HELLO CS421” 2070 0E ; 13 characters to follow2071 48; Letter H2072 45; Letter E2073 4C; Letter L2074 4C ; Letter L2075 4F ; Letter H2076 20; space2077 43; Letter C2078 53; Letter S2079 34; Digit 42080 32;Digit 22081 31; Digit 12082 0D; Carriage return 2083 0A; Linefeed

Page 27: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

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 8251OUT FFHMVI A,CA; Initialize 82512OUT FFHMVI A,11 ; initialize for transmitOUT FFH

STATUS: IN FFHANI 01H ;Ckeck TxRDYJZ STATUS ; is txRDY 1 ? If not waitINX H ; Pont to Next CharMOV A,M ; place the Char in ACCOUT FEH ; Send the Char to TransmitterDCR C ; DCr cntJNZ STATUS ;Again Send the rest of CharHLT

Page 28: Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. Hierarchy of I/O Control Devices 8155 I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54.

Thanks


Recommended