Input and Output (I/O)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Input and Output (I/O)

One of the basic features designed into a computer system is its ability to exchange data with other external devices, and to allow the user to interact with the system.
Input Devices: Keyboard, Mouse, Scanner, Switches, Sensors, etc. Output Devices: Monitors, Printers, Speakers, LEDs, etc.

An interface circuit (or controller card) is usually present between the I/O devices and the CPU to
Handle transfer of data between the CPU and I/O interface Handle transfer of data between I/O device and interface Enable the CPU to request the status of data sent (or received) by the interface

Common I/O interfaces:


Serial I/O: Data is exchanged 1-bit at a time. Parallel I/O: Data is exchanged one byte at a time.

Review: Memory-Mapped I/O


The 68000 employs memory-mapped I/O where all of the I/O device registers are assigned unique addresses within the memory address space.
Memory Map
000000

System Bus

Address Decoder CPU

Address Decoder
0007FF 002000

Program Data

Interface Chip

Memory
The address decoder enables the device to recognize its addresses when issued by the CPU

Register 1 Register 2

0020FF

00C001 00C003

Register 1 Register 2

The same instructions that move data to or from memory can be used to transfer data to or from I/O devices

Role of Registers in Interface


The control register can be programmed to control the way in which the peripheral device operates. ! ! ! ! baud rate stop bits parity etc.

n n+2 n+4 n+6

Control Register Status Register Output Port Input Port

The status register tells the CPU things it needs to know about the peripheral. ! Is the Output Port ready to send data? ! Has data arrived at the Input Port? ! Did an error in transmission occur? The i/o ports temporarily hold data that has been received or is about to be transmitted and are usually buffered.

Input Port Buffered I/O Input Port Input Port

Functional Units of a Serial Data Link

68000
7 0 10010110 D0

Hardware & Software of dedicated system (PC & PC-VT)

Serial Interface - DUART


! Send: parallel-to-serial ! Receive: serial-to-parallel

Serial Interface 0

Shift Register CLK

data transmitted one bit at a time


0 0 0 1 0 1 1 0

! Send: parallel-to-serial ! Receive: serial-to-parallel

Line Drivers
! Translate voltage levels into suitable form

Line Drivers
! Translate voltage levels into suitable form

Transmission path (Twisted Pair)

Terminal

Format of Asynchronous Serial Data


5 to 8 Data Bits Marking (1) T Space (0) Start Bit optional Parity Bit X X X X X X X X P 1 or 2 Stop Bits

Example: Send ASCII M = 1001101 (with even parity & one stop bit)
Mark Space 7 data bits 0 Start bit 1 0 1 1 0 0 1 0 Parity Stop bit bit

Baud Rate
The baud rate is defined as the reciprocal of the transmission time for each bit, and represents the number of bits of information that are transferred per second (including the start, stop and optional parity bit).
1 Baud Rate = T

Typical Baud Rates: 600, 1200, 2400, 19200

Example An asynchronous serial interface is configured to operate at 9600 baud with 1 start bit, 7 data bits, 1 parity bit, and 2 stop bits. How much time would be required to transmit 100 ASCII characters?
Transmission Time = Number of bits to transmit Transmission time per bit = 100 (1 + 7 + 1 + 2) 1/9600 = 0.11 seconds

Clock-Select Register for Channel A (CSRA)


The clock-select register is used to specify the transmitter and receiver baud rates.

Clock-Select Register A (CSRA) Receiver Clock 7 6 5 4 Baud Rate 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 300 600 1200 2400 4800 9600 19200 Transmitter Clock 3 2 1 0 Baud Rate 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 300 600 1200 2400 4800 9600 19200

$00C003

Clock-Select Register A (CSRA)

Memory-mapped address

e.g., configure DUART to operate at 9600 baud.


MOVE.B #$BB,$00C003

Channel A Mode Register 1 (MR1A)


This register defines the basic operating parameters of the DUART.
Channel A Mode Register 1 (MR1A) Other Parameters 7 6 5 Parity Mode 4 3 Parity Type 2 0 = even 1 = odd Bits/Character 1 0

(assume 000)

00= with parity 01= no parity

10 = 7 11 = 8

$00C001

MR1A

e.g., configure DUART to operate with 7 data bits and odd parity.

Memory-mapped address

MOVE.B

#$06,$00C001

Channel A Mode Select Register 2 (MR2A)


This register also defines the basic operating parameters of the DUART.
Channel A Mode Register 2 (MR2A) Channel mode 7 6 other parameters 5 4 Stop bit length 3 2 1 0 0 1 1 1 = 1 bit 1 1 1 1 = 2 bits

00 = Normal

(assume 00)

$00C001

MR2A

e.g., configure the DUART to operate normally with 2 stop bits.

Memory-mapped address

MOVE.B

#$0F,$00C001

Channel A Command Register (CRA)


This register is used to control the DUARTs transmitter and receiver.

Channel A Command Register (CRA) Other Commands 7 6 5 4 (assume 0000) Transmitter Commands 2 3 Receiver Commands 1 0 00 = No action, stays in same mode. 01 = Receiver enabled 10 = Receiver disabled

00 = No action, stay in same mode. 01 = Transmitter enabled 10 = Transmitter disabled

$00C005

CRA

e.g., enable the DUARTs transmitter and receiver.

Memory-mapped address

MOVE.B

#$05,$00C005

Initializing the DUART


Write an instruction sequence to initialize the DUARTs channel A to operate at 9600 baud with 1 start bit, 7 data bits, odd parity, and 2 stop bits.

DUART MR1A MR2A CSRA CRA

EQU EQU EQU EQU EQU

$00C001 0 0 2 4

;DUARTs base register ;mode register 1A ;mode register 2A ;clock select register A ;command register A

LEA MOVE.B MOVE.B MOVE.B MOVE.B END

DUART,A0 #$06,MR1A(A0) #$0F,MR2A(A0) #$BB,CSRA(A0) #$05,CRA(A0)

;A0 points to DUART ;7 data bits, odd parity ;2 stop bits ;set baud rate = 9600 ;enable Tx/Rx

Channel A Status Register (SRA)


The status register provides information about the DUARTs receiver and transmitter.

$00C003

SRA

Memory-mapped address

Received Break
7

Framing Error
6

Parity Error
5

Overrun Error
4

TxEMPT Y

TxRDY
2

FFULL
1

RxRDY
0

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

0 = No 1 = yes

Errors
Request for termination of connection
$00C007

Transmit buffer Transmit buffer

Receive buffer Receive buffer Receive buffer

$00C007

Receive buffer

input/output ports

Reading a Character

Start

Bit 0
$00C003 Read RxRDY Flag $00C007

SRA

RxRDY

Receive Buffer

Character Waiting?

NO YES
Read Character Clear Flag

DUART SRA RBA

EQU $00C001 EQU 2 EQU 6 LEA MOVE.B ANDI.B BEQ MOVE.B END DUART,A0 SRA(A0),D7 #1,D7 LOOP RBA(A0),D0

;Base Address ;Status Reg A ;Receive buffer ;point to DUART ;read status reg A ;RxRDY = 1? ;no: check again ;yes: input character

LOOP

Polling

Clears Flag if buffer is empty

Writing a Character

Start

Bit 2
$00C003 Read TxRDY Flag $00C007

SRA

TxRDY

Transmit Buffer

Buffer Empty? NO YES


Write Character Clear Flag

DUART SRA TBA

EQU $00C001 EQU 2 EQU 6 LEA MOVE.B ANDI.B BEQ MOVE.B END DUART,A0 SRA(A0),D7 #4,D7 LOOP D0,TBA(A0)

;Base Address ;Status Reg A ;Transmit buffer ;point to DUART ;read status reg A ;TxRDY = 1? ;no: check again ;yes: output character

LOOP

Polling

Example
Write a program that displays the message, Assembly language programming is fun, on the terminal attached to the DUARTs serial port A. Display the message 10 times on 10 separate lines.

DUART SRA TBA CR LF

EQU EQU EQU EQU EQU

$C001 2 6 $0D $0A

;68681 base address ;status register A ;Tx buffer A ;ASCII carriage return ;ASCII line feed

ORG $8000 MESSAGE MOVE.W #10,D7 LOOP MOVEA.L #TEXT,A1 BSR OUTSTR SUBQ #1,D7 BNE LOOP TRAP #14 TEXT DC.B DC.B

;use D7 as counter ;A1 ---> message ;send it ;decrement loop index ;repeat until done

CR,LF,'Assembly language programming' ' is fun',0

****************************************************** * OUTCHR - OUTput CHaRacter in D0 to serial port * * * * ENTER: D0[0:7] contains ASCII character * * EXIT: D0[0:7] unchanged * * D0[8:31] cleared * * USES: no subroutines * ****************************************************** OUTCHR MOVE.L A0,-(A7) ;save A0 MOVE.W D7,-(A7) ;save D7 MOVEA.L #DUART,A0 ;A0 points to 68681 OUTCHR2 MOVE.B SRA(A0),D7 ;get port A status ANDI.B #4,D7 ;buffer empty? BEQ OUTCHR2 ;no: check again MOVE.B D0,TBA(A0) ;yes: send char. MOVE.W (A7)+,D7 ;restore D7 MOVE.L (A7)+,A0 ;restore A0 RTS ****************************************************** * OUTSTR - OUTput null-terminated STRing * * * * ENTER: A1 points to string * * EXIT: A1 points to null-terminator * * USES: OUTCHR * ****************************************************** OUTSTR MOVE.L D0,-(A7) ;save D0 on stack OUTSTR2 MOVE.B (A1)+,D0 ;get character BEQ EXIT ;if null byte, done BSR OUTCHR ;send BRA OUTSTR2 ;repeat EXIT MOVE.L (A7)+,D0 ;restore D0 RTS END MESSAGE

You might also like