Professional Documents
Culture Documents
Esclavo I2c
Esclavo I2c
Esclavo I2c
c> #USE I2C (SLAVE,SDA=PIN_C4,SCL=PIN_C3,ADDRESS=0XA0,SLOW,FORCE_HW) #USE standard_IO(A) #USE standard_IO(c) INT VALUE=0; INT VALUE1=0; INT BUFFER[16]; INT ADDRESS; #INT_SSP void ssp_interupt () { int incoming; BYTE state; state = i2c_isr_state(); if(state == 0x00) { address = i2c_read(0); } else if(state < 0x80 & state>0) //Master is sending data { incoming = i2c_read(0); if(state == 1) //First received byte is address {buffer[1] = incoming; }ELSE if(state == 2) //Second received byte is data { buffer[2] = incoming; }ELSE //Second received byte is data { buffer[0] = incoming; } } if(state == 0x80) { i2c_write(value); i2c_write(value1); }} VOID MAIN(){ setup_adc(adc_clock_internal); setup_adc_ports(AN0_AN1_VSS_Vref); DELAY_mS(1500); //Master is requesting data