Grant Brown wrote: > I have a I/O expander that is I2C based that controls some chip select > pins for a SPI network > > I also have a function that sends out I2C commands > > void SendI2C(unsigned char AdresStr, CmdStr); > > in calling that function is it more efficient etc to define the CmdStr > or should I create them on the fly. > > ie > > _Method 1_ > > #define CS_SR14_on 0x01; // | 0000 0001 > #define CS_SR14_of 0xFE; // & 1111 1110 > > or > > _Method 2_ > > unsigned char SetCmdStr (unsigned char CmdType); > { > Switch (CmdType) > { > case 1: > CmdStr = 0x01; > Break; > case 2 : > CmdStr = 0xFE; > Break; > etc etc > > Method 1 takes up lots of program room however Method 2 takes up clock > cycles You need to show how you want to use them. As it is, method 1 is oranges and method 2 is apples -- that is, they are not in the same realm and can't really be compared against each other. FWIW, the #defines in method 1 take up nothing in the processor, because these #defines are only visible to the compiler. How this will look in the processor depends on how you use these defines. Also, FWIW, I'd say that you definitely should use method 1, even if you should decide to use method 2. As I said, they are not competing and can be used together. > I can see Method 1 being much better for debugging etc and if I was > writing a Win32 app These days one rarely writes a Win32 app in C. And even if you did that and used method 1, I'd give you another chance, and if you did it again, I'd probably fire you :) Seriously, in a Windows program you should use constants, enums or similar in such a case and not preprocessor defines. Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist