Professional Documents
Culture Documents
Input and Output (I/O)
Input and Output (I/O)
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
System Bus
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
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.
68000
7 0 10010110 D0
Serial Interface 0
Line Drivers
! Translate voltage levels into suitable form
Line Drivers
! Translate voltage levels into suitable form
Terminal
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
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 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
Memory-mapped address
(assume 000)
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
00 = Normal
(assume 00)
$00C001
MR2A
Memory-mapped address
MOVE.B
#$0F,$00C001
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
$00C005
CRA
Memory-mapped address
MOVE.B
#$05,$00C005
$00C001 0 0 2 4
;DUARTs base register ;mode register 1A ;mode register 2A ;clock select register A ;command register A
;A0 points to DUART ;7 data bits, odd parity ;2 stop bits ;set baud rate = 9600 ;enable Tx/Rx
$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
$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
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
Writing a Character
Start
Bit 2
$00C003 Read TxRDY Flag $00C007
SRA
TxRDY
Transmit Buffer
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.
;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
****************************************************** * 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