Keil Logo

GENERAL: ACCESSING MANY PORT BITS WITH THE SAME CODE

QUESTION

I need to simulate I2C interface on 3 sets of Port 1 pins in a single implementation. The code for doing this is exactly the same for each port bit except that it has to operate on different SBIT's.

Since pointer's are out of question (because post bits cannot be indirectly referenced) are there any other tricks I can use for optimizing my code so that I have only 1 set of I2C routines? I prefer not to use if or switch statements. I would prefer something in C.

ANSWER

You may want to consider creating separate small functions to handle read and write operations for each port bit. Then, pass function pointers to your I2C routines. This should let you maintain 1 set of I2C routines but have 3 sets of xmit and recv routines (1 for each port bit).

Other than that, you may have to consider the switch/case solution (which really wouldn't be that bad on the 8051).

Last Reviewed: Monday, June 7, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.