On Mon, 2009-05-25 at 11:26 -0700, Vitaliy wrote: > So where do you specify the project specific attributes, for instance the > baud rate for UART, or the resolution for ADC? > > Specifying these attributes inside the module that uses them, effectively > precludes code reuse. You have to make a copy of the UART module, just so > you can specify a different baud rate. Since the file is now different, it > will quickly get out of synch with the other copies, because any other > changes you decide to make, won't propagate. > > It makes sense to isolate the stuff that changes (e.g., configurable > attributes) and put it in one file that contains project-specific code. Then > the UART module can be used without any modifications, in a project that > uses it at 9600 baud and a second project that runs it at 115k baud. Exactly. For example, many of my projects have had "print string" type functions. I've been able to reuse all this code because none of it is specific to any piece of hardware. All the routines end up calling just one function: putChar. putChar is the only function I need to change when moving from platform to plaform. Obviously there is an associated initPutChar type routine that handles where putChar outputs it's stuff. So when I want to change UARTs it's just a matter of changing a define in initPutChar. If I want to output through say a USB port I just bring in a different initPutChar. LCD? initPutChar and putChar get a little more complicated, but not much. The point is none of the code that calls putChar needs to be changed. Moving to a PC? Even easier since then I've got an OS that does most of what initPutChar does. TTYL -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist