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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/14/06 07:24
Read: times


 
#109913 - What are you trying to do?
Responding to: ???'s previous message
David Tong said:
I defined in .h file:
sbit key0 = P1^1;
sbit key1 = P1^2;
//more keys here as needed
#define MaxKey  N  // number of keys used
and have a function in .c file:
unsigned char keyState(keyID)
 {
 switch(keyID) {
  case 0:
   return key0;
   break;
  #if MaxKey>1
  case 1:
   retrun key1;
   break;
  #endif
  // for each key, enclose case statement in #if
  #if MaxKey>N
  case N:
   return keyN;
   break;
  } // end switch
}

The program works but programming style is not satisfactory. Can it be more elegant?

I don't think it's a matter of style - the whole approach seems bizarre!
What is keyID?
When you define an sbit in Keil C51, you are effectively defining an address - why do you want your function to return an sbit address as a char?!

Please explain what you are actually trying to achieve!

List of 12 messages in thread
TopicAuthorDate
question on keil C sbit access            01/01/70 00:00      
   What are you trying to do?            01/01/70 00:00      
      Try or doing            01/01/70 00:00      
         sbit access            01/01/70 00:00      
            The 8051 does not have indirect bits            01/01/70 00:00      
            send me keilc code for keypad            01/01/70 00:00      
               Yes sir! Right away sir!            01/01/70 00:00      
                  How about Fries?            01/01/70 00:00      
   please tell more            01/01/70 00:00      
   Buttons library            01/01/70 00:00      
      how to post code            01/01/70 00:00      
      The main question            01/01/70 00:00      

Back to Subject List