On Thu, Mar 5, 2009 at 05:47, solarwind wrote: > Can someone please tell me if I am doing this correctly? My code his here: > http://pastebin.com/f244a02f3 Looks okay to me, even if the code is not complete. Here's another example that I wrote for testing a digital potentiometer using SPI. Perhaps you can steal some of it: __CONFIG(UNPROTECT & LVPDIS & BORDIS & MCLREN & WDTDIS & PWRTDIS & INTIO); void delay() { int delayer = 10; while (delayer != 0) { delayer -= 1; } return; } void spi_write(unsigned char data) { unsigned char i, j; for (i = 1; i < 9; i++) { RB2 = 0; j = 1 << (8-i); // MSB first if (data & j) RB2 = 1; // If data, pulse data line RB1 = 1; // Pulse clock RB1 = 0; } } void main() { unsigned char resistance = 0, op = 0; OPTION = 0; VRCON = 0; EECON1 = 0; TRISA = 0; TRISB = 0; CMCON = 0x7; INTCON = 0; PORTA = 0; PORTB = 0; // Neverending loop // RB0: Chip select (active low) // RB1: SPI-clock // RB2: SPI-data while (1) { RB0 = 0; // Make digipot active spi_write(0b00001001); // Write data / All pots spi_write(resistance); // Update the resistance RB0 = 1; // Disable pot if (resistance > 127) op = 1; else if (resistance == 0) op = 0; if (op) resistance -= 1; else resistance += 1; } } What it does is to send the values 0..127 (back and forth) to the digipot while I measured it using a DMM. It was run on a low clocked PIC (32kHz I think), and that's why I don't use any delay-routines for the strobing. -- - Rikard - http://bos.hack.org/cv/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist