Timothy J. Weber wrote: > No, I haven't upgraded to 2008... "if it ain't broke" and there are no > new compelling features... There are two reasons why we're switching: 1. The lack of a good, flexible serial port library (Async Pro crashes on computers with dual cores -- have yet to confirm this conclusively, but evidence suggests our code is not the problem). 2. The ratio of precanned stuff available for C# vs Delphi, is now in favor of the former. >> Uart_Init(9600, 'N', 8, 1); > > I like that solution. Concise. It's settled then. Although I think I will also add a UART parameter, so it would look like this: Uart_Init(UART_1, 9600, 'N', 8, 1); Not so concise, but this makes it usable for projects that use two ports (or use UART_2 for debugging). > The other thing I tend to do is add a .h file with #defines for things > that are going to be constant throughout the program, like baud rate of > a UART, port and pins for button inputs, etc. This is checked into > Subversion as a file named like "uart-consts-template.h", which then > gets copied to "uart-consts.h" for any individual project and customized > from there. How about: io_defs.h: I/O pin definitions main.h: Project-specific constants (version of the program, crystal frequency, etc) As far as UART baud rate, I prefer to handle it thus: - Initializer object sets the baud rate. Then, - It's UART object's responsibility to know what its baud rate is, and - Any object can ask UART what its baud rate is I don't like globals. :) > On PICs, I still want things to be a bit more efficient than this. I > think I would be tempted to do something like: > > Uart1_PutStr("Hello on port 1"); > Uart2_PutStr("Hello on port 2"); > > and do > > #define Uart_PutStr Uart1_PutStr That's pretty much how Microchip does it in their UART libraries, they have as many copies of each function (one function per file) as there are UARTs: OpenUART1.c OpenUART2.c OpenUART3.c OpenUART4.c It's no doubt more efficient, but it violates one important software development principle: "one rule, one place". Copy-paste programming always gets me in trouble: I fix a bug in one function, but forget to carry over the changes to the other functions. > This also illustrates why much of this is best done as the need arises, > and why huge libraries that do everything for everyone come with a cost: > My own UART routines are quite simple, because I've only ever used > 9600/N/8/1 and only chips with a single UART. I try to follow the YAGNI (Ya Aint Gonna Need It) principe, it saves me loads of time. Often I would define the interface, but won't actually implement the underlying functionality until I need it. For example, this is approximately how I defined the SetBaudRate() function initially: Uart_SetBaudRate(int baudRate) { switch (baudRate) { case 9600: BRGH = 1; U1BRG = 0x0123; break; } } >> Do you mostly work with the 8-bit controllers? > > 16F and 18F, yup. I believe this is a major factor influencing how you and I view programming on PICs. 16- and 32-bit PICs give one the luxury to trade performance for code that's more human-friendly. >>> and partly because of my preference for >>> English-like syntax. >> >> In programming, Yoda-like syntax make better sense may sometimes... > > If you.CanThinkIn(thatStyle) { it.MakesSense(often); }. :) My first language is Russian, where you can scramble the words in the following sentence in any way you want (you get 24 variations total): Mary wore a red hat. ..and they would still make sense, and be grammatically correct. So all of these are perfectly valid: Mary red hat wore. Hat red Mary wore. Wore hat Mary red. What's perhaps even more frightening, is that all 24 variations mean the same thing as the original. And it doesn't matter which particular nouns, verb, and adjective you select, as long as the original sentence makes sense. I've never watched Star Wars in Russian, so I wonder what tricks they use to simulate Yodish grammar. :) Vitaliy -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist