Newbie question on reading port staus
I am sure this is real simple:
OK, so I have inputs on PortB.0 through PortB.7.
How can I read the status of this as a whole?
For example if PortB.0, PortB.1 and PortB.3 are all HIGH then I want to retun the digit "11"....and so forth from 0-127.
Thanks!
Re: Newbie question on reading port staus
Hi,
Just read the Port register:
That's it.
/Henrik.
EDIT: Make sure to check and setup stuff like ADCON, CMCON for any pins you're going to use.
Re: Newbie question on reading port staus
Ah, if only all things in life were this easy!
Thanks!!!
Re: Newbie question on reading port staus
Now, how do I get the value of the Port if the port is less than 8 bits?
Thanks!
Re: Newbie question on reading port staus
Exactly the same way as before.
On a 16F877, for example, PortA is 6bits. Reading it will return a byte with the state of the port pins in the lower 6 bits, the two high bits will always read zero.
PortE on the 16F877 is only 3bits. Reading it will return a byte with the state of the port pins in the lower 3 bits, the upper 5 bits will always read zero.
If you look at the register summary in the datasheet for the 16F877 (or whatever device you're actually using) it's all pretty clear.
/Henrik.
Re: Newbie question on reading port staus
Yes, that makes good sense. But what if I only use say 4 bits of the PortA port in my code and make the other PortA bits as outputs? Would reading the port give me the correct result?
:-)
Re: Newbie question on reading port staus
it will also return the state of the output. Nothing hard to solve through a bitwise operation or simply by breading the bits you need.
Re: Newbie question on reading port staus