microprocessors l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Microprocessors PowerPoint Presentation
Download Presentation
Microprocessors

Loading in 2 Seconds...

play fullscreen
1 / 42

Microprocessors - PowerPoint PPT Presentation


  • 391 Views
  • Uploaded on

Microprocessors. Input/Output Interface (Chapter 10). Introduction. In a typical computer system, the user communicates with the computer via standard peripheral devices such as the keyboard, mouse, display, printer e.t.c.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Microprocessors' - vail


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
microprocessors

Microprocessors

Input/Output Interface

(Chapter 10)

introduction
Introduction
  • In a typical computer system, the user communicates with the computer via standard peripheral devices such as the keyboard, mouse, display, printer e.t.c.
  • Furthermore computers and microprocessor based systems are used in instrumentation or automatic control applications. In such cases it is necessary that the microprocessor reads the state of input devices (switches, sensors) and activate some output devices (motors, heaters, lights).
  • The I/O interface is required to enable the interface between the microprocessor and the peripheral devices.
  • The peripheral devices are connected on a microprocessor system through the Input/Output ports.
  • The I/O interface provides the following:
    • Isolation between the buses and the peripheral devices.
    • Address decoding.
    • Synchronization/Latching.
isolated vs memory mapped i o
Isolated vs Memory-mapped I/O
  • Isolated I/O
    • I/O locations are separate from memory locations
    • Special I/O instructions are used
    • The most common technique for Intel microprocessors
    • Advantage: More space for memory
    • Disadvantage: Additional control signals (IO/M) and instructions increase complexity
  • Memory-mapped I/O
    • I/O devices are treated as memory locations in the memory map
    • Any memory transfer instruction can be used (MOV, LDR, STR etc)
    • Advantages: Simpler decoding circuitry, no special instructions required
    • Disadvantage: A portion of the memory system is used as the I/O map, reducing the memory available to applications
input output instructions
Input/Output Instructions
  • The 8088 and 80X86 processors use the 16 lower address lines (A0 to A15) to address I/O devices. This limits the maximum number of I/O ports to 64K.
  • The IN instruction copies the content of an input port to register AL, AX or EAX.
  • The OUT instruction copies the content of register AL, AX, or EAX to an output port.
  • Register AL is used for 8-bit ports, AX for 16-bit ports and EAX for 32-bit ports.
  • The 8088 and 80X86 processors support two I/O addressing modes.
    • Fixed Address. The address is directly specified in the instruction as an 8-bit number. That is loaded on the address lines A0 to A7. Address lines A8 to A15 are set to 00.
      • IN AL,30H ;Read input port 0030H into register AL
      • OUT 30H,AL ;Copy register AL to output port 0030H.
    • Variable Address. The address is specified through register DX as a 16-bit address.
      • MOV DX,3A0H ;Set I/O address
      • IN AL,DX ;Read input port [DX] or 3A0H into register AL.
      • OUT DX,AL ;Copy register AL to output port [DX] or 3A0H
high level language input output instructions pascal
High Level Language Input/Output Instructions (Pascal)
  • Input/Output using Pascal: I/O is obtained using the ‘Port[ ]’ instruction.
    • X := Port[PortAddress]; /* Copy the contents of the specified port into X */
    • Port[PortAddress] := X; /* Copy the contents of X into the specified port */
  • Input/Output using Delphi: Delphi does not allow direct access to I/O ports. This can be done by inserting assembly language code into Delphi as follows:

asm ; code equivalent to ‘value:=port[portaddress];

begin

mov dx,portaddress;specify the port address

in al,dx;input from the port specified by “dx” into “al”

mov value,al;copy input data into variable ‘value’

end;

asm ; code equivalent to ‘port[portaddress] := value;

begin

mov dx,portaddress;specify the port address

mov al,value;move output data into register “al”

out dx,al;output data to the port specified by “dx”

end;

high level language input output instructions c c
High Level Language Input/Output Instructions (C/C++)
  • C/C++ does not allow direct access to I/O ports. This can be done by inserting assembly language code into the C/C++ code as follows:

__asm ; code equivalent to ‘value:=port[portaddress];

{

mov dx,portaddress;specify the port address

in al,dx;input from the port specified by “dx” into “al”

mov value,al;copy input data into variable ‘value’

}

__asm ; code equivalent to ‘port[portaddress] := value;

{

mov dx,portaddress;specify the port address

mov al,value;move output data into register “al”

out dx,al;output data to the port specified by “dx”

}

input output using dlls c c
Input/Output Using DLLs (C/C++)
  • For protection purposes, modern operating systems such as the Windows XP do not allow the use of the IN and the OUT instructions in the users programs.
  • A way to have access to I/O ports is through libraries (DLL files) developed for this purpose. Such a library is the inout32.dll
  • To use this library in Visual Studio (C++) we must:
    • Add the inout32.lib file in the Linker properties
      • Project ->Properties->Linker->Input->Additional Dependencies
    • Define the two functions for input and output and use them accordingly
  • short _stdcall Inp32(short PortAddress);
  • void _stdcall Out32(short PortAddress, short data);
  • main()
  • {
  • short Inval = Inp32(889); /* input from port 889 into variable “Inval”*/
  • Out32(888,0x2f); /* Output the hex value 2f to port 888 */
  • }
simple input port
Simple Input Port
  • An input port can be implemented using a simple octal buffer such as the 74LS244.
  • The address decoding circuit enables the three-state buffers of the 74LS244 whenever the port address is selected by the processor. In such a case the state of the input devices appears on the data bus.
  • The address decoding circuit is enabled only if the IO/M signal is set High by the 8088 (Low for the x86 processors) and the RD signal is Low.

Switch Open => Logic 1

Switch Closed => Logic 0

simple output port using the 74ls373
Simple Output Port(Using the 74LS373)
  • An output port can be implemented using a simple octal latch such as the 74LS373.
  • The address decoding circuit enables the D-latches of the 74LS373 whenever the port address is selected by the processor. In such a case the state of the data bus is latched to the output devices.
  • The address decoding circuit is enabled only if the IO/M signal is set High by the 8088 (Low for the x86 processors) and the WR signal is Low.

Logic 1 => LED is OFF

Logic 0 => LED is ON

simple output port using the 74hct573
Simple Output Port (Using the 74HCT573)
  • The 74HCT573 is pin compatible with the 74LS373. There are three significant differences:
    • The ‘573 has all inputs on the left side and all outputs on the right side of the IC, while the ‘373 has the even numbered inputs on the left side and the odd numbered inputs on the right side. Thus the ‘573 is easier to by handled on PCB boards.
    • The HCT573 has a 20mA current sink and a 20mA current source, thus it can drive a LED connected either to the ground or to +5V. The LS373 has a 16mA current sink and a 400uA current source, thus it can only drive a LED connected to +5V.
    • The HCT family is faster than the LS family.

Logic 1 => LED is OFF

Logic 0 => LED is ON

Logic 1 => LED is ON

Logic 0 => LED is OFF

simple i o example 1 hardware
Simple I/O Example 1 (Hardware)
  • Draw a circuit to show how 8 switches can be connected on the input port 3AH and 8 LEDs on the output port 5CH.
simple i o example 1 software
Simple I/O Example 1 (Software)

Write a program to keep reading the state of the switches and switch ON the LED at the position form by the switches at D2, D1 and D0 (i.e. 3X8 decoder).

  • C/C++ Code
  • main()
  • {
  • short InVal, OutVal = 0;
  • do { InVal = Inp32(0x3a);
    • InVal = InVal & 0x7;
    • if (InVal == 0) OutVal = 0x1;
    • if (InVal == 1) OutVal = 0x2;
    • if (InVal == 2) OutVal = 0x4;
    • if (InVal == 3) OutVal = 0x8;
    • if (InVal == 4) OutVal = 0x10;
    • if (InVal == 5) OutVal = 0x20;
    • if (InVal == 6) OutVal = 0x40;
    • if (InVal == 7) OutVal = 0x80;
    • Out32(0x5c,OutVal);
  • } while (!_kbhit());
  • }
  • Pseudo Code:
  • Repeat
  • Read Input port in InVal
    • Mask out D2,D1,D0 from InVal
    • if InVal = 0 then OutVal = 1
    • if if InVal = 1 then OutVal = 2
    • if InVal = 2 then OutVal = 4
    • if InVal = 3 then OutVal = 8
    • if InVal = 4 then OutVal = 16
    • if if InVal = 5 then OutVal = 32
    • if InVal = 6 then OutVal = 64
    • if InVal = 7 then OutVal = 128
    • Write OutVal to Output port
  • Until keypressed
mask operations
Mask Operations

(a) Write a program to keep reading the .

(b) Write a program to keep reading the state of the switches and switch ON the LEDs for which the corresponding switch is closed.

simple i o example 2
Simple I/O Example 2

Four float switches and four LEDs are used to indicate the level of a liquid in the tank shown below. The switches and the LEDs are connected on a computer through an interface board with an input and an output port occupying the address 460H to 46FH.

  • Draw the circuit diagram of the interface board.
  • Write a program to keep reading the state of the float switches and display the liquid level on the LEDs. If an error is detected then switch ON all LEDs.
simple i o example 2 software using case switch statement
Simple I/O Example 2 (Software using Case/Switch Statement)
  • Pseudo Code:
  • Set OutVal to 0, i.e switch off all leds
  • Repeat
  • Read Input port in InVal
    • Mask out D3,D2,D1,D0 from InVal
    • Case of InVal
    • 0: OutMask = 1
    • 1: OutMask = 2
    • 3: OutMask = 4
    • 7: OutMask = 8
    • FH: OutMask = 10H
    • else OutMask = 1FH
    • Mask in D4 to D0 of OutMask in OutVal
    • Write OutVal to Output port
  • Until keypressed
  • C/C++ Code
  • main()
  • {
  • short InVal, OutVal = 0;
  • do {
  • InVal = Inp32(0x460);
    • InVal = InVal & 0xf;
    • switch (InVal) {
    • case 0: OutMask = 1; break;
    • case 1: OutMask = 2; break;
    • case 3: OutMask = 4; break;
    • case 7: OutMask = 8; break;
    • case 0xf: OutMask = 0x10; break;
    • default OutMask = 0x1f; }
    • OutVal = (OutVal & 0xe0) | OutMask;
    • Out32(0x460,OutVal);
  • } while (!_kbhit());
  • }
simple i o example 2 software using array as a lookup table
Simple I/O Example 2 (Software using array as a lookup table)
  • C/C++ Code
  • main()
  • {
  • short InVal, OutVal = 0;
  • short Table[16] = 0x1, 0x2, 0x1f, 0x4,
  • 0x1f, 0x1f, 0x1f, 0x8,
  • 0x1f, 0x1f, 0x1f, 0x1f,
  • 0x1f, 0x1f, 0x1f, 0x10;
  • do {
  • InVal = Inp32(0x460);
    • InVal = InVal & 0xf;
    • OutMask = Table[InVal];
    • OutVal = (OutVal & 0xe0) | OutMask;
    • Out32(0x460,OutVal);
  • } while (!_kbhit());
  • }
  • Pseudo Code:
  • Table[0] = 00001 /*
  • Table[1] = 00010 /*
  • Table[3] = 00100 /*
  • Table[7] = 01000 /*
  • Table[15] = 10000 /*
  • Table[rest] = 111111 /*
  • Repeat
    • Read Input port in InVal
    • Mask out D2,D1,D0 from InVal
    • Mask in D2,D1,D0 of Table[InVal] to OutVal
    • Write OutVal to Output port
  • Until keypressed
dc motor speed and direction control
DC Motor Speed and Direction Control
  • The speed of a DC motor is proportional to the DC voltage applied at its terminal.
    • Thus the speed can be controlled by controlling the DC voltage.
  • The DC voltage can be controlled by:
    • Inserting a resistor in series with the DC motor.
      • Unnecessary dissipation of energy on the resistor.
    • Using Pulse Width Modulation (PWM)
  • The direction of rotation a DC motor is reversed by reversing the polarity of the DC voltage applied at its terminal.
    • This can be obtained using a relay (change-over connection).
    • Connecting a relay on an output port requires the use of high current drivers such as the ULN2803 and diodes to protect the output transistors due to Lenz’s law.
  • Special drivers (H-drivers) can also be used to provide both speed control and direction control.
dc motor interface example
DC motor interface example

A DC motor is connected to a computer as shown below. The switches and the motor are connected on an input and an output port occupying the address 460H to 46FH.

  • Draw a circuit of the interface and the connections to the motor
  • Write a program to keep reading the state of the switches and control the operation of the motor accordingly.
dc motor interface example software using conditional execution
DC motor interface example (Software using conditional execution)
  • Pseudo Code:
  • Set OutVal to 0, i.e motor is OFF
  • Repeat
    • Read Input port in InVal
    • If On/Off bit = 1 then OutVal(D0) = 1
    • else OutVal(D0) = 0
    • If Fast/Slow bit = 1 then OutVal(D1) = 1
    • else OutVal(D1) = 0
    • If Frwd/Rev bit = 1 then OutVal(D2) = 1
    • else OutVal(D2) = 0
    • Write OutVal to Output port
  • Until keypressed
dc motor interface example software using a lookup table
DC motor interface example (Software using a lookup table)
  • Pseudo Code:
  • Table[0] = 000 /* 000 ->motor is Off
  • Table[1] = 000 /* 001 ->motor is Off
  • Table[2] = 010 /* 010 -> On-Slow-Rev
  • Table[3] = 011 /* 011 -> On-Slow-Frwd
  • Table[4] = 000 /* 100 -> motor is Off
  • Table[5] = 000 /* 101 -> motor is Off
  • Table[6] = 110 /* 110 ->On-Fast-Rev
  • Table[7] = 111 /* 111 ->On-Fast-Frwd
  • Repeat
    • Read Input port in InVal
    • Mask out D2,D1,D0 from InVal
    • Mask in D2,D1,D0 of Table[InVal] to OutVal
    • Write OutVal to Output port
  • Until keypressed
7 segment displays
7-Segment Displays
  • Used to display the digits from 0 to 9, as well as many letters (A,b,C,d,E,F,L,H)
  • Consists of seven leds connected to a common point
  • Can be common-anode or common-cathode

Can be connected directly on an O/P port

OR

Through a BCD/7 segment decoder

7 segment displays example1
7-segment Displays– Example1
  • Draw a circuit to show how a common cathode 7-segment display can be connected on an o/p port and four switches on an i/p port both occupying the address range 860h to 86Fh.
  • Write a program to read the state of the switches and display the binary number formed by the switches as a hexadecimal digit.
7 segment displays example 2
7-Segment Displays: Example 2

Four float switches and a 7-segment display are used to indicate the level of a liquid in the tank shown below. The switches and the display are connected on a computer through an interface board with an input and an output port occupying the address 460H to 46FH. Draw the circuit diagram of the interface board.

Write a program to keep reading the state of the float switches and display the liquid level on the display using the digits F(Full), H(High), A (Half), L(Low) and E(Empty). If an error is detected then switch ON the decimal point.

7 segment displays example3
7-segment Displays– Example3
  • Draw a circuit to show how a common cathode 7-segment display can be connected on an o/p port and four switches on an i/p port both occupying the address range 860h to 86Fh.
  • Write a program to read the state of the switches and display the binary number formed by the switches as a hexadecimal digit.
7 segment displays example130
7-segment Displays– Example1
  • Draw a circuit to show how common cathode 7-segment display can be connected on an o/p port and four switches on an i/p port both occupying the address range 860h to 86Fh.
  • Write a program to read the state of the switches and display the binary number formed by the switches as a hexadecimal digit.
homework question 1
Homework- Question 1
  • Draw a circuit diagram to show how four switches and two 7-segment displays can be interfaced to an 8088 based system occupying the address 10H to 1FH, 20H to 2FH and 30H to 3FH respectively.  
  • Write a program to read the binary number formed by the four switches and display the equivalent decimal number on the 7-segment displays. For example if the switches form the number 0110, the displays should display the number 06, and if the switches form the number 1110, then the displays should display the number 14.
homework question 2
Homework- Question 2
  • Draw a circuit diagram to show how four switches and a 7-segment display can be interfaced to an 8088 based system occupying the address A0H to AFH, F0H to FFH respectively.
  • Write a program to read the state of the switches and display on the 7-segment display the letter:
    • H, if there are more switches closed than open,
    • L, if there are less switches closed than open,
    • E, if the number of switches closed is equal to the number of switches open.
homework question 3
Homework- Question 3
  • Draw a circuit diagram to show how six switches and eight Leds can be interfaced to an 8088 based system occupying the address 30H to 3FH, 20H to 2FH respectively.
  • Write a program to read the binary number formed by the six switches and display the equivalent Binary Coded Decimal number on the Leds. For example if the switches form the number 100101, the displays should display the number 00110111, since (100101)2 = (00110111)BCD.
homework question 4
Homework- Question 4
  • Draw a circuit diagram to show how the following can be interfaced to an 8088 based system:
    • Four switches connected on an I/P port occupying the address range from 30H to 3FH.
    • Eight Leds connected on an O/P port occupying the address range from 20H to 2FH.
  • Write a program to read the BCD number formed by the four switches, and display it on the eight Leds the square of the input number in BCD form. If the number formed by the switches is an invalid BCD number, then all of the Leds should be switched ON.
    • For example if the switches form the number 00000101 then the Leds should display 00100101, since (00000101)BCD = (05)10 and 52 = 25 = (00100101)BCD
    • If the number formed by the switches is 00001100 then the Leds should display 11111111 since 1100 is an invalid BCD number.
homework question 5
Homework- Question 5
  • Draw a circuit diagram to show how a common cathode 7-segment display can be connected on an output port, occupying the address CAH.
  • Write a program to display the digits from 0 to 9 on the 7-segment display with a 1-second delay between digits.
  • Write a procedure to display on the 7-segment display, the letter E if the contents of the variable INVAL is equal to 80H, the letter H if INVAL is greater than 80H, or the letter L if INVAL is less than 80H.
  • Write a program that keeps reading the binary number from the input port 0AAH and displays on the 7-segment display, a letter according to the table given below.
homework question 6
Homework- Question 6
  • Draw a circuit diagram to show how the following can be interfaced to an 8088 system
    • Three switches connected on an I/P port occupying the address range from 60H to 6FH.
    • Eight Leds connected on an O/P port occupying the address range from 50H to 5FH.
  • Write a program to
    • read the code formed by the three switches in a 1-second time intervals,
    • convert the input code into a binary value according to the table below and store it in an array called BINV, and
    • display it as a bar graph on the eight Leds as shown in figure below

For example if the switches form the number 101 then the number 110 must be stored in the array BINV and the Leds should display 11111110.  

the 82c55 programmable peripheral interface ppi
THE 82C55 PROGRAMMABLE PERIPHERAL INTERFACE (PPI)
  • A popular interfacing component, for interfacing TTL-compatible I/O devices to the microprocessor.
  • Requires insertion of wait states if used with a microprocessor using higher that an 8 MHz clock.
  • PPI has 24 pins for I/O that are programmable in groups of 12 pins and three modes of operation (Basic I/O, Strobed I/O, Strobed Bi-directional Bus I/O).
  • In the PC, an 82C55 or its equivalent is decoded at I/O ports 60H-63H, interfacing keyboard and Parallel printer port).

VCC: The +5V power supply pin.

GND: GROUND

D0-D7: I/O DATA BUS

RESET: A high on this input clears the control register and all ports (A, B, C) are setto the input mode with the “Bus Hold” circuitry turned on.

CS: Chip select is an active low input used to enable the 82C55A onto theData Bus for CPU communications.

RD: Read is an active low input control signal used by the CPU to read statusinformation or data via the data bus.

WR: Write is an active low input control signal used by the CPU to load controlwords and data into the 82C55A.

A0-A1: Address input signals, in conjunction with the RD and WR inputs, controlthe selection of one of the three ports or the control word register (00 – Port A, 01 – Port B, 10 – Port C, 11 – CR).

PA0-PA7 (I/O PORT A): 8-bit input and output port.

PB0-PB7 (I/O PORT B): 8-bit input and output port.

PC0-PC7 (I/O PORT C): 8-bit input and output port.

example
EXAMPLE
  • Use a 82C55 PPI to interface four switches at address 60H and a SSD at address 62H
programming the 82c55
PROGRAMMING THE 82C55
  • Mode 0 operation causes the PPI to function as either buffered input or latched output
  • The 82C55 is programmed through two internal command registers, selected through bit 7.
  • Command byte A
    • 0 Port C, PC3-PC0 (1-input, 0-output)
    • 1 Port B (1-input, 0-output)
    • 2 Mode (00-mode 0, 01-mode1)
    • 3 Port C, PC7-PC4 (1-input, 0-output)
    • 4 Port A (1-input, 0-output)
    • 5-6 Mode (00-mode 0, 01-mode 2, 1X-mode 2)
    • 7 Command byte select (always 1 for Command byte A)
  • Command byte B
    • Used in mode 1 and mode 2
example41
Example
  • Rewrite the program of the example of slide 30, this time using the PPI and setting up the ports as shown in the previous slide
homework
Homework
  • All examples of slides 31-36 can be modified to include PPI interfacing