Hola, te envio los dos codigos que use y en cuanto a si es original o no, me imagino que si y ademas directamente no mide la distancia en ningun rango. O sea tira valores aleatorios que no se de donde salen.
#include <16F887.h>
#use delay(clock=4000000)
#fuses XT,NOWDT
#BYTE TRISA = 0x85
#BYTE PORTA = 0x05
#BYTE TRISB = 0x86
#BYTE PORTB = 0x06
#BYTE TRISC = 0x87
#BYTE PORTC = 0x07
#BYTE TRISD = 0x88
#BYTE PORTD = 0x08
#BYTE TRISE = 0x89
#BYTE PORTE = 0x09
#include <LCD_LIB.c>
int main (void)
{
SET_TRIS_A(0);
SET_TRIS_B(0);
SET_TRIS_C(0);
SET_TRIS_D(0x04);
SET_TRIS_E(0);
PORTA=0;
PORTB=0;
PORTC=0;
PORTD=0;
PORTE=0;
lcd_init();
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
float tiempo;
for(;;){
output_high(pin_D3);
delay_us(10);
output_low(pin_D3);
while(!input(pin_D2))
{}
set_timer1(0);
while(input(pin_D2))
{}
tiempo=get_timer1();
float temp = (tiempo*0.000001*343.2)/2;
lcd_gotoxy(1,1);
printf(lcd_putc, "\fDistancia :%Lu",temp);
delay_ms(500);
}
}
#include <16F887.h>
#use delay(clock=4000000)
#fuses XT,NOWDT
#BYTE TRISA = 0x85
#BYTE PORTA = 0x05
#BYTE TRISB = 0x86
#BYTE PORTB = 0x06
#BYTE TRISC = 0x87
#BYTE PORTC = 0x07
#BYTE TRISD = 0x88
#BYTE PORTD = 0x08
#BYTE TRISE = 0x89
#BYTE PORTE = 0x09
#include <LCD_LIB.c>
int main (void)
{
SET_TRIS_A(0);
SET_TRIS_B(0);
SET_TRIS_C(0);
SET_TRIS_D(0x04);
SET_TRIS_E(0);
PORTA=0;
PORTB=0;
PORTC=0;
PORTD=0;
PORTE=0;
lcd_init();
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
int start = 1;
for(;;){
if(start==1){
output_high(pin_D3);
output_low(pin_D3);
set_timer1(0);
start = 0;
}
if(input(pin_D2)==1){
int tiempo = get_timer1();
if(tiempo<11655){
float temp = tiempo*0.000001;
float final = temp*343.2;
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"%f metros",final);
start = 1;
}
else
{
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"Más de 4 metros");
start = 1;
}
}
}
}