Professional Documents
Culture Documents
Objectives
Operation of basic I/O operations Decode 8-, 16, and 32-bit addresses for enabling I/O ports Handshaking for I/O operations Interface and program the 82C55 PPI (programmable peripheral interface) Using the 82C55 to connect LEDs, keyboards, etc. to the processor Interface stepper and DC motors to the processor Interface and program the 16550 programmable asynchronous serial interface adapter (UART) Interface and program the 8254 programmable interval timer (PIT)
I/O Instructions
Two types: - Transfer data between the processor accumulator (AL, AX, EAX) register
and I/O device: IN and OUT - Transfer string data between memory and I/O device directly: INS and OUTS (for processors above 8086) The IN instruction (I/O Read): Inputs data from an external I/O device to the accumulator. The OUT instruction (I/O Write): Copies the contents of the accumulator out to an external I/O device. The accumulator is: - AL (for 8-bit I/O), - AX (for 16-bit I/O), - EAX (for 32-bit I/O).
I/O Address
As with memory, I/O devices have I/O addresses (addresses for the I/O port) Up to 64K I/O bytes can be addressed The 16-bit port address appears on address bus bits A15-A0 This allows I/O devices at addresses 0000H-FFFFH Two ways to specify an I/O port address: - An 8-bit immediate (fixed) address (specified as a byte in the instruction): e.g. IN AX, p8 ; Reads a word from port p8 0000H-00FFH (can only see the first 256 addresses) - A 16-bit address located in register DX (can be easily varied): e.g. OUT DX, AL; outputs the byte in AL to the port whose address is in DX 0000H-FFFFH (upto 16K addresses). i.e. high port addresses are accessible only through DX addressing
DX
00FF
Immediate 4
00F3H 00F2H
Port Address p8
00F0H
LS byte
AL
(Note corrections)
Width of Transfer Determined by the A register used Width of Transfer Determined by the Instruction used
No argument, DX by default
DX DX DX
But most Intel-based systems e.g. the PC, use isolated I/O
Some other processors do not have dedicated I/O instructions and therefore use only memory-mapped I/O addressing, e.g. the PowerPC microprocessor (Macintosh computers)
8
Memory and I/O address Maps for the 8086/8088 Memory: MOV a. Isolated I/O Using dedicated I/O instructions e.g. IN, OUT I/O: IN
00FF
64 K I/O bytes
Memory
10
0100 00FF
Interval (8254)
Can Use either: - Fixed (immediate) 8-bit I/O address in instruction, p8 - Variable 16-bit I/O address in register DX
0000
0000
11
IN (I/O Read)
The IN instruction primarily takes he following forms: Data from the Input port addressed
is put on the data bus for the processor to read into the A register
IN IN IN IN IN IN
15
Basic 8-bit Input Interface: Reads the status of 8 toggle Switches (a byte read) Pull-up Resistors
Gate
To mP
0 1 Toggle switches
3-state buffer
The SEL signal is generated (active low) By decoding: - The address for the I/O port - The I/O READ operation
whenever the mP executes the correct OUT instruction with the correct
I/O port address Must latch the processor data put on the bus during the I/O instruction to
17
From mP
Edge-triggered latch
OE
Data is latched and remains here until the next OUT instruction to this port is executed The SEL is generated (for + ive edge triggering) by decoding: - The address for the I/O port - The I/O WRITE operation 18
Parallel Port
The parallel port is an example of interfacing slow devices, e.g. a
printer, to the processor A printer can print say 100s of characters per sec (CPS), but the
19
Interfacing
When connecting external input and output devices to the processor, we
must take into account the DC characteristics and drive capabilities of the
mP pins.
mP Input
mP Output
Source Sink
Sink Source
20
TTL Input to mP
The pullup resistor does the conditioning required to allow the switch to produce a TTL compatible input to the processor
Switches
bounce
and
this
is
often
undesirable.
Here, processor senses the switch effect directly- hence bouncing is a problem, especially if input Is used as a clock
Initial Posn
TTL Input to mP
22
A Blue, White, or Ultra Bright LED passes more current at a larger voltage drop, e.g. 30 mA @ 2.5 V.
A bit of electronics!
23
V diode + _
I min = 10 mA
Vdiode 1.65 V
To ensure I = 10 mA, R should be
Vout
LED ON indicates 1 or 0 at Input?
+ 1.65 V _
Ic = 10 mA Ib = 0.1 mA b c e Rb 0.7V 0.1V (Transistor Is saturated)
(TTL)
Transistor: b = Base Use minimum gain value specified e = Emitter (worst case condition) c = Collector Vout, high, min 0.7 Rb Nearest standard 0.1mA resistor value 2.4 0.7 17 KW 18 kW 25 0.1
Driving larger currents and voltages; e.g. DC motors, mechanical relays, etc.
Large current loads such as motors or large relays require a Darlington pair in place of the transistor driver Two transistor gains in cascade, (b = b1 b2), so smaller base currents from TTL for large load currents Can use 12 V or higher supply Select a transistor that meets both the voltage and current requirements for the load The diode is used to prevent the transistor from being destroyed by the inductive kickback current that appears when the field collapses suddenly in the coil
12 V DC Motor
Vout, high, min 0.7 0.7 Rb 0.143mA (TTL) 0.7V 2 .4 1 .4 0.7V 7 KW 6.8 kW 1A/(7000)=0.143 mA 0.143
Ic = 1 A
Rb
b b1 b2
Current can not change instantly through an inductor. If it suddenly drops from I1 to 0, a negative current - I1 is generated which gradually decays to 0. The diode provides a safe path for this current away from the transistor
26
WK 9
As with memory addresses, port addresses must also be decoded to select an I/O device for a particular port number. Memory mapped I/O is identical to memory access (with IO/#M = 0) Will consider here only isolated I/O (using dedicated instructions: IN, OUT, etc.)
Address Decoding for 8 I/O Ports: F0 to F7 for the 8088 using 8-bit I/O address
a. Using a Decoder IC
X X X X X X 0 1 1 0
MS part (Enable decoder)
Decoder I/Ps
Decoder O/Ps
To Enable Inputs on the 8 I/O ports A7 ....A0 11110 000 = F0 1st 11110 001 = F1 2nd . 11110 111 = F7 7th
28
1 1 1 1 1 1
3-to-8 Decoder
Address from mP
Note: #IO/M decoding should be added
29
Data Bus
2-bit Address I/P (select port or Command register for Read or Write)
Read/Write Control
B
Port B + lower half of C = Group B (12 bits)
On the PC: Two 82C55s CS Input -One 82C55 occupies (low) 4 I/O ports 60H-63H: Handling Keyboard, timer, speaker, etc. -One 82C55 occupies 4 I/O ports 378H-37BH Parallel printer port
RESET initializes the PPI to operate in mode 0 & all 3 ports as inputs at power up. With all ports as input ports, this avoids damage to the device at Power up 30
31
A1
A0 Function
Port C (PC7-PC4).
Group B is Port B and lower of Port C (PC3-PC0).
0 0 1
0 1 0 1
Writing into this register programs the various ports to operate in various modes and be used as either inputs or outputs
A1 A0 Inputs on 82C55 A7 A6 A5 A4 A3 A2 A1 A0 1 1 0 0 0 0 0 0 = C0H Port A 1 1 0 0 0 0 1 0 = C2H Port B 1 1 0 0 0 1 0 0 = C4H Port C 1 1 0 0 0 1 1 0 = C6H Comnd Register
80386SX Processor
001
33
Program
Program
Bit 7 = 0: Command Byte B: Sets (to 1) or Clears (to 0) the specified one of 8 bits of port C (in modes 1 and 2)
34
8255 Modes
Mode 0 (for groups A & B)- the most commonly used mode: All 12 bits of the group
are simple inputs or simple latched outputs
Data Data
Mode 1 (for groups A & B)- is used occasionally to provide handshaking to an I/O device and operate asynchronously with the device. Most Port C bits are dedicated for handshake functions for the operation. A few are controlled separately using the Command byte B format for handshaking I/O.
Data
Mode 2 (for group A only- Group B not used)- is a bidirectional mode for Port A only
35
8255 Modes
36
Segment Driver
Common 38
7-Segement Display
CA Vcc
Anode
Cathode
CC
Select Segments: Switched Resistors to Vcc
GND
39
7-Segement Display
Anode
Cathode
40
by a factor of n
n=8 Digits
41
0 turns digit B: O/P Port: digit ON B: O/P Port: Select # Displayed Select digit To be displayed
Vcc
Digit transistor switch Controlled by Port B bit, e.g. Tr 1 7 Segment data transistor switches 42 Controlled by Port A bits, e.g. Tr 2
1 digit . . . . . .
library ieee; use ieee.std_logic_1164.all; entity DECODER_11_21 is port ( IOM, A15, A14, A13, A12, A11, A10, A9, A8, A7, A6, A5, A4, A3, A2: in STD_LOGIC; D0: out STD_LOGIC ); end; architecture V1 of DECODER_11_17 is begin D0 <= not IOM or A15 or A14 or A13 or A12 or A11 or not A10 or not A9 or not A8 or A7 or A6 or A5 or A4 or A3 or A2; 82C55 end V1;
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 X X Total: 16-bit I/O address 14-bit address decoding Using PLD
On chip Selection
4 I/O ports: 0700 0701 0702 0703 Port A Port B Port C Control 43 Register
; Program the 82C55 for Port A and Port B are output ports in mode 0 MOV AL, 80H ; 80H Data into AL 8 bytes of MOV DX, 703H ; Address of Command Port into DX Digit Data OUT DX, AL ; Write 80H into Command Port In memory ; ; to program PPI MS Digit MEM+7 ; An assembly language procedure that multiplexes the 8-digit display. . ; This procedure must be called often enough for the display to appear stable . DISP PROC NEAR USES AX BX DX SI BX PUSHF . MEM LS Digit MOV BX,8 ;load counter BX with # of display digits MOV AH,7FH ;load initial digit selection pattern to enable MS digit (01111111) MOV SI,OFFSET MEM - 1 ;Load SI with offset (MEM) - 1 MOV DX,701H ;address Port B (for Port A: decrement DX) ;Sequentially display all 8 digits starting with MS digit .REPEAT MOV AL,AH OUT DX,AL ;send digit selection pattern to Port B DEC DX ;Address Port A (to send Digit Data) MOV AL,[BX+SI] ;Load digit data from memory into AL OUT DX,AL ;send digit data to Port A CALL DELAY ;wait 1.0 ms leaving displayed digit ON ROR AH,1 ;adjust selection pattern to point to next digit INC DX ;Address port B DEC BX ;decrement counter for data of next digit. .UNTIL BX == 0 Procedure for 1 ms delay, e.g. a loop of instructions POPF i.e. digit remains ON for 1 ms before moving to next RET 44 DISP ENDP
; Delay Loop DELAY D1: LOOP D1 RET ENDP PROC NEAR USES CX MOV CX, XXXX
DELAY
Loop execution time is calculated from instruction data and the clock frequency.
An 80486 executes LOOP D1 in 7 clock cycles With a 20 MHz clock, loop exec time = 7 x 50 = 350 ns XXXX = 1ms/350ns
Display Flashing Rate: - Assume the DISP Procedure is called continuously - Ignore loop execution times relative to delay time (e.g. 350 ns << 1 ms)
1 ms Digit Displayed 8 7 8 ms
DISP Proc DISP Proc
... 2 1 8 7
... 2 1
...
46
47
Coils
Stator
Rotor
1
N
2 2
S
1
Stators
S N
2 2
S N
1
Rotor
49
Winding number 1
1
N
6 pole rotor
2
N S
N
2
One step
S N S
Winding number 2
a b
52
53
P P
54
55
STEP SEQUENCING There are three modes of operation which is determined by the step sequence applied. The three step sequences are: Wave Full
Half Stepping
HALF STEPPING: Combination
The half-step sequence has the most torque and is the most stable at higher speeds. It also has the highest resolution of the main stepping methods. It is a combination of full and wave stepping.
56
57
D
Anti-clockwise Rotation N Pole lies between the two energized coils Rotation Direction: Anti-clock wise Step angle: 90
A B C D 0 0 1 1
ROR reverses the direction of Motor rotation
225
315
58
1 activates coil
Anti-surge diodes
ROL
Rotate instruction operates on whole byte 0011 We want to rotate half the byte duplicate pattern! 0110 ROL ROR 1100 Current angular 1001 POS 03H or 06H or 0CH or 09H Position stored at location Anti-Clockwise Clockwise POS (in memory) 59
60
The top electromagnet (1) is turned on, attracting the nearest teeth of a gearshaped iron rotor. With the teeth aligned to electromagnet 1, they will be slightly offset from electromagnet 2
The top electromagnet (1) is turned off, and the right electromagnet (2) is energized, pulling the nearest teeth slightly to the right. This results in a rotation of 3.6 in this example.
61
The left electromagnet (4) is enabled, rotating again by 3.6. When the top electromagnet (1) is again enabled, the teeth in the sprocket will have rotated by one tooth position; since there are 25 teeth, it will take 100 steps to make a full rotation in this example. 62
63
Stepper motors
CNC lathes
64
Stator coils
Rotor
65
Advantages / Disadvantages
Advantages:-
66
67
68
Necessity
It solves:
Generation of accurate time delays in microprocessor system under software control (No processing overhead due to looping to create a delay-the microprocessor can trigger the counting and do some other job while the timer is producing necessary delays)
69
CS A1 A0 0 0 0 0 0 1 0 1 0 0 1 1
70
71
OUT: can be square wave, or one shot GATE: Enable (high) or disable (low) the counter Data Pins: (D0 ~ D7) Allow the CPU to access various registers inside the 8253/54 for both read and write operations. RD and WR are connected to IOR and IOW of control bus.
72
The programmer can not only write the value of the divisor into the 8253/4, but read the content of the counter at any given time as well All counters are down counters.`
73
74
75
76
77
Example:
78
If GATE becomes low at the middle of the count, the count will stop and the output will be low. The count resumes when the GATE becomes high again This in effect adds to the total time the output is low. 79
80
Gate Disable: 1) If Gate = 1 it enables a counting otherwise it disables counting (Gate = 0 ). 2) If Gate goes low during an low output pulse, output is set immediately high . A trigger reloads the count and the normal sequence is repeated.
81
odd
Decrement by 1, then by 2
Decrement by 3, then by 2
82
In Mode4, if GATE=1, the output will go high when loading the count, it will stay high
for duration N*T. After the count reaches zero, it becomes low for one clock pulse, then goes high again and stays high until a new command word or new count is loaded
83
84
85
86
87
88
89
90
91
92
93
Initialization Example
Write a program to initialize counter 2 in mode 0 with a count of C030H. Assume address for control register = 0BH, counter 0 = 08H, counter 1 = 09H and counter 2 = 0AH. Soln:
Control word:
D7 SC1 1 D6 SC2 0 D5 RW1 1 D4 RW0 1 D3 M2 0 D2 M1 0 D1 M0 0 D0 BCD 0
=B0H
Source Program:
MOV AL, B0H OUT 0BH, AL MOV AL, 30H OUT 0AH, AL MOV AL, C0H OUT 0AH, AL ; loads control word to control register ; loads lower byte of the count ; loads higher byte of the count
94
95
= Data rate (bps) for binary data Compatible with Intel and other Processors Includes: - A programmable baud rate generator - 16-byte FIFO buffers at input and output to help processor deal with data bursts
96
97
40 pin DIP
98
mP
Control
16-byte FIFO Input Buffer PS
SIN
Receiver
UART
16-byte FIFO Output Buffer PS
SOUT Data
DMA Data Transfers: Memory UART Directly Without going through the mP
Transmitter
Memory
99
40 pin DIP
Crystal or External Clock Input TX ready for data. Put data into UART by DMA Interrupt Processor RX ready with data. Take data from UART by DMA
100
UARTs in the PC
Used to control the COM ports of the PC - UART at I/O address 3F8-3FF: COM Port 0 - UART at I/O address 2F8-2FF: COM Port 2
101
a. Initialization Dialog: (Setup) - Follows RESET - Has two steps: 1. Program the line control register (Set asynchronous transmission parameters: # of stop, data, and parity bits, etc.) 2. Program the baud rate generator for the required baud rate
b. Operation Dialog: (Actual Communication)
102
0
0 0 0 1 1
0
0 1 1 0 0
0
1 0 1 0 1
Receiver buffer (read data from RX) and transmitter holding (write data to TX). Also write LS byte of baud rate divisor
Interrupt enable. Also write MS byte of baud rate divisor Interrupt identification (read) and FIFO control Register (write) - Used for operation dialog programming Line control Register (Write into the line control register to program asynchronous communication at initialization) Modem control Line status LSTAT (Read the line status register to see if TX or RX are ready and to check for errors )
1
1
1
1
0
1
Modem status
Scratch
103
DL bit must be set before you can load the divisor for the baud generator
300
1200 2400 4800 9600 19,200 38,400 57,600 115,200
3840
920 480 240 120 60 30 20 10
106
(Active Low)
107
;Initialization dialog for Figure 11-45 ;Baud rate 9600, 7 bit data, odd parity, 1 stop bit LINE EQU 0F3H ; A2 A1 A0 = 011 for the Line Control Register LSB EQU 0F0H ; A2 A1 A0 = 000 for LSB of divisor MSB EQU 0F1H ; A2 A1 A0 = 001 for MSB of divisor FIFO EQU 0F2H ; A2 A1 A0 = 010 for the FIFO Control Register INIT PROC NEAR MOV AL,10001010B OUT LINE,AL ; Enable Baud rate programming See slide 108
; program Baud 9600 ; Divisor = 120d (see Table on slide 110) MOV AL,120 OUT LSB,AL MOV AL,0 OUT MSB,AL MOV AL,00001010B Must write this OUT LINE,AL
into FIFO Register to enable communication and operation dialog programming
; LSB of divisor
; MS Byte of divisor
;program 7 bit data, odd ;parity, 1 stop bit ;(& disable baud rate programming?) ;enable transmitter and receiver ;by writing into the FIFO control Reg.
108
INIT
ENDP
109
Before writing data for transmission, Ensure TX is ready to take it [TH (bit 5) = 1]
110
111
112
113
115
116
MC1408 Description
R-2R ladder:
The R-2R ladder divides the reference amplifier current into binaryrelated components, These are fed to the remainder current which is equal to the least significant bit. The maximum output current is 255/256 of the reference amplifier current.
117
MC1408 Description
Reference current amplifier:
The reference voltage source supplies the full reference current through R14 resistor for Reference current amplifier
118
For 8086, the Clock frequency is 5 MHz and the Clock cycle takes 0.2us.
Each Instruction takes some time for Execution.
Examples:
MOV AX,BX takes two clock cycles (0.4us). DAA takes four clock cycles (0.8us).
119
Calculation:
Calculate the clock cycles for each instruction inside and outside the loop.
Find the no. of clock cycles according to delay time and processor clock.
Equate these two values to obtain the CX initialize value.
120
A/D Converter
A/D Converter produces digital word which represents the magnitude of analog voltage or current. Specifications: Resolution Accuracy: The difference between a measurement reading and the true value of that measurement Linearity Conversion Time :
The Conversion Time of A/D Converter is more than D/A converter.
121
122
Disadvantage:
Low Resolution : No. of Comparators (2n-1) required are more.
123
124
After fixed time, the Control switch is towards the negative reference Voltage.
Resets the counter values to zero. The capacitor then discharges linearly with rate of Vref/RC for variable time Produces a positive, fixed-slope ramp.
125
This method is commonly used with voltmeters and other test equipment. Advantages:
Higher resolution Higher accuracy Lower cost Good noise immunity Slow Conversion Time
Disadvantages:
126
127
Conversion Process:
The bits of the D/A converter are enabled one at a time, starting with the MSB. As each bit is enabled, the comparator produces an output. It indicates whether the analog input voltage is greater or less than the output of the D/A converter.
128
If the D/A output is less than the analog input, the comparator output is HIGH and the bit is set HIGH.
This process is repeated for each bit.
Properties
Reliable Capable of high speed
129
131
132
These tasks are carried out by the Microprocessor using 8255 I/O ports.
133
134
135
136