Truncated match.
PICList
Thread
'bit wise logic functions'
1999\02\09@170408
by
David Wong
Does the Hi-tech C compiler not handle bit wise logic function.
I tried compiling the following lines
if (T0IE && T0IF) - this compiles fine
and
if (T0IE & T0IF) -this doesn't but it should being
that both are just bits
thanks
DW
1999\02\10@042746
by
paulb
David Wong wrote:
> I tried compiling the following lines
> if (T0IE & T0IF) -this doesn't but it should being
> that both are just bits
Hey! TOIE and TOIF are different bits, are they not? If you AND
different bits, you always get zero.
--
Cheers,
Paul B.
1999\02\10@072347
by
Caisson
> Van: David Wong <spam_OUTDavidTakeThisOuT
SWIFTCEC.COM>
> Aan: .....PICLISTKILLspam
@spam@MITVMA.MIT.EDU
> Onderwerp: bit wise logic functions
> Datum: dinsdag 9 februari 1999 22:47
Hello David,
> Does the Hi-tech C compiler not handle bit wise logic function.
>
> I tried compiling the following lines
>
> if (T0IE && T0IF) - this compiles fine
This is a Bit-wise AND.
> and
>
> if (T0IE & T0IF) -this doesn't but it should being
> that both are just bits
This is a Logical AND. Could it be that T0IE is a _index_ into a register
specifying a bit. In other words T0IE could be the number (lets say) 5 to
tell you that the sixt bit from the right in the T0 file-register has got
the IE value ? Try it out : movlw T0IE. If your compiler is
none-too-smart it will load W with the Index-value of T0IE.
Greetz,
Rudy Wieser
1999\02\10@092834
by
Dave Johnson
>> if (T0IE && T0IF) - this compiles fine
>This is a Bit-wise AND.
>> if (T0IE & T0IF) -this doesn't but it should being
>This is a Logical AND.
Whoah, I think you got those backwards. The first is a logical AND, the
second is a bitwise AND. (I'd be awfully surprised if this particular C
compiler decided to reverse the meaning of those two operators.)
I've never tried to program a PIC in C, so this is just a wild guess, but
maybe the problem is that you're trying to do a bitwise AND on individual
bits, rather than on bytes? A bitwise AND on two separate bits makes no
sense, really...
Dave Johnson
1999\02\10@102057
by
Stefan Sczekalla-Waldschmidt
Hi,
Dave Johnson wrote:
>
> I've never tried to program a PIC in C, so this is just a wild guess, but
> maybe the problem is that you're trying to do a bitwise AND on individual
> bits, rather than on bytes? A bitwise AND on two separate bits makes no
> sense, really...
>
> Dave Johnson
IMHO it does.
A & B = C
0 0 0
0 1 0
1 0 0
1 1 1
But I think tho problem is, that in this case is that T0IE is EQU to a
certain
value ( nothing to look up at the moment ) and T0IF to a different EQU
so waht he is doing is e.g. "6 & 7" ...
I think what he need to do is:
if (bit_test ( INTCON, T0IF) & bit_test (INTCON, T0IE))
do something;
Kind regards
Stefan
1999\02\10@105136
by
Dave Johnson
|
>> maybe the problem is that you're trying to do a bitwise AND on individual
>> bits, rather than on bytes? A bitwise AND on two separate bits makes no
>> sense, really...
>IMHO it does.
>
> A & B = C
> 0 0 0
> 0 1 0
> 1 0 0
> 1 1 1
That's the truth table for a logical AND, not a bitwise one. Actually,
in this case (comparing two individual bits) maybe bitwise reduces to the
same thing as logical?
But typically you use bitwise AND to compare several individual bits
simultaneously, and their positions in the byte are important, for
instance:
A & B = C
00001111 01010101 00000101
This is just like the PIC AND instructions. I'd think that the compiler
would want to make a bitwise AND in C compile to a single PIC
instruction, since it can. But if you give the compiler two separate bits
in the same byte (like these flag bits in the intcon register), it can't
do that.
But in any case, if he's comparing two discrete values to see if they're
both "set", then conceptually he's doing a logical AND, and IMHO he
should use the logical AND operator (&&) to do it. If nothing else, it'll
make for easier reading 6 months from now when he's trying to figure out
what he did :-)
Dave Johnson
1999\02\11@074233
by
Caisson
> Van: Dave Johnson <djohnson
KILLspamSIRIUS.COM>
> Aan: .....PICLISTKILLspam
.....MITVMA.MIT.EDU
Hello Dave,
> Onderwerp: Re: bit wise logic functions
> Datum: woensdag 10 februari 1999 15:26
>
> >> if (T0IE && T0IF) - this compiles fine
> >This is a Bit-wise AND.
> >> if (T0IE & T0IF) -this doesn't but it should
being
> >This is a Logical AND.
> Whoah, I think you got those backwards. The first is a logical AND, the
> second is a bitwise AND. (I'd be awfully surprised if this particular C
> compiler decided to reverse the meaning of those two operators.)
You are quite right. And I _did_ look it up in the book first :-( What I
tried to tell (but was non too clear about) was that T0IE is not a Bit, bit
a _index_ to a bit. The compiler tries to do a _Compile-time_ and. So it
can never work with the bits they (T0IE, T0IF) are _referring_ too ...
Greetz,
Rudy Wieser
More... (looser matching)
- Last day of these posts
- In 1999
, 2000 only
- Today
- New search...