Hi. I'm trying to program the eeprom in a pic12ce519 using the following code. Doesn't work, though. Someone care to have a look? /* IIC BUS INTERFACE: Code size for one read and one write to IIC device: 8 MHz clock : 110 instructions 4 MHz clock : 91 instructions 2 MHz clock : 82 instructions 500 kHz clock : 76 instructions Use of macros are recommended. This module use subroutines in one level. New macros may be constructed in a similar way. Delay syntax: delay_4us_m3 : insert a 4 microseconds delay, but subtract the time to execute 3 instruction cycles 1 instruction cycle = 4 clock cycles = 1 microsecond at 4 MHz */ #include <12ce519.h> void delay_ms(uns16 number){ int a,b; uns16 c; for(a=0;a 0); scl_IIC = 0; sda_IIC = master_ack; delay_5us_m7 scl_IIC = 1; delay_4us_m6 } void sendIICbyte( char W) /* writes one byte to IIC slave device */ { char counter; IIC_byte = W; counter = 8; do { IIC_byte = rl( IIC_byte); scl_IIC = 0; delay_5us_m5 sda_IIC = Carry; delay_0us_m1 /* minimum 250 nanosec. */ scl_IIC = 1; delay_4us_m3 } while ( -- counter > 0); /* read ack. */ scl_IIC = 0; READ_sda(); delay_5us_m2 scl_IIC = 1; if ( sda_IIC) IIC_error = 1; delay_4us_m8 } #define readByteFromIIC( address, variable) \ startIICcomm(); \ sendIICbyte( IIC_address_RW_0); \ sendIICbyte( address); \ stopIICcomm(); \ \ startIICcomm(); \ sendIICbyte( IIC_address_RW_1); \ \ /* more bytes to read .. \ master_ack = 0; \ readIICbus(); */ \ \ master_ack = 1; \ readIICbus(); \ stopIICcomm(); \ variable = IIC_byte #define writeByteToIIC( address, IIC_data) \ startIICcomm(); \ sendIICbyte( IIC_address_RW_0); \ sendIICbyte( address); \ \ sendIICbyte( IIC_data); \ /* + more bytes to send \ sendIICbyte( .. ); */ \ \ stopIICcomm(); /* NOTE: EEPROM's require a delay between each (or each second) write to IIC device */ void main( void) { #asm MOVLW 0x1F // Set the OPTION register OPTION MOVLW 0x0F TRIS GPIO #endasm char x; writeByteToIIC(10, 100); blink(); // delay readByteFromIIC(10, x); if(x==100) { while(1) blink(); /* this is what I want... */ } else { while(1) GPIO.5=0; /* Program flow ends up here. :( */ } } -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.