S Suraj143 Active Member Dec 3, 2011 #1 I have a variable called temp1.I need to check its bits individually. The below code works for SFR. Code: if(PORTB.B0==1){.....} But it won't work for GP registers.It gives an error "Operator '.' is not applicable to these operands 'temp1'" Code: if(temp1.B0==1){.....} Last edited: Dec 3, 2011
I have a variable called temp1.I need to check its bits individually. The below code works for SFR. Code: if(PORTB.B0==1){.....} But it won't work for GP registers.It gives an error "Operator '.' is not applicable to these operands 'temp1'" Code: if(temp1.B0==1){.....}
3v0 Coop Build Coordinator Forum Supporter Dec 3, 2011 #2 The generic way to check a bit is with a bitwise and. Code: if(temp1&0x01){.....} or in binary if(temp1&0b00000001){.....} Some embedded c compilers will let you do a struct with bit fields. The definitions in the C18 processor header files are an example of that. Code: extern near struct { unsigned C:1; unsigned DC:1; unsigned Z:1; unsigned OV:1; unsigned N:1; } STATUSbits; But I if you stick with the method above it will work on all c compilers. Last edited: Dec 3, 2011
The generic way to check a bit is with a bitwise and. Code: if(temp1&0x01){.....} or in binary if(temp1&0b00000001){.....} Some embedded c compilers will let you do a struct with bit fields. The definitions in the C18 processor header files are an example of that. Code: extern near struct { unsigned C:1; unsigned DC:1; unsigned Z:1; unsigned OV:1; unsigned N:1; } STATUSbits; But I if you stick with the method above it will work on all c compilers.