Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Bitwise check - please help with this task

Status
Not open for further replies.

kotsam

Member level 1
Joined
Nov 16, 2005
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
Bitwise check

Hey Guys

i have problem and i hope that someone can help for solving it ,

the problem is that i need to compare the pic input with char (8bytes) lets say that i have RB1,RB2,RB3 confguired as input; how can i compare the status of them with char first three bits , i thought about shift but the problem how can i combine RB1,RB2,RB3 in the char and compare them; i hope tha explained my self clearly but if not imagine that you have dip switch connect it to the pic and you need to compare results with internal char .

thanks
 

Re: Bitwise check

Hi,
It looks simple, you AND Rb register and the Character with Mask 0x0E and XOR the results. In case you want to compare each bit separately use separate masks of 0x02,0x04 and 0x08 in each case.

Regards,
Laktronics
 

Re: Bitwise check

Hi

thanks for the quick reply i know its so simple , but RB i can't combine all of it , cuz part for the RB port is input and part is output thats the point , if i combine RB i would effect the outputs status at RB port.

Thanks
 

Re: Bitwise check

Just remember that the XOR will set the bits to 1 that are not the same. I would and the inputs with the char and then and with 0x0e. The result will be a 1 for a bit where the char and input are the same and a 0 where they differ. Take note I have never used a PIC so this assumes that when you read input bits you get a 1 when the pin is hi and a 0 when the pin is low.

Added after 7 minutes:

kotsam said:
Hi

thanks for the quick reply i know its so simple , but RB i can't combine all of it , cuz part for the RB port is input and part is output thats the point , if i combine RB i would effect the outputs status at RB port.

Thanks

Why? You are only reading from the port. The and 0x0f mask off the other bits. For example if you io bits = 11001011 . You say you are only interested in bits 1 to 3 their value is 101 in this example. You want to compare with char, so if your char = xxxx011x (x = dont care) then you do the following: value = char and input and 0x0e; this = 11001011 and xxx011x and 00001110 (0x0e) the result in value will be
00000010.
 

Re: Bitwise check

Hi,

Just remember that the XOR will set the bits to 1 that are not the same

Yes, that is what is required. After Xoring, you check for the Zero flag and if set, the bits have compared.

Regards,
Laktronics
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top