Esclavo I2c

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <16f877a.h> #device adc=8 #fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT #USE DELAY (CLOCK=4000000) #include <lcd.

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

ENABLE_INTERRUPTS(GLOBAL); ENABLE_INTERRUPTS(INT_SSP); WHILE(1){

set_adc_channel(0); VALUE=read_adc(); DELAY_MS(300); set_adc_channel(1); VALUE1=read_adc(); } }

You might also like