Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/01/05 20:16
Read: times


 
#94205 - Right answer, wrong reason
Responding to: ???'s previous message
Vignesh Prasad said:
After a day of trying out all the combinations, I came to know what was the mistake I was doing.

In the loop, I have given like this:
       while(P0^7==x);
But when i used something like this:
       sbit my_bit=0x87;

       while(my_bit==x);
This one is working. Nevertheless, I have found out where I had made the mistake. I think P0^7 is not defined as a sbit in reg51.h. Only P0 is defined as sfr P0=0x80. When I explicitly define my_bit and use, things are working fine.

You are very nearly there!

The trouble is with the '^' operator:

  • In standard 'C', it is the bitwise exclusive-OR operator - you can read about this in any standard 'C' textbook.
    P0^7 is the bitwise exclusive of the value read from P0 with the byte value seven.
    This also applies to Keil C51.

  • Keil C51 also uses it in sbit definitions.
    In Keil C51, sbit P0_7 = P0^7; defines P0_7 as a single-bit variable to acces bit-7 of P0.
    http://www.keil.com/support/m...ittype.htm
    This applies to Keil C51 only, and only when used in and sbit definition - when used in any other expression, the '^' operator has its standard 'C' function of bitwise exclusive-OR.

    We can only stand and wonder what on earth posessed Keil to do something so obviously bound to cause confusion... :-(

    Yes, it caught me out the first time!

    Note that, in Keil C51,
        sbit my_bit=0x87;
    and
        sbit my_bit=P0^7;
    are equivalent (given a suitable sfr definition for P0, of course).



  • List of 22 messages in thread
    TopicAuthorDate
    Keil: getting input            01/01/70 00:00      
       If it works in ASM it Works in C            01/01/70 00:00      
          Why C?!            01/01/70 00:00      
             Irrelevant            01/01/70 00:00      
             Of Course            01/01/70 00:00      
       key scan            01/01/70 00:00      
          Delay..            01/01/70 00:00      
             Delay            01/01/70 00:00      
             Software Delay Loops            01/01/70 00:00      
                Software Delay Loops            01/01/70 00:00      
       Learning 'C'            01/01/70 00:00      
       to be precise..            01/01/70 00:00      
          Debounce            01/01/70 00:00      
             completely missed it..            01/01/70 00:00      
          to be precise...            01/01/70 00:00      
             Sorry Leo !            01/01/70 00:00      
             Inferences            01/01/70 00:00      
                Right answer, wrong reason            01/01/70 00:00      
                   and therefore            01/01/70 00:00      
                Congratulations            01/01/70 00:00      
                   to: Raghu Sir            01/01/70 00:00      
          BIts!            01/01/70 00:00      

    Back to Subject List