On 30/06/07, Peter P. wrote: > #include > #include > #include > #include > > volatile int errors = 0; > volatile int keycode = 0; > > void Rs232txd { > CRITA > if((rs232->status & RS232_TXEMPTY) && keycode) { > rs232->txd = keycode; > keycode = 0; > } > CRITZ > } > > void ButtonsToSerial(void) { > CRITA > if(keycode) { // overrun > errors |= TXD_OVERRUN; // NOT throw(), oops > CRITZ // !!! > return; > } > keycode = kbd->keycode; > kbd->status & ~KEY_DOWN; > CRITZ > Rs232txd; > } > > int main() { > timer_init(); > rs232_init(); > kbd_init(); > > timer_setup(0, TICKS); // needed by kbd for debouncing > > rs232->speed = RS232_SPEED; > rs232->txcallback = Rs232txd; > rs232_poll(); > > kbd->debounce = DEBOUNCE_CONSTANT; > kbd->callback = ButtonsToSerial; > kbd_poll(); > > idle: > goto idle; > } > > Yes, I know that you described an event driven model and I a timer driven aided > one, but this illustrates just a little bit of what you need to implement to > make your 'beautiful' main() work (20-50 more lines of code missing, to do the > timer interrupts, the keyboard, and the serial and baud generator init). You or > someone who implements it (the libraries) for you. Which is most likely heavily unportable since you use constants and the internal structure of these modules in your main code, you use a goto at the end where you should've just used while(1); or for(;;); which have the same effect but don't include a goto in the code and your drivers seem to be unable to handle more than one given device, which would be a problem on the aforementioned LPC2101 which has two UARTs. These kinds of problems are exactly why I would not want to use C as it inspires and practically promotes this kind of structures. > Anyway the main() is about as terse as yours. It's about 4x as long, a lot more involved with the drivers in question and requires a lot more care from the writer to not forget initializing a module before use or to initialize all modules before use just to be done with it. > And isn't it dercandy ? Probably. The actual nickname would be Candy but gmail requires at least 6 characters. Not to mention that Candy is usually taken. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist