i2c para sensor srf10 con el pic18f452

hola aver si alguien me puede ayudar lo que pasa es que estoy haciendo un sistema de proximidad ultrasonico con un sensor srf10.En el programa que mostramos no sabemos si esta bien habilitado el i2c por que las medciciones que nos despliega por la lcd no son coherentes nosostros le dimos el comando para que salga en cm pero no savemos que esta pasando...

#include "D:\sensor\srf10 452.h"
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use fast_io(d)
#include <lcd.c>


void main()
{
int i;
int16 range[17];
lcd_init();
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_oscillator(False);
set_tris_d(0x00);
// TODO: USER CODE!!
while(1)
{
i2c_start(); //initate start condition
i2c_write(0xE0); //device address //changing the i2c addres
i2c_write(0x00); //register address //set maximum analogue gain to 40
i2c_write(0x51); //set units to inches
i2c_stop();

delay_ms(105); //wait for returning ping

i2c_start(); //initiate a new start condition
i2c_write(0xE0); //device address //changing the i2c addres
i2c_write(0x02); //address of high byte register //set maximum analogue gain to 60
i2c_start();
i2c_write(0xE1); //device address but read //esta instruccion no figura en la lista


for (i=0;i<17;i++)
{
range = i2c_read(1); //read first byte and shift left
range = range << 8;
if(i<16)
range += i2c_read(1); //read second byte and add to 1st
else
range += i2c_read(0);
}
i2c_stop();

for (i=0;i<17;i++)
// printf("range in inches = %lu\n\r", range);//este es por defecto
{lcd_gotoxy(1,1);printf(lcd_putc,"Med=%lu", range);
delay_ms(2000);
}
}
lcd_gotoxy(1,2);printf(lcd_putc,"ya");
}
 
Atrás
Arriba