Em 22/7/2010 12:00, Matt Rhys-Roberts escreveu: > Please can someone faimilar with C kindly help clear up my confusion here? > > I'm declaring a couple of SPI function prototypes, see below. Not = > wishing to waste too much time testing awkward things, shouldn't the = > common variables (sync_mode, bus_mode etc.) be specified more uniquely = > for each SPI channel? Will the following, although it compiles ok, cause = > ambiguity when it comes to execution? I can't tell whether prototyping a = > function is the same as declaring a variable by name, nor how it's = > allocating the names following "unsigned char". > > Many thanks, > Matt > > > > void OpenSPI1 > ( > unsigned char sync_mode, > unsigned char bus_mode, > unsigned char smp_phase > ); > unsigned char WriteSPI1(unsigned char data_out ); > > void OpenSPI2 > ( > unsigned char sync_mode, > unsigned char bus_mode, > unsigned char smp_phase > ); > unsigned char WriteSPI2(unsigned char data_out ); > > void Open1USART > ( > unsigned char config, > unsigned int spbrg > ); Why don't you pass the port as an argument to the functions? Instead of duplicating a lot of code, just duplicate and select between the code that access the hardware? Or you could do as in desktop systems, OpenSPI takes the port number and returns a handle which must be passed to the other functions or -1 if it fails? This way you could share the SPI ports between threads (if you are using a RTOS). I do it this way in my designs, for SPI, USART, etc. Isaac __________________________________________________ Fale com seus amigos de gra=E7a com o novo Yahoo! Messenger = http://br.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist