|ARM Technical Support Knowledge Articles|
Applies to: General Topics
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.
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).
Article last edited on: 2004-06-07 08:25:40
Did you find this article helpful? Yes No
How can we improve this article?