PDA

View Full Version : Accessing Portion of Input Port



Frozen001
- 24th October 2008, 15:30
I have PortA on an 18F8722 defined as an input port , and I want to read 3 of these pins at once. Say I want to read 0,3,5 and use the input in an IF statement is this possible?

The Master
- 24th October 2008, 15:37
You can check for a state on all 3 pins with one if statement if thats what you mean



if porta.0=1 and porta.3=1 and porta.5=0 then

endif


In that example 0 and 3 must be high and 5 must be low to execute the code in the if statement

Frozen001
- 24th October 2008, 15:46
I know I can do it that way I was just looking to do it with out the and satements... so I can say something like:


IF PortA135 = $6h then

endif

skimask
- 24th October 2008, 15:49
I know I can do it that way I was just looking to do it with out the and satements... so I can say something like:

IF PortA135 = $6h then
endif

IF ( PortA AND %00101001 ) = $29 (in this case all bits must be logic high) THEN whatever

Or are you talking about pulling out PortA. bits 1, 3, and 5 (or whatever) and putting them in temp. bits 0,1,2 ???

The Master
- 24th October 2008, 15:52
That is also possible. You can use the bit AND operator (&).



if (porta & %00010101)=%00010101 then


The purpose of (porta & %00010101) is to strip out the unwanted information. Only the bit where you see a 1 will be kept from porta. Then you compare that with the value you are looking for

Edit: Looks like skimask got there before me!

skimask
- 24th October 2008, 16:02
Edit: Looks like skimask got there before me!
MMMMWWWWAAAAHAAAAAA!!!!!!
(don't know if you guys do much for Halloween over there or not...but there it is :) )

The Master
- 24th October 2008, 16:08
(don't know if you guys do much for Halloween over there or not...but there it is :) )

Have you seen half my threads?!?! I dont think many people celebrate it here but i sure do:D Its my fave time of the year

mackrackit
- 24th October 2008, 16:16
I do a little morphing this time of year too.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2931&stc=1&d=1224861188">

The Master
- 24th October 2008, 16:18
Is that going to be your new avatar for next week?

Thinking about it, i should get an avatar for halloween!

mackrackit
- 24th October 2008, 16:20
Is that going to be your new avatar for next week?

Thinking about it, i should get an avatar for halloween!

I can not figure out how to up load an animated avatar. But that is what I was thinking.

The Master
- 24th October 2008, 16:33
Your limited to 19.5K so that one is too big. Im sure someone here has an animated avatar already