How to check whether a byte of 8 bits contains 1, assembler 8051?

I need to know how to check whether a byte contains a 1 for touch status in a MPR121 project, so if:
00000010 then pin 2 is touched
00000100 then 3 is touched, how can i know it?
A set bit means that a pin is touched it doesnt matter whether there are more 1s, I just want to know if there is any 1, because that means that a pin is touched not caring which is that particular pin

I tried
R1-byte container

CJNE R1,#0, hasone
hasone:
....


But I don’t know if this works since is comparing a hex with a number, I can do it comparing with every single solution but I don’t like the approach. If anyone can help. Thank you!

• Do you need to know which bit is 1 or just that any is 1? – Eugene Sh. Mar 18 at 18:18
• What result do you want in case more than one of the bits is 1? – The Photon Mar 18 at 18:26
• Also, you might want to review the JZ and JNZ instructions. – The Photon Mar 18 at 18:35
• This risks being closed as unclear what you are asking. If the register has any bits set to one the value the register will contain anything other than 0x00. If you want to know if bit zero is set then if ((R0 & 0x01) != 0) it is, for bit 2 if ((R0 & 0x02) != 0) it is, for bit 3 if ((R0 & 0x04) != 0) etc. – Warren Hill Mar 18 at 18:36
• @ÇlirimMurati, then you're back to looking at the JZ or JNZ instruction. – The Photon Mar 18 at 20:15

If the byte is NOT 00000000, then at least one bit is non-zero. All you need to know is it is 00000000 or not.

To avoid all those if statements, you could use an 8 bit lookup table. The code will execute much faster than performing all the if-then-else statements. For the values you've indicated, 0x01, 0x02, etc the table below returns the number of the button pressed. But there are a lot of 0xUU in the table. 0xUU means that the value has not been defined by you yet, as the comments have indicated. You must decide what you want to return for those values and then update your lookup table. You might set them to 0xFF, for example, if you wanted to detect an error.

 char lookup[] = {
0x00, 0x01, 0x02, 0xUU, 0x03, 0xUU, 0xUU, 0xUU,
0x04, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0x05, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0x06, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 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0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU,
0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU, 0xUU
}
char result = lookup[R1];

• I mentioned it has to be assembler 8051 – Çlirim Murati Mar 18 at 20:03
• This isn't really a free consulting service, you might have to do some work yourself. – Cristobol Polychronopolis Mar 18 at 20:10