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 04:30
Read: times


 
#109897 - question on keil C sbit access
Hello,

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
}

I can then add any number of keys in .h file without touching .c file. The program works but programming style is not satisfactory. Can it be more elegant?


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