??? 06/18/06 04:56 Read: times Msg Score: +2 +2 Good Answer/Helpful |
#118486 - input/output Responding to: ???'s previous message |
Hi Munaza,
I am guessing that you are thinking of the port of the µ-controller as if it were the port of a digital i/o card. Stop thinking of it like that. Instead, think of the port as a register associated with a data bus. Each bit in the register is tied to one line of the bus. Now, if anything tied to the bus pulls one of the lines low, that line will cause anything that "reads" the bus to read that bit as a 0. And if the µ-controller reads the port register tied to that bus, it too will read that bit as a 0. Of course, if you put a 0 in any of the bits in that register, then you will still read that bit as a 0. This is why you want to load 0xFF into port 0 anytime you aren't actively writing something to the data bus. This is not the same as pulling all of the lines high. Instead you are allowing them to go high, as long as nothing else on the data bus is pulling any of them low. If you're familiar with tri-state devices, think of writing a 1 to one of the port bits as putting that bit in the Hi-Z state. So, it really isn't like working with a digital i/o card. You don't have to program the µ-controller ports as input or output. If you MOV A, P0, then you read the data bus and used P0 as input. If you MOV P0, A, then you wrote something to the data bus and used P0 as an output. Some might tell you to think of loading 0xFF to P0 as "putting P0 in the input mode." Don't think of it this way. If you do, it will only be a matter of time before you're trying to figure out why something else on the bus isn't working when the only problem is that you never put the port back into "INPUT" mode since you had no plans to read anything. Instead, think of putting the bus back into HI-Z mode after your finished writing to it. And just stop thinking about putting it in either INPUT or OUTPUT modes at all. Good luck, Joe |