Basics of peripheral devices and Working

13,178 views
12,878 views

Published on

This class notes is meant for Electronics and Physics students of various universities.

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
13,178
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
711
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Basics of peripheral devices and Working

  1. 1. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com BASICS OF PERIPHERAL DEVICES AND WORKINGIntroduction Microprocessor based system design involves interfacing of the processor with one ormore peripheral devices for the purpose of communication with various input and output devicesconnected to it. During the early days of the microprocessor revolution, these techniquesrequired complex hardware consisting of Medium scale integration devices making the designhighly complex and time consuming. So, the manufacturers (INTEL) have developed a largenumber of general and special purpose peripheral devices most of them being single chipcircuits. They are also programmable devices. Hence these peripheral devices are found to be oftremendous use to a system designer. Peripheral devices, can broadly be classified into two categories. (a) General purpose peripherals and (b) Special purpose peripherals (Dedicated function peripherals) General purpose peripherals are devices that perform a task but may be used forinterfacing a variety of I/O devices to microprocessor. The general purpose devices are givenbelow: Simple I/O -- (Non-programmable) Programmable peripheral Interface (PPI) – (8255) Programmable Interrupt Controller – (8259) Programmable DMA Controller – (8237/8257) Programmable Communication Interface – (8251) Programmable Interval Timer – (8253/8254) Special function peripherals are devices that may be used for interfacing amicroprocessor to a specific type of I/O device. These peripherals are more complex andtherefore, relatively more expensive than general purpose peripherals. The special functionperipherals (Dedicated function peripherals) are Programmable CRT Controller Programmable Floppy Disc Controller Programmable Hard Disc Controller Programmable Keyboard and display interface. The functioning of these devices varies depending on the type of I/O device they arecontrolling.PROGRAMMABLE PERIPHERAL INTERPHASE - 8255AIntroduction INTEL introduced this programmable peripheral interface (PPI) chip 8255A forinterfacing peripheral devices to the 8085 system. This versatile chip 8255A is used as a generalpurpose peripheral device for parallel data transfer between microprocessor and a peripheraldevice by interfacing the device to the system data bus. The PPI has three programmable I/Oports viz., Port A, Port B and Port C each of 8 bit width. Port C can be treated as two ports –1
  2. 2. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comPort C upper (PC7-4) and Port lower (PC3 – 0) and these two can be independently programmedas INPUT or OUTPUT ports also.Salient Features i. It is a general purpose programmable I/O device which is compatible with all INTEL processors and also most other processors. ii. It provides 24 I/O pins which may be individually programmed in two groups. iii. This chip is also completely TTL compatible. iv. It is available in 40 pin DIP and 44 pin plastic leaded chip carrier (PLCC) packages. v. It has three 8 bit ports. Port A, Port B and Port C. Port C is treated as two 4 bit ports also. vi. This 8255 is mainly programmed in two modes (a) the I/O mode and (b) The bit set/reset mode (BSR) mode. The I/O mode is further divided into three modes: Mode 0, Mode 1, and Mode 2. vii. An 8 bit control resister is used to configure the modes of 8255. There is also another 8 bit port called control port, which decides the configuration of8255 ports. This port is written by the microprocessor only.Pin Description The 8255A is a 40 pin DIP chip which works at single + 5V DC. The pin diagram of8255A chip is shown in Fig. The pin details of the chip are given below. PA3 1 40 PA4 PA2 2 39 PA5 PA1 3 38 PA6 PA0 4 37 PA7 RD 5 36 WR CS 6 35 Reset GND 7 34 D0 A1 8 33 D1 A0 9 32 D2 PC7 10 8255A 31 D3 PC6 11 30 D4 PC5 12 29 D5 PC4 13 28 D6 PC0 14 27 D7 PC1 15 26 Vcc PC2 16 25 PB7 PC3 17 24 PB6 PB0 18 23 PB5 PB1 19 22 PB4 PB2 20 21 PB3 Pin Configuration of 8255 (Top view – DIP Package)2
  3. 3. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com Pin description of 8255A3
  4. 4. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com Selection of 8255A Ports and their functionBlock Diagram of the 8255AThe functional diagram of 8255A is shown in Fig. Each functional unit is explained below.4
  5. 5. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com Functional Block Diagram of 8255A Programmable Peripheral Interface (PPI)Data Bus buffer This tri-state bidirectional 8 bit buffer is used to interface the data bus of 8255A to thesystem data bus. Data is transmitted or received by the buffer when the CPU executes input oroutput instructions control words and status information is also transferred through the data busbuffer.Read/Write and Control Logic The function of this block is to manage all the internal and external transfers of both dataand control or status words. It accepts inputs from the CPU and inturn issues commands to bothof the control groups.Group A and Group B Controls Each of the group A and group B control blocks receives control words from the CPUand issues suitable commands to the ports associated to it. The group A control block controlsport A and port C Upper (PC7 - PC4) where are group B control block, controls port B and port Clower (PC3 - PC0)Port A It has one 8 bit data output latch/buffer and one 8 bit input latch buffer. This port A canbe configured in all the three modes: mode0, mode 1, mode 2.Port B This has an 8 bit data input/output latch/ buffer which can be programmed both in mode 0and mode 1.Port C It has one 8 bit unlatched input buffer and an 8 bit output latch/buffer. This port can bedivided into two 4 bit ports under the mode control. These two ports can be used as controlsignals for ports A and B in the handshake mode.Operational Modes of 8255 8255 can be mainly configured in two modes. i) Input/Output mode (I/O mode) ii) Bit Set-Reset mode (BSR mode) Input/Output mode In I/O mode, the ports of 8255 acts as programmable ports, while in BSR mode only portC (PC0 - PC7) can be used to set or reset its individual port bits. The 8255 can programmed to operate in any one of the following modes. i) Mode 0 (simple mode) ii) Mode 1 (strobed mode)5
  6. 6. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com iii) Mode 2 (bi-directional bus mode)Mode 0: Simple I/O Mode This is a simple I/O or basic mode in which no hand shake signals are used. Port A andPort B are used as two simple 8 bit I/O ports and port C as two 4 bit ports it is used with thoseI/O devices whose timing characteristics are clearly known. For example, if an I/O device sendsa byte for every 10 ms, to the UP, we can execute the IN instruction for every 10 ms to receivethe data. All the 3 ports can be programmed in Mode 0.Mode 1: Storbed Mode This is a handshake I/O mode (strobed mode) in which the data transfer is controlled byhandshake signals. For example, when the microprocessor wish to transfer the data to arelatively slow device like printer, for proper transfer of data handshake signals are used toinform the processor whether the printer is ready to receive the data or not. The data transfer byhandshake use both port A and port B as 8 bit input/output ports. Port A uses the upper threesignals PC3, PC4 and PC5 where as port B uses the lower signals PC2, PC1 and PC0 forhandshaking signals. The remaining two lines of port C are used in Mode 0. The unique featureof this mode is that the data transfer can take place without direct CPU intervention. When portA or port B are configured as input ports the three control signals used are IBF (Input BufferFull), (strobe) and INTR (Interrupt request). Similarly when port A or port B are programmedas mode 1 output ports, the three control signals used are (Output Buffer Full), (Acknowledge)and INTR (Interrupt Request). A very important point to be remembered is that only port A and port B can beconfigured in mode 1. Mode 2: Bidirectional I/O (or) Strobed Bidirectional I/O In this mode port A alone can be configured to both, transmit and receive data. Placeover a single 8 bit data bus using handshaking signals. This mode of operation is useful whentransferring data between two computers. As it is bidirectional I/O, it needs more number ofhandshake signals i.e., 5 lines of port C, PC3 - PC7. The remaining lines of port C can be used byport B in Mode 1. So, when port A is programmed to operate in mode 2, port B can operate inmode0 or mode1.If programmed for mode 0, PC0 - PC2 can be programmed as mode 0 inputs oroutputs. If port B is programmed for mode 1, PC0 - PC2 become handshake signals for this port. In conclusion, we can understand that, Port A can be in Mode 0, Mode 1 or Mode 2. Port B can be in Mode 0 or Mode 1 Port C can only be in Mode 0.Note: A high on reset line of 8255, resets all the ports A, B and C to work as input ports in mode0. The reset pin of 8255 is generally connected to Reset Out pin of 8085.BSR (Bit Set/Reset) Mode6
  7. 7. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com The BSR mode is related to only with the 8 bits of port C, which can be set or reset bywriting an appropriate control word in the control register. A control word with bit D7 = 0 istreated as a BSR control word. It does not change any previously transmitted control word withbit D7=1.So, the I/O operations of port A and port B are not changed by a BSR control word. InBSR mode, individual bits of port C can be used for applications such as an ON/OFF switch.Control Word The 8255A has an 8 bit control register. The contents of this register called, the controlword, decides the I/O function for each port. This register is allowed to write a control wordwhen A0 and A1 lines are at logic 1. This register is not accessible for a read operation. In the control word register, the bits D0 through D2 correspond to the group B controlblock as shown in Fig.4.3. Bit D0 configures the lower four lines of port C for input / outputoperation. Control Word Format of 8255 and Control Bit Description When D0 = 0, port C Lower - output port7
  8. 8. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com D0 = 1, port C Lower - input port. The bit D1 configures port B as an 8 bit wide input or output When D1 = 0, port B is output port. D1 = 1, port B is input port. The bit D2 is the mode select bit for port B and the lower 4 bits of port C. D2 = 0, selects Mode 0 D2 = 1, selects Mode 1. The bits D3 through D6 in the control register correspond to the group A control. Bits D3 and D4 of the control register are used to configure the operation of the upper halfof port C and complete port A. When D3 = 0, port C upper is output port. or D3 = 1, port C upper is input port. Similarly when D4 = 0, port A is output port. or D4 = 1, port A is input port. The bits D5 and D6 are used to select among the three modes of operation names mode 0,mode 1 and mode 2. D6 D5 = 00 selects mode 0 = 01 selects mode 1 = 1x selects mode 2. The last control register bit D7 is the mode set flag, which is shown in Fig.3. D7 = 1 selects I/O mode and D7 = 0 selects BSR mode. BSR Mode Control Word Register Format8
  9. 9. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comThe bit set/reset function is not really a control word. Instead, it allows individual bits of port Cto be set or reset. But only one bit can be set or reset at a time. One of the advantages of thismode is that individual bits of port C can be changed without changing any of the others. This isneeded when port C is used to control the ON/OFF status of several external devices. For example, the device connected to PC4 can be turned ON without affecting the statusof any devices connected to the other seven outputs. The bit set/reset function is used in mode 1 and 2 to enable interrupt outputs available inthese modes.Programmable Interval Timer - 8253/54Introduction It is always possible to generate accurate time delays using the microprocessor system byusing software loop programs. But that will waste the precious time of CPU. Hence INTELintroduced the chips 8253/8254 which is a hardware solution for the problem of generatingaccurate time delays. These chips can be used for applications such as a real-time clock, eventcounter, a digit alone shot, a square wave generator and also as a complex wave form generator.Salient Features 8254 is an upgraded version of 8253 and they are pin-compatible. The features of thesechips are almost same except that, 8254 can operate with higher clock frequency ranging from DC to 8 MHz and 10 MHz, whereas the 8253 can operate with clock frequency from DC to 2 MHz. 8254 includes a status read-back command that can latch the count and the status of thecounters. This command is not available in 8253. 8253 uses N-MOS technology where as 8254 uses H-MOS technology. The chips are packaged in 24 pin DIP and requires a single +5V DC power supply. Three identical 16 bit counters that can operate independently in any of the six modes are available. The counters are down counters. These chips are compatible with all INTEL and most of the other microprocessors. To operate a counter, a 16 bit count is loaded in its register and on command beings to decrement the count until it reaches 0. At the end of the count, it generates a pulse that can be used to interrupt the microprocessor. The counters can be programmed for either binary or BCD count. The read-back command of 8254 allows the user to check the count value and current status of the counter.Pin Description The chips 8253/54 is packaged in a 24 pin DIP and require a single +5V power supply.The pin diagram is shown in Fig. The description of each pin is given below.9
  10. 10. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com Pin Diagram of 8253/54(Top view Dip)10
  11. 11. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comBlock Diagram of 8254 The block diagram of the Programmable Interval Timer is shown in Fig. The blockdiagram includes three counters - Counter 0, Counter 1 and Counter 2, a data bus buffer,read/write control logic and a control word register. Each counter has two input signals CLOCKand GATE and one OUTPUT signal-out. Functional Block Diagram of 8253/8254Data Bus Buffer This tri-state bidirectional 8 bit buffer is used to interface the 8253 to the system bus.Data is transmitted or received by the buffer upon execution of INPUT or OUTPUT CPUinstructions. The data bus buffer has three basic functions. They are i. Programming the MODES of the 8253. ii. Loading the count registers and iii. Reading the count values.Read/Write Logic11
  12. 12. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com The read/write logic accepts inputs from the system bus and in turn generates controlsignals for overall device operation. It is enabled or disabled by so that no operation can occur tochange the function unless the device is selected by the system logic.RD : A low on this pin informs the 8253 that the CPU is inputting data in the form of countersvalue.WR : It is an active low pin. A low on this pin informs the 8253 that the CPU is outputting datain the form of mode information or loading counters.A0,A1: These two lines are address lines used to select one of the three counters and the controlword register as shown in the table for mode selection.CS(Chip Select): It is an active low pin. A low on this input enables 8253. No read or writewill occur unless the device is selected. The input has no effect on the actual operation of thecounters. Selection and function of 8253/54 CountersControl Word Register This register is selected when A0, A1 are at logic 1. It then accepts the information fromthe data bus buffer and stores it in a register. The information stored in this register controls theoperation MODE of each counter, selection of binary or BCD counting and the loading of eachcount register. The control word register can only be written to into, but no read operation ispossible.Counter 0, Counter 1, Counter 2 These three functional blocks are identical in operation. Each counter consists of a single16 bit, pre-settable DOWN counter. The counter can operate in either binary or BCD and itsinput, gate and output are configured by the selection of modes stored in the control word12
  13. 13. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comregister. The counters are totally independent. The counter can be read by a simple READoperation for event count applications.Operational Description The complete functional operation of 8253 is programmed by the system software. A setof control words must be sent out by the CPU to initialize each counter of 8253/8254 with thedesired MODE. Once programmed, the 8253 is ready to perform whatever timing tasks it isassigned to perform. The actual counting operation of each counter is totally independent and additional logicis provided on-chip so that the usual problems associated with efficient monitoring andmanagement of external, asynchronous events or rates to the micro computer system have beeneliminated.Programming 8253/54 Each counter of 8253/54 is individually programmed by writing a control word intocontrol word register. The control word register is shown in Fig.below. The different bits of this8 bit register are either set or reset for the operation of the counters. The various options aregiven below. Control Word Format Counter selection is done by the D6, D7 bits.The bits D4, D5 decides the counter READ/LOAD operations as shown below.13
  14. 14. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comThe bits D1, D2 and D3 decides the mode operation 8253/54 can be configured in six modes. This mode selection is done by these bits as shown below. The D0 bit decides whether the counter is a 16 bit binary counter or a BCD counter. When D0 = 0 it acts as a 16 bit binary counter. D0 = 1 it acts as a binary coded decimal counter (BCD) While using 8253/54 we must write the control word to initialize the counter to be used.For every counter we use, the control word must be written and select the counter and set it up.8253/54 can operate in six different modes. The modes of operation are explained below. Mode 0 (Interrupt on Terminal Count) The output of the counter will be initially low after the mode set operation. After thecount is loaded into the selected counter register the output will remain low and the counter willcount. When terminal count is reached, the output will go high and remain high until theselected count register is reloaded with the mode or a new count is loaded.Mode 1 (Programmable one shot) In this mode, the out signal is initially high. When the GATE is triggered, the OUT goeslow, and when count reaches 0, the OUT goes high again. Thus a one shot signal is generateddue to the signal on the GATE.Mode 2 (Rate Generator) It is a divide by N counter. In this mode, a pulse is generated that is equal to the clockperiod at a given interval controlled by the count that is loaded. When the count is loaded, theOUT signal stays high until the count reaches 1, at this point the OUT signal goes low for oneclock period. Afterwards, the count is reloaded automatically and the cycle repeats, generating acontinuous string of pulses.Mode 3 (Square-wave Generator) In this mode, when the count is loaded, the OUT signal is high. The count is thendetermined by two with each clock cycle. When the count reach 0 the OUT signal goes low andthe count is reloaded automatically. As this is repeated continuously a square wave is generatedon the OUT signal. The period of the square wave is controlled by the count value.14
  15. 15. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comMode 4 (Software Triggered Strobe) In this mode, the OUT signal is initially high and goes low for one clock period when thecount reaches 0. So, one strobe pulse (low) is generated for each count. The count must bereloaded for more strobe signals.Mode 5 (Hardware - Triggered Strobe) This mode is similar to mode 4, except the strobe is hardware triggered with a signal onthe GATE signal. The OUT signal is initially high. When the GATE signal goes from low tohigh, the count starts and when it reaches 0, the OUT signal goes low for one clock period.Read-Back Command The read-back command in the 8254 allows the user to read the count and the status ofthe counters (This command is not available in 8253). When the read-back command is selectedin the control word (SC1 SC0 - 11) each of the counters specified is latched and then the countand/ or the status may be read for each counter latched. The command is written in the control register and the count of the specified counter(s)can be latched if COUNT (bit D5) is 0. A counter or a combination of counters is specified bymaking the respective CNT bits (D1, D2 and D3) high. The read-back command format is shownbelow. D0 = 0 (Reserved for future expansion) CNT0, CNT1, CNT2 are counter select bits. Read back command format The STATUS of the counters can be read if D4 bit (STATUS) of Read-back command is0. The Read-back command eliminates the need of writing separate counter latch commands fordifferent counters.Programmable Interrupt Controller - 8259Introduction There is an absolute need of this Programmable Interrupt Controller for Interfacing I/Odevices to the microprocessor The 8085 processor has 5 interrupt lines namely, Trap, RST 7.5,RST 6.5, RST 5.5 and INTR. So, we can interface five I/O devices, which can perform theinterrupt driven data transfer safely. But, suppose we wish to connect more than five I/Odevices, to the microprocessor, then we may have to connect more than one I/O device to theinterrupt lines. This will affect the interrupt driven data transfer and the microprocessor has toperform polling. i.e, it has to check each device, which is in need of interrupt service. Thispolling has the dis-advantage of long time and slow interrupt response. Hence to overcome all15
  16. 16. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comthese problems, INTEL introduced the 28 pin DIP chip -8259. This device accepts interruptrequests from as many as 8 devices independently and as many as 64 I/O devices by cascadingmethod.Salient Features INTEL 8259 is a single chip programmable interrupt controller which is compatible with8085, 8086 and 8088 processors. It is a 28 pin DIP IC with N-Mos technology and requires a single +5 DC supply. It handles up to eight vectored priority interrupts for the CPU and cascadable for up to 64 vectored priority interrupts without the need of any additional circuitry. when two 8259s are cascaded through cascade lines the first 8259 will act as master and the second 8259 will act as a slave.Pin Description The pin diagram of 8259 is shown below . The pin details are given below Pin Diagram of 8259Block Diagram The block diagram of programmable interrupt controller is shown in Fig. below. Theblock diagram consists of eight sub units. They are Control logic, Read/write logic, Data bus16
  17. 17. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.combuffer. Three register (IRR, ISR and IMR), 5 priority resolver and cascade buffer. The functionsof each unit are explained below.Priority Resolver This logic unit determines the priorities of the bits set in the IRR. The highest priority isselected and strobed in to the corresponding bit of the ISR during pulse.Interrupt Mask Register (IMR) The IMR stores the bits which mask the interrupt lines. The IMR operates on the IRR.Masking of a higher priority input will not affect the interrupt request lines of lower priority.17
  18. 18. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comControl Logic This unit has two pins. INT (Interrupt) as an output pin and (interrupt acknowledge) asan input pin. The INT is connected to the interrupt pin of the microprocessor unit. Whenever aninterrupt is noticed by the CPU, it generates signal.Working of 8259 The 8259 accepts interrupt requests from any one of the 8 I/O lines (IR 0 - IR7). Then itascertains the priority of the interrupt lines. Then it ascertains the priority of the interrupt lines.Suppose, the received interrupt has higher priority than currently serviced, it interrupts themicroprocessor and after receiving the interrupt acknowledgement from microprocessor. Itprovides a 3 byte CALL instruction. The sequence of steps that occur when an interrupt requestline of 8259 goes high is as follows. The 8259 accepts the requests on IR0 - IR7 in IRR. Then it checks the contents of IMR whether that request is masked or not. The 8259, then checks ISR to know the interrupt levels that are being currently serviced. After this 8259 sends a high INT to 8085 processor. Normally, it is the job of the priority resolver to check the contents of IRR, IMR and ISR and decide whether to activate INT output of 8259 or not. Now 8085 processor responds by suspending the program flow at the end of the current instruction and makes low. On receiving, 8259 sends code for CALL to the microprocessor on D7-0 bus. This code for CALL in IR register of 8259 causes the 8085 to issue two more signals.When goes low the second time, 8259 places LSB of ISS address on the data bus. When goeslow the third time, 8259 places the MSB of ISS address ont he data bus. Now, the microprocessor branches to the ISS after saving the contents of program counter on the stack top. After finishing the ISS, the control returns to the main program by popping the top of stack to PC.Programming 8259 The 8259 requires two types of command words namely, Initialization Command Words(ICW) and Operational Command Words (OCW). The 8259 can be initialized with four ICWs,the first two are essential and the other two are optional based on the modes being used. Thesewords must be issued in a sequence. Once the 8259 is initialized, the 8259 can operate in variousmodes by using three different OCWs.Direct Memory Access (DMA) When large amount of data is to be transferred between microprocessor and I/O device itis a very time consuming operation and the CPUs time is wasted. If the I/O port can directlyaccess memory for data transfer, without CPU intervention, that will be more efficient. So, inany microprocessor system, if the data transfer occurs without the intervention of the CPU, that18
  19. 19. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.commethod is known as Direct Memory Transfer technique (DMA).This is explained in the figurebelow.As an example , the data transfer between a floppy disk and a R/W memory in a computersystem is based on DMA.To perform the DMA transfer in 8085 based systems two pins HOLD and HLDA (HoldAcknowledge) are used. An I/O device which wishes to transfer data using DMA scheme,sends the HOLD signal to the CPU. On receiving the HOLD signal from an I/O device, the CPUsends a hold acknowledge signal (HLDA) to the I/O device to indicate that it has received theHOLD request and it will give-up the buses in the next machine cycle. The I/O device takesover the control of buses and directly transfer data to the memory or reads data from thememory. This data transfer can be shown by the Fig.4.14. There are two types of DMA schemes. They are a) Burst mode DMA b) Cycle stealing DMABurst Mode DMA This method is used when a large data block is to be transferred between a I/O device andmain memory. In each DMA cycle one byte will be transferred and the DMA controller givesupcontrol of system buses only after all the data has been transferred. The DMA controllerinterrupts the microprocessor and HOLD request is withdrawn. This technique was widely used by magnetic disk drives. In case of magnetic disks datatransfer can not be stopped or slowed down without loss of data. Hence burst mode data transferscheme is useful.Cycle Stealing DMA This method is used when the I/O device is relatively slow. After a DMA cycle whichresults in a byte of data transfer, the I/O device withdraws the DMA request. So, the DMAcontroller withdraws the Hold request by making it low. So, the CPU comes out of HOLD modeand continues to execute the main program. After some time when the I/O device is again ready,it once again activates the data request I/P of DMA controller. So, DMA again activates theHOLD pin and waits for HLDA. Now the data transfer is performed again. In this way the19
  20. 20. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comcomplete data is transferred. As the data transfer occurs during certain cycles of CPU, it is calledcycle stealing DMA.DMA Controller - Intel 8237/8257 In Direct Memory Access technique, the data transfer takes place without the interventionof CPU, so there must be a controller circuit which is programmable and which can perform thedata transfer effectively. For this purpose Intel introduced the controller chip 8257 which isknown as DMA controller. A DMA controller temporarily borrows the address bus, data busand control bus from the microprocessor and transfers the data bytes directly from the port tomemory devices. As the transfer is handled totally by hardware, it is much faster than softwareprogram instructions. A DMA controller can also transfer data from memory to a port.Salient Features Intel 8257 is a programmable, 4-channel direct memory access controller i.e., fourperipheral devices can request data transfer at any instant. The request priorities are decidedinternally. Each channel has two signals, DRQ (DMA Request) and (DMA acknowledge). Eachchannel has two 16 bit registers. One for the memory address where the data transfer shouldbeing and the second for a 14-bit count. There are also two 8-bit registers one is the mode setregister and the other is status register. It can operate both in slave and master mode. It is atotally TTL compatible chip.Pin Diagram: 8257 is a 40 pin IC package which requires a single +5V supply for its operation.The pin details are as follows. The pin diagram is shown in Fig below. Pin Diagram of 8257Block Diagram The functional block diagram is shown below. It consists of20
  21. 21. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com Data bus buffer Read/Write logic DMA channels Control logic Mode set Register Status RegisterData Bus Buffer Three state bidirectional, 8 bit buffer interfaces the 8257 to the system data bus. Whenthe 8257 is being programmed by the CPU, eight bits of data for DMA address register, aterminal count register or the mode set register are received on the data bus. When the CPUreads the DMA address register, a terminal count register or status register, the data is sent to theCPU over the data bus. When 8257 is operating as Master, during a DMA cycle, it gains control over the systembuses. In this mode, the 8257 sends out the 8 MSBs of the DMA address register of the channelbeing serviced on the D0-D7 pins at the starting of each DMA cycle to the 8212 latch. After this,the bus is released to handle the memory data transfer during the remaining DMA cycle. Read/Write Logic Pin and Block Diagram of 825721
  22. 22. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com In the slave mode, when the CPU reads data from or writes data to the 8257, theread/write logic accepts the I/OR (or) I/OW signals and decodes the least significant 4 addressbits (A0 - A3). During DMA cycles, when 8257 is the master, the read/write logic generates the I/O readand memory write or I/O write and memory read signals which controls the data link with theperipheral that has been granted DMA cycle. The different signals are(I/O Read) It is active low bidirectional three-state line. In the slave mode, it is an input, whichallows the 8-bit status register or upper/lower byte of a 16 bit DMA address register of terminalcount register to be read. In the master mode, is a control output, which is used to access datafrom a peripheral during the DMA write cycle.(I/O Write) It is an active low bi-directional tri-state line. In slave mode, it is an input, which allowsmicroprocessor to write. In the master mode, is a control output, which allows data to be ouputin the peripheral during DMA read cycle.CLK (Clock Input) This is the clock output of the microprocessor.RESET It is an asynchronous input from the microprocessor which disables all DMA channels byclearing the mode register and tri-states all control lines.A0 - A3 (Address Lines) These least significant four address lines are bidirectional. In the slave mode they areinputs, which select one of the registers to be read or programmed. In the master mode, they areoutputs, which constitute the most significant 4 bits of the 16 bit memory address generated bythe 8257.(Chip Select) It is an active low input which enables the I/O read or I/O write input when the 8257 isbeing read or programmed in the slave mode. In the master mode, is automatically disabled toprevent the chip from selecting while performing the DMA function.Control Logic Block This block controls the sequence operations during all DMA cycles by generating theappropriate control signals and 16 bit address that specifies the memory relations to be accessed.A4 - A7 (Address Lines) These four address lines are tri-stated outputs which contains 4 to 7 of the 16 bit memoryaddress generated by the 8257 during all DMA cycles.READY This is an asynchronous input used to insert wait states during DMA read or writemachine cycles. Wait states are included between S3 and S4 states of the duty transfer.22
  23. 23. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comHRQ (Hold Request) This output line requests the control of the system bus. This is connected to the HOLDinput of 8085.DMA Channels The 8257 has four separate DMA channels each channel with two 16 bit registers (1) aDMA address register (2) Counter register. Both these registers must be initialized before achannel is enabled. The DMA address register is loaded with the address of the first memorylocation to be accessed. The value loaded into the low order 14 bits of the terminal countregister specifies the number of DMA cycles minus one before the terminal count output isactivated.DRQ0 - DRQ3 (DMA Request) These are active low signals one for each of the four DMA channels. The output acts as achip select for the peripheral device requesting service. The DACK line becomes 0 and then 1for each byte of DMA data transfer.Mode Set Register This register is used to set the mode of operation of 8257. It is normally programmed bythe CPU after the DMA address register and terminal count registers are initialized. This registeris cleared by RESET input, by disabling all options. The mode set register is shown in Fig. Bysetting the 4th bit we can opt for rotating priority. Normally DRQ0 has highest priority andDRQ3 has lowest priority. But in the rotating priority mode the priority of the channels has acircular sequence and after each DMA cycle, the priority of each channel changes. If the rotatingpriority bit is reset, (is a zero) each DMA channel has a fixed priority in the fixed priority mode.i.e., channel 0 has highest priority and channel-3 has lowest priority. The terminal count (TC) bits (bits 0 - 4) for the four channels are set when the TerminalCount output goes high for a channel. The TC bits in the status word are cleared when the statusword is read or when the 8257 receives a Reset input. The update flag is cleared when (i) 8257is reset or (ii) the auto load option is set in the mode set register or (iii) when the update cycle iscompleted. The update flag is not affected by a status read operation.DMA WorkingIn 8085 microprocessor two lines dedicated for DMA operation. They are HOLD and HLDA.If any device is in need of DMA service it activates a DRQ line. Now the 8257 in turn sends outHOLD request (HRQ) to microprocessor on HOLD line. The microprocessor then completes thecurrent machine cycle and then goes to HOLD state, where the address bus, data bus and therelated control bus signals are tri-stated. Now the HLDA signal is activated. The DMAcontroller which is a slave to the microprocessor so far will now become the master. The DMAcontroller resolves the priorities of the requesting I/O devices and accordingly sends a signal tothe suitable I/O device. When the microprocessor is the master, D7-0 is used by the 8257 for communication withmicroprocessor and A3-0 are i/p lines to 8257 to select register for communication withmicroprocessor. But in the HOLD state the 8257 sends out most significant byte of memoryaddress A15-8 on D7-0, sends out address information on A3-0 and also on A7-4. Now become23
  24. 24. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comoutput lines of 8257. So, the 8257, after sending out a signal to the requesting I/O device,generates and signals if it is a DMA read operation. 8257 generates and signals for DMA writeoperation. Then a byte of data is transferred between I/O device and memory directly in 4 clockcycles. This is known as a DMA machine cycle, at the end of which, the number of bytes to betransferred is decremented by 1 in the count register and address register is incremented by 1 topoint to the next memory address for data transfer.USART-8251(Universal Synchronous Asynchronous Receiver Transmitter)The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serialdata communication. In a microprocessor system the CPU has to perform the data conversionlike serial to parallel or parallel to serial and transmit the data to peripheral devices. This processwill wastes the precious time of the CPU. In order to release the CPU from this burden andcontinue its processing work , INTEL introduced a 28-pin DIP chip called the programmablecommunication interface. This chip will take care of all the communication activities and lessensthe burden of the Microprocessor .This chip is compatible with all the INTEL processors. This8251 receives parallel data from the CPU and transmits serial data after conversion. Similarly italso receives serial data from outside devices and transmits parallel data into the CPU afterconversion. The 8251 is a 28 pin DIP chip which works at 5 volts DC. The Pin diagram of 8251 is shown below.24
  25. 25. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com The Block diagram of 8251 is shown below sThe USART chip consists of four important sections .They are  CPU Interface & Control Logic section  Transmitter Section  Receiver Section  Modem Control Section .CPU Interface & Control Logic section : The CPU interface and control logic accepts signalsfrom RD, WR, CLK, C/D, CS , D7-0 and RESET pins of the system and generates the necessarysignals for controlling the device operation. It consists of three registers ,8-bit data buffer register,one 16-bit control word register and one 8-bit status word register. The active low signals RD,WR, CS and C/D (Low) are used for read/write operations with these three registers.When C/D bar is high, the control register is selected for writing control word or reading statusword. When C/D bar is low, the data buffer is selected for read/write operation. When the resetis high, it forces 8251A into the idle mode. The clock input is necessary for 8251A forcommunication with CPU and this clock does not control either the serial transmission or thereception rate.25
  26. 26. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comTransmitter section: The transmitter section accepts parallel data from CPU and convertsthem into serial data. This section is double buffered, i.e., it has a buffer register to hold an 8-bitparallel data and another register called output register to convert the parallel data into serial bits.When output register is empty, the data is transferred from buffer to output register. Now theprocessor can again load another data in buffer register. If buffer register is empty, then TxRDYis goes to high. If output register is empty then TxEMPTY goes to high. The clock signal, TxC(low) controls the rate at which the bits are transmitted by the USART. The clock frequency canbe 1, 16 or 64 times the baud rate.Receiver Section: The receiver section accepts serial data and convert them into parallel dataThis receiver section is also double buffered with two registers. i.e., it has an input register toreceive serial data and convert to parallel, and a buffer register to hold the parallel data.When theRxD line goes low, the control logic assumes it as a START bit, waits for half a bit time andsamples the line again. If the line is still low, then the input register accepts the following bits,forms a character and loads it into the buffer register. The CPU reads the parallel data from thebuffer register. When the input register loads a parallel data to buffer register, the RxRDY linegoes high. The clock signal RxC (low) controls the rate at which bits are received by theUSART. During asynchronous mode, the signal SYNDET/BRKDET will indicate the break inthe data transmission. During synchronous mode, the signal SYNDET/BRKDET will indicatethe reception of synchronous character.MODEM Control Section: The MODEM control unit allows to interface a MODEM to 8251Aand to establish data communication through MODEM over telephone lines. This unit takes careof handshake signals for MODEM interface. The Modem control signals are general purpose innature and can be used for functions other than the Modem control if necessary.The Modemsends certain hand shake signals for proper communication between two devices. The DTR andRTS are the are the hand shake signals sent out by the 8251 to Modem and they are activated byusing command instruction register. The DSR and CTS are the hand shake signals sent by theModem to 8251.__DSR (Data Set Ready): This signal is general purpose in nature. This signal is used to normallytest the Modem condition. The CPU reads its condition by Status read operation.___26
  27. 27. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comDTR (Data Terminal ready) :This is an output signal which is also a general purpose. The DTRsignal is used to control the modem operation such as Data terminal ready or rate select.It can beset low by programming the appropriate bit in the command instruction word.___RTS (Request to Send):This output signal is normally used to control the Modem operationssuch as Request to send. This pin can be set low by programming the appropriate bit in thecommand instruction word.___CTS (Clear to Send) :A low on this pin enables the 8251 to transmit the serial data ,if the Tx ENbit in the command byte is set to one.This Modem control section will decrease the burden of the CPU by converting the 0 s and 1sinto unique audio frequencies and transmit on the telephone network.Programmable Keyboard/Display Interface - 8279Intel 8279 is the programmable keyboard/display controller, used to interface the keyboard andthe display unit to the Microprocessors. The advantage of 8279 is that it is able to drive thesignals for both the keyboard and display and hence it is possible for the microprocessor toconcentrate on its processing tasks without wasting time.The 8279 has two major sections. One is the Keyboard section and the other is the Displaysection. The 8279 chip provides four scan lines and eight return lines for interfacing keyboardsand a set of eight output lines for interfacing a display.The 8279 scans a keyboard regularly and detects a key depression ,de-bounces the signal fromthe pressed key and stores the code for the pressed key in an internal RAM of size 8x8.Themicroprocessor reads this RAM on first in first out basis. Similarly the 8279 refreshes themultiplexed display consisting of7-segment LED digits. The 7-segment codes for the data to bedisplayed are stored in a display RAM of size 16x8 with in the 8279.The 8279 automaticallysends the code for each data to be displayed one after the other until all digits have beendisplayed.The 8279 is available as a 40 pin DIP chip and it is compatible with all the INTEL basicprocessors. It works at +5 volts DC. The pin diagram of 8279 is shown below.27
  28. 28. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comThe keyboard section can interface to regular type-writer style keyboards or random toggle orthumb switches. The display section drives alphanumeric displays or a bank of indicator lights.So, the CPU is relieved from scanning the keyboard or refreshing the display continuously. Thekeyboard portion can provide a scanned interface to a 64-contact key matrix. The keyboardportion interfaces an array of sensors or a strobed interface keyboard. Keyboard depressions canbe 2-key lockout or N-key rollover. Keyboard entries are de-bounced and strobed in an 8-charcter FIFO. If more than 8 characters are entered, over-run status is set. Key entries set theinterrupt output line to the CPU.The display section provides a scanned display interface for any display device. Both numericand alphanumeric segment displays may be used as well as simple indicators. The 8279 has 16*8displays RAM which can be organized into dual 16*4. The RAM can be loaded or interrogatedby the CPU. Both right entry, calculator and left entry typewriter display formats are possible.Both read and write of the display RAM can be done with auto-increment of the display RAMaddress.28
  29. 29. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comSince the 8279 is directly connected to the microprocessor, the microprocessor can program alloperating modes of 8279. The various input modes of the 8279 are scanned keyboard, scannedsensor matrix and strobed input.BLOCK DIAGRAM : The block diagram of the 8279 is shown below and each block isexplained.In scanned keyboard mode, a key depression generates a 6-bit encoding of the key position.Position and shift control status are stored in the FIFO. Keys are automatically de-bounced with2-key lockout or N-key rollover. In the scanned sensor matrix, key status is stored in RAMaddressable by the microprocessor. Data on return lines during control line strobe is transferredto FIFO in strobed input. In one output mode, 8 or 16 character multiplexed displays areorganized as dual 4-bit or single 8-bit and another output mode deals with right entry or left entrydisplay formats.The keyboard interface part of 8279 continuously scans the keyboard to check if any key hasbeen pressed. If it finds that a particular key has been pressed it sends the code of thecorresponding key to the microprocessor. The microprocessor uses 8279 to send the result to thedisplay device. In other words, we can say that 8279 controller transmits the data received fromthe CPU to the display device. The major advantage of using 8279 is that both of these activitiesare done without the intervention of the microprocessor. The keyboard can be interfaced to the29
  30. 30. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.commicroprocessor either in the polled mode or in the interrupt mode. In the polled mode themicroprocessor reads an internal flag of 8279 to check if any key has been pressed. In theinterrupt mode, the processor is requested service only if a key is pressed otherwise themicroprocessor can proceed with its routine activities. 8279 permits a maximum of 64 keys to bepresent in the keyboard.This keyboard/display controller maintains an 8-byte First in First out Random AccessMemory (FIFO RAM). If the FIFO contains a valid key entry, the CPU is interrupted (ininterrupt mode) or the CPU checks the status (in polling mode) to read the entry. Once the CPUreads the key, the corresponding entry is deleted from the queue to generate space for the futurekeys that may be pressed. The 8279 normally provides a maximum of sixteen 7 segment displayinterface with CPU. It contains a 16-byte display RAM that can be used either as an integratedblock of 16*8 bits or two 16*4 bit blocks of RAM. The data entry to RAM block is controlled byCPU using the command words of the 8279.The I/O control section controls the flow of data to/from the 8279. The data buffers interfacethe external bus of the system with internal bus of 8279. The I/O section is enabled only if RD(Active Low) is low. The pins A0, RD (Active Low), WR (Active Low) select the command,status or data read/write operations carried out by the microprocessor with 8279.Timing control registers store the keyboard and display modes and other operating conditionsprogrammed by the processor. The registers are written with A0=1 and WR (Active Low) = 0.The timing and control unit controls the basic timings for the operation of the circuit.Scan counter divide down the operating frequency of 8279 to derive scan keyboard and scandisplay frequencies. The scan counter has two modes to scan the key matrix and refresh thedisplay. In the encoded mode, the counter provides a binary count that is to be externallydecoded to provide the scan lines for keyboard and display. In the decoded scan mode, thecounter internally decodes the least significant 2 bits and provides a decoded 1 out of 4 scan onSL0-SL3. The keyboard and the display both are in the same mode at a time.Another set of functional components is return buffers and keyboard debounce and control.These components scan for a key closure row wise. If it is detected, the keyboard debounce unitdebounces the key entry (i.e. wait for 10 ms). After the debounce period, if the key continues tobe detected the code of the key is directly transferred to the sensor RAM along with SHIFT andCONTROL key status.Another block present in 8279 is the FIFO sensor RAM and Status Logic. FIFO is used tohandle the quick pressings of the key. Each key code of the pressed key is entered in the order ofthe key, and in the meantime, read by the CPU, till the RAM becomes empty. The status logicgenerates an interrupt request after each FIFO read operation till the FIFO is empty. In scannedsensor matrix mode, this unit acts as the sensor RAM. Each row of the sensor RAM is loadedwith the status of the corresponding row of sensors in the matrix. If a sensor changes its state, theIRQ line goes high to interrupt the CPU.30
  31. 31. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.comThe display address registers hold the address of the word currently being written or read by theCPU to or from the display RAM. The contents of the registers are automatically updated by8279 to accept the next data entry by CPU. The 16-byte display RAM contains the 16-bytes ofdata to be displayed on the sixteen 7-segment displays in the encoded scan mode. ----------xxxxxxxxxxxxxxxx--------ACKNOWLEDGEMENTS : Thanks are due to Prof.K.Udaya Kumar ,Principal ,BNMCollege, Bangalore , a good friend and wellwisher who inspired me in microprocessor teachingduring early 90s.31
  32. 32. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com32
  33. 33. Dr.Y.Narasimha Murthy Ph.D yayavaram@yahoo.com33

×