// I2C and the Parallax 3-axis compass module.

// Pianoman0488 - November 1st, 2012.

unsigned char outByte = 0; // 0 - 255 (ascii capable)


void init(void)

{

// Initialize 18f4550.

ADCON0 = 0;

ADCON0 = 0x0F;

TRISB = 0b01000000;

Soft_UART_Init(&PORTB, 6, 7, 9600, 0);

I2C1_Init(100000);

}


void writeByte( unsigned char outByte )

{

// Write byte to Soft_UART interface.

Soft_UART_Write(outByte);

}


void whoAmIA(void)

{

I2C1_Start();

I2C1_Wr(0x3C); // write to slave 0x01E

I2C1_Wr(0x0B); // d'10 h'0A

I2C1_Repeated_Start(); // continue to next segment

I2C1_Wr(0x3D); // 1E -> read from -> h'3D

outByte = I2C1_Rd(0u);

I2C1_Stop();

}



void main() {

init();

while(1)

{

whoAmIA();

writeByte( outByte );

Delay_ms(10);


}

}