--- Andrew Warren wrote: > > Anthony: > > A few things... > > 1. #define isn't the correct way to declare your > volume[][] array. > Got it. > 2. In C, array subscripts start at 0... So if > you've declared an > array of size 2 (e.g., "int array[2];"), it > contains elements > array[0] and array[1]; there's no array[2]. > Right, I forgot about that. > 3. This is scary: > > for (k = 7; k >= 0; k--) > > If k is unsigned, it's by definition ALWAYS > greater than or > equal to 0... The loop will never terminate. > I didn't define k anywhere, should this be done, or will the compiler take care of that? I guess it's better to put it explicitly in the code, right? > 4. An easier, faster, more code-efficient way to do > your bit- > shifting is: > > unsigned char k, temp; > > .... > > temp = volume[i][j]; > for (k = 0b10000000; k != 0; k = k >> 1) > { > pga_latch = pga_latch & 0b11111110; > > if (temp & k) > { > pga_latch = pga_latch | 0b00000001; > } > } > > .... > > This puts the array lookup outside the loop so > you only do it > once per byte, and it reduces the number of > shifts per byte from > 28 to 8. It also gets rid of the "else" by > always pulling SDI > low, then pulling it high when appropriate; it > didn't look as > though that'd be a problem. Thanks! I don't think pulling SDI low every time will be a problem either, since it's set on the PGA2310 every rising edge of SCLK. > 5. Does your C compiler support bit-wide variables? > If so, it'd > make your code more readable and less > error-prone, since you > could simply write "SDI = 0" or whatever, > instead of the > complicated logical operations. If not, "set" > and "clear" > macros would do almost as well. I had something like that first, but that seemed too simple. I'm using the High-Tech PICC18 demo, but I can't seem to get it to work. I might also try the Microchip C18 compiler demo. I guess they support 1 bit wide vars? Thanks, Anthony ===== Website: http://members.lycos.nl/anthonyvh __________________________________ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.