-
Reading Inputs
I would appreciate some help/advice with what seems a very simple problem, however I am just starting out in this branch of the hobby and I’m a raw beginner with buckets to learn!
I wish to read the lower 5 bits of my PIC (16F628) which are connected to 5 simple (0 or 1) sensors and then deliver a conditional result to a PORTA pin with IF…THEN statements. As an example IF PORTB = %11100100 THEN etc etc. This seems OK but I would like to remove the upper 3 bits as they are not required. I can hold these three pins high, for example, so they are always a 1 but it would be nice to ‘isolate’ them out of the logic. Is there a way of doing this, please? I hope that’s clear but effectively I would like to end up with a statement which simply says, for example IF PORTB (or MyVar) = 00100 THEN etc etc
How to do this, please
Many thanks
Adrian
-
Welcome
What you want is to mask the top three bits
Code:
MyVar=PORTB & %00011111
IF MyVar = %00000100 THEN
EDIT: See section 4.17.4 of the manual
-
yup,
for reference about bit masking you could have a look at those
http://en.wikipedia.org/wiki/Bitwise_operation
http://en.wikipedia.org/wiki/Mask_(computing)
Welcome here, and enjoy!
-
Reading inputs
Thank you both for excellent information. Lots to learn but absorption rate very high at present!!!
Adrian