Transcript for:
Microprocessor IO Interfacing Overview

So as I have informed during my last class is the last topic of this micro philosophy. It is I interpretation. So I have already told you two types of IO interpation. One is isolated IO or is called as IO mapped IO. I I have explained you the difference between IO mapped IO and one more time which is called as memory mapped IO right with an analogy I have explained during my last class. Hope if you are there if you remember what was covered in the last class you'll be knowing about it isolated IO or IO map I what is this in simple I can say your microprocessor and IO is directly contacted okay through a IO okay see what what is happening here is every microprocessor will have its address generated to locate the IO whichever IO is connected. Okay, see in isolated IO memory address space is different from IO address space. What is this? Memory address space is different to IO address space. I have explained you about this. Okay, during last class I have explained you your this is your microprocessor and these are all I devices. These are all IO devices. Okay, these are all IO devices. So there is a there is a IO read and I write you know you have a memory and IO bar. Yes or no? You have memory and IO ball right and you have a read signal and you have a right signal. Suppose if you give zero to this particular pin. Suppose if you give zero to this particular pin that means microprocessor your 8086 microprocessor is doing read and write operation to the IO provided to the IO. Okay, if this particular signal is one, then microp processor is giving read and write signal to memory. Right? Hope you're understanding this. Okay? See, you have this memory also connected to this microprocessor. IO also connected to microprocessor. Now, how do you differentiate reading and writing to memory and IO? This particular pin, right? If you give one to this pin, it is doing read and write operation through memory. If you give zero to this particular pin, it is going it is doing read and right operation to IO devices. Okay, that is the difference. Okay. Okay. So, signal used here as I told you it is IO read and I write. signal used here is IO read and I write see that's what I have told here see memory bar IO memory bar IO as I told you that when the signal is zero in this signal is zero in this okay it is actually selecting this IO devices when the signal is zero on this can you tell me whether memory is selected when the signal This I told you when the signal is zero on this. Okay, this is select bar, right? This is enabled. Can you tell me whether memory is enabled same time? Memory is not enabled, right? See this memory/ IO bar either will select memory or IO device. Whenever the signal on this is one, see here, whenever signal on this is one, it will tell me what it's supposed to be memory, right? Yes or no? And you have a not gate here. So one will become zero here. One will become zero here. That means what is selected? Memory is selected. Okay. Now whenever the signal is zero on this now what will happen to memory? Memory will not be selected. Instead of that what will be selected? IO is selected. Are you understood? Now the purpose of having memory splash IO bar this is what itself okay and in isolated IO we use this okay whenever we communicate to the whenever we communicate to the IO devices this is this is something direct connection to the IO device direct connection okay this is called IO map IO or isolated IO Okay, what exactly is this? Okay, hope you know why I'm telling this. This is IO interfacing. We're interfacing input output devices to microprocessor. And I'm telling you that there are two ways you establish interface. You establish connection. One is IO map or called as isolated IO. Right? Another type is called as memory map. It is through memory. I gave you an example also during my last class. Another one is memory mapped I mode. In memory mapped IO we don't use instruction body now. Right? What is this in and out instruction right? I try to understand very clearly in the previous case if you want to put any data to the IO device we used an instruction called as two instructions called as in and out. Okay try to understand very clearly about this. Okay see what is this in inout instruction. I just want to tell you. Okay, just try to understand this. This is your microprocessor. Okay, this is your 8086 microprocessor. Okay. And you all know that this has this has D15 to D0 data bus. And all of you know this has an address bus starting from A19 to A0 and it has got M by M / IO bar. It has got a read signal and it has got a right signal. This much is enough to represent your input output devices. Try to understand this. Okay. Now you have IO device here. Okay. I will consider this as an IO device and this IO device has got a select select pin. Okay. Select pin. And also this has got a read pin or this also this has got a right pin. Assume that this IO does both. read and write. Okay, this IO is something which does both read or write. Okay, if this IO is a temperature sensor, okay, then it is only trying to read the data. If this sensor is an LED, if this IO is an seven segment, it is microp processor is writing the data. Have you understood about it? Okay, consider this IO is capable of doing both read and write. underscore this. Now see here it also has it also has a data line. It requires data yes or no. This IO device is supposed to give data to microprocessor. That is microprocessor. Microprocessor is reading the data and also it accept data from the microprocessor. That means microp processor writes the data into this. Right? Microprocessor can read the data from IO device. Microprocessor can write the data into the IO devices. So for that you require data lines, right? No. Yes. Yes. So assume that you are actually giving 8 bit data. Assume that this IO device is capable of giving out and taking in okay 8 bit of data. Have you understood this? Okay. This is about now microp processor wants to write some data into books. Assume that microprocessor wants to data write a data into. Okay. What is the first step microprocessor does? microprocessor first identifies this IO device. Okay, how does it identify this this this particular device using address? Okay, you have something called address decoder here. Okay, you have something called address decoder here in between like you have address decoder for memory, right? For IO also you have a address decoder. It will make use of your address lines and entire address line and it will locate that IO device like it used to locate your memory. All of you know about it. Okay. Then what it does? Okay. First it will locate the IO device. Once IO device is located, if microprocessor wants to put data to the IO devices, it is using an instruction called as out instruction. Out instruction and this out instruction, this out instruction will give data from microprocessor to the IO device. That means whenever out instruction is generate executed by 806 microprocessor you can see that the data will be put on the lower order data lines here. Suppose if you are putting only 8 bit data you don't require higher order data lines right only lower order data line 8 bit data will be put into this IO device. We'll see the syntax of out instruction. In out instruction we are going to specify the address also. We are going to specify the address also. Which address this particular data is going? I understood this. Okay. So you have used the out instruction where already in the laboratory you have used the out instruction right. So what is the syntax of instruction? You remember the syntax of instruction? You done the right. You done h out vx comma 8 a. What is that? What is the dx? What is here? The syntax of out instruction is TR out. Since you are using 825, you are using 85 instruction. Otherwise, this is going to be your address. Add address of the port out address, what you going to put? Data, right? Data. The data can be in any register right? The data can be in any register of the microprocessor. So like it can be BL whatever. This instruction writes the data okay into the IO devices from where it writes from the microprocessor. Similarly, don't you think we need to have restriction like microp processor writes the data to the microprocessor can also read the data from my right? Yes or no? Yes or no? So, what is the instruction for you? Tell me. Come on. What is the instruction for reading the data from IO device? Come on. This is very bad. This is out instruction is to write the data into the IO device. What is the what is the instruction to read the data from device? H what is that instruction? Come on. You done it in the lab, right? Have you done any instruction in the lab? You're not done, right? You done only out. Can you guess what mean the instruction? If out is going if writing is out, what will be the instruction to read the data? Can you guess? Of course, it is going to be in instruction. That's all. Once again, here you'll have a port address, data and port address, right? Data and port address. That's all. Right? This also consist of your AL comma address. It is writing data into the AL register syntax exactly we see in the program. That means in IO mapped IO or we call it as isolated IO we use this in and out instruction in and out instruction. Right? This is the this is the this is the way it writes. I'll repeat once again how it how your microprocessor writes or read data into IO or from the IO what it does first it'll identify the IO device which IO device okay through address right it will generate an address once it identifies it it knows Now which address is that right? This address. Now it drives the data into the IO maybe from a register maybe from whatever registers you have. Okay. Through an instruction called as out instruction. At that time you can see the uh the lower order data lines of microprocessor will have the data which is to be returning to the IO device it will just write. Then similarly if microprocessor wants to read a data right you have an instruction called in anyway address is written in the instruction itself. Okay. And what is the data to where the data to be right right that will that will indicate it by register here. See once microprocessor wants to read the data from IO device where it is going to keep the data. Come on tell me it has to keep it in its own registers right? Okay. So that is what you are mentioning in this. So this method of exchanging the data between microprocessor and IO directly by locating address is called as IO map IO or or call it as isolated IO. Have you understood this now? Right. Okay. Now what is what is another method? What is another method? Another method is through memory. through memory here. Is there anywhere memory is involved here? Tell me nowhere memory is involved. I'm directly actually writing the data to the IO and I'm directly reading the data for the IO to the processor. I'm not going to involve any memory here. I don't want the memory in this type this type of method. Okay. Now, can I involve memory in this? Right. That is called as memory mapped IO. That is called as memory mapped IO. In this we are not going to use your instruction in and out. Right? We're not going to use the instruction in and out in this. We don't want why we don't want this instruction in and out here because we're not going to directly send the data to the memory to the sorry to the IO or we're not going to get the data directly from the IO. Now here what we do we don't use any IO I signal at all right we don't use any IO signal at all but instead of that we will use memory to contact the IO have understood this we'll use memory to contact the IO where your IO device and memory they have got married they are connected right they're connected Okay. So since they connected whatever data you put into the memory it will go to the unders. Okay. In memory map IO it works something like this. You have your microprocessor here. This is your 8086 microprocessor. This is your memory. This is your memory. Okay. And this is your IO device. Assume that this is your IO device. Okay. Which does both read and write. Now ultimately purpose is to put the data into IO get the data from IO. That's our microp processor wants to put the data into IO or it wants to take the data from IO. Okay. So instead of contacting directly using iOS see there are some memory locations in this some memory locations in this is reserved to get the data to put the data from IO and to get the data from IO I understood this so what it does if at all IO device wants to send the data to 806 first it will put it in the memory it'll put it in the memory whatever see this exchange is actually happening always whenever your IO device wants to send the data to microprocessor it need not give interrupt and interrupt the microp processor here it'll put it in the memory location it'll directly put in the memory location now what microp processor can do whenever microp processor wants to read the data of IO device microprocessor will not look directly into this but it look into the memory memory a particular memory location is reserved fixed for this IO address. So what microprocessor will do? Microp processor will generate that address and it will make use of memory read and memory write instead of IO read and IO write to get the data from the IO device. Hope you're understanding this right. This is called as memory mapped IO. There are two types of IO operations we have discussed now. One is IO mapped IO and the one is memory mapped IO. In memory mapped IO, we directly get the data from the memory. That's all. We don't use instruction. Have understood this right. Okay. So these two are different types of IO interfacing. Okay. Now you understood how to interface the data read and data write. to microprocessors. See this is what I have told you. It will directly okay it will direct you see this is the total memory total memory that memory some of the memory spaces are reserved for IO operation right what is the meaning of reserving this memory for IO operation tell me that means whatever memory location you have here this is having the data from IO devices whenever microp processor want the data from that IO device it will look into this memory this memory location I understood this Yes or no? Okay, let us go forward. So these are the these are the memory memory mapped memory plus IO mapping. So these are the memory divisions. Let us talk about now interfacing. How do we interface either switch or an LED to 8086 microprocessor? Okay. Now you see here what is this? Tell me now. What is this? Switch. This is a switch, right? Is it not a switch? The switch. Now can you tell me what happens to this A when the switch is closed? Just a small electrical sciences question to when the switch is close it'll be zero right why it is zero because it will be grounded right is zero it will give zero now when the switch is open it will give one right so this is this can be connected to one of the data like this or where D0 will be still zero and one I understood this right okay so this is simple switch and then we have I already told you about what is this tell me this is not the correct symbol for LED. So normally LED is you need to have a paros LED symbol is you will have a diode symbol and then you will have an arrow two that is the correct when the examination please don't do this mistake okay the class I'm telling you your diode symbol is this one what is the light emitting diode symbol there are two arrows symbols arrow symbols fine Remember this. Can you tell me what happens if I give zero in this? We we are working with only zeros and ones, right? In microp processor, we are working with only zero and right. So what happens if you give zero here whether LED will glow? No. Right? Because you have this this is this is P. You give zero here it is reverse bias. Right? Right. Okay. Now suppose if you give one here this is forward bias right your diode is forward bias because one is 5 vol now so this will be positive and this is in the lower voltage so this definitely this diode will be powered by us but this diode is powered by what will happen tell me this LED will glow come a little bit glow, right? Okay. So now, how do you give this? How do you make your microprocessor to make this LED on and off? Tell me, I want to make this LED on and off. Let us use IO map. What data I should give to make this LED on and off? Imagine that this is connected to D0 tell you h what what use you you say which instruction is supposed to be given executed for microprocessor to make this LED on and off. Is it reading the data or writing the data? Writing the data. Right. Which instruction is to write the data out? Out. Okay. Address. This address corresponding to this IO device. Can you tell me what data I should give? Okay. I will just put the data into AL register. What data I should give to make the LED on? Exactly. 01. Right. Okay. See you put 01 into a register and you just make you just execute an instruction out comma address a what happened now tell me so microp processor will put 01 into the D7 to D0 right where D is connected here so what happen to this LED it will glow how do you switch off the LED You want to put How do you switch off the LED? How do you switch off the LED? More A comma 0 H. Now once again execute out out address, A that's all right. We are not using memory mapped IO here but we are using IO mapped IO in this. Okay. So this is a a type of Okay. So I have told you about this. Now and in instructions I already told you about in instruction. What is the thin instruction? I told you. See in accumulator, port. What is this port? Port is nothing but your the port address of the IO device. The IO device address is called port address. Why it is called port address? Because normally your age microp processor data lines are not directly connected to IO. Listen to this. Okay. It is connected through a a another integrated circuit called as program interface which is called as 8255. Right? Remember this your microprocessor that your data lines are not directly connected to the IO device. It is connected through another device called as programmable peripheral interface which has multiple ports which can be programmed okay to have access through an address called as port address. Hope you remember when you are typing the program. Okay, I know you are blindly making cut and paste, copy and paste. Okay, in the first few lines you written port address, port A with port address, port B with port address, port C with port address. But you have one more control register. What is the purpose of that? That is where you program your 8255 that is programmable in Ps. Right? That's what this port address is. So in accumulator port address what it does whatever data copied this is in mean in means what in means microprocessor getting the data in getting the data from IO device. Whatever data read from the IO device, okay, with the device port address will be copied to accumulator. It can be either AL or AX. Can you tell me when we use AL and when we use AX? You answer any question by whenever you you are reading 8 bit data you use AL. Whenever you are reading 16 bit data, you use a exit. That's all. So for example, see in 00h okay in ax 20. Can you tell me what is this? It reads a data from an IO port from IO IO device IO port with address address 00. Okay. And puts it into the air register. That means it is reading 8 bit. Similarly, this reads a data from a IO device with port address 20 and it copies the 16 bit data into the this is what your instruction is. Okay. Now, can you tell me can you guess your address can be either 8 bit or 16 bit. Okay, I already told about this. So the port address appears on the address bus first during the IO operation. So 8 bit address is this one. It copies the data from the pole to the I already explained in this whatever is there in the slot on the slide I already explained in this. Okay. In instruction. Okay. This is also possible. See here this this is just a programming, right? See we are writing in. Okay. In AL comm, port address. This is a port address, right? Is the port address. If this port this this is normally 16 bit port address. Okay. You can put the port address in a DX register, right? Okay. And then here you can put in ala dx. Of course, we are using one more statement extra statement here. Maybe if your program requires that you can put this in the DX register and you can indicate here that means this DX register is having what? This is having address of the port. That's it's nothing no other significance. Okay fine. This is just this is just a programming. This is the way you can do the uh in instruction. Okay. Port address. Out instruction. Can you guess out instruction? In out instruction what comes here's port address first is the port address. Okay. In in instruction your port address comes next. Okay. In out instruction port address comes first is the port address. So can you tell me what this instruction do? Tell me it writes an 8 bit data into the IO device with a port address 0 5. Similarly this copies a 16 bit data from the microprocessor to the IO port with the address 0 ph. That's all. And this port address can be in DF register also. Okay, that option is there. Okay, I already told about in and out instruction. It can be out immediate port 8 address AL out immediate port address AX out immediate port address EX. Can you tell me what is this? E A X. This is for 32 bit. Okay. And similarly you can put the address in the DX registry understood this. Okay. This in out instructions are very very important for you. Okay. Now okay. So once again once again you can use even and addressing here. Can you tell me what's the purpose of using and addressing here? Tell me what is the purpose of using and addressing in memory interface. You get 16 bit data at a time, right? Don't you think that some of your IO devices are giving you 16 bit data? Yes or no? Right. In that case, you need to have these data read from the two addresses. Two addresses. That's why this even and odd addressing comes here. Right? See here your lower order bite lower order bite data either can be read or written using your addresses. Okay, like you have done it for memory interfacing. Similarly, your higher order data has to be read or written using odd addresses. So whenever you design an IO interfacing, if you want to read a 16 bit data, okay, your IO device, the data transfer has to be in such a way that it will give it will have two ports. It will have two addresses. It will have two addresses and it will give 16 bit data from the two. I understood this. Okay. Imagine this IO device is giving 16 bit data. Okay. Right. Okay. Eight. Imagine this is giving 8 bit data two times. Okay. This I device is having 8 bit. Okay. Since microprocessor is having see this is where you you address see this is your 886 microp processor okay and it has got 16 data lines if your one IO device if you are one IO device okay is giving you 16 bit data if this giving you 16 bit data can you tell me do you need even an order you don't require don't require We don't require evening. Okay, remember this because your IO also can handle 16 bit data and your edge access also can handle 16 bit. Now suppose you have two IO devices. This is 8 bit. This also 8 bit, right? And both the devices can simultaneously put the data into microprocessor. How it can do? How it can do? Come on, I wrote it down. You put this, you give even address for this, you give odd address for this. Right? I understood this. See, 8086 has the capability of reading 16 bit data. Right? Yes or no? It has a capability of system with data. Suppose if I have two IO devices separately sending 8 bit 8 bit, right? Why I should send these two data separately in two mission cycle? Why I should do it? Right? Instead of that, I can give an even address for this and I can connect I can connect D7 to D0. I can give odd address to this. I can connect D15 to D8. So I can read both the data from through D6 D15 to D0. Okay. Even from the given address from here or address from here that means this particular IO device will have address. This particular IO device will have odd address. So it will read a 16 bit data at a time from even and o address. I understood this. Okay. This is this is the way you can use even and all address to get the 16 bit data. Right? But remember if that 16 bit data coming from one device do you need your address? No. You can connect this directly D15 to D0 and D15 to D0 of the mic microprocessor. This is D15 to D0 of microp processor. So it can do a trans data transfer in one machine set. Right? Suppose you have two IMO devices. This is an 8 bit. This is also 8 bit. both can do the exchange of data to microp processor at a time provided you give even address to this and odd is very important to understand okay that's why this even and odd address interesting comes in a z IO interfacing also so how do you separate even and odd address how do you separate how to decode using a z using a z You all know each is always zero for units. Even is always one for all. Okay. So we will see remaining thing in the Monday's class. Okay. So try to revise this once again. I have recorded this lecture. I will sh