////////////////////////////////////////////////////////////////////////////////
//
// PIC16F877 + HY-SRF05 + LCD03 example
// Written October 2008 , using HITECH PIC16 compiler
//
//Note - assumes a 20MHz crystal, which is 5MHz timer clock
//A 1:4 prescaler is used to give a 1.25MHz timer count (0.8uS per tick)
//
// This code is Freeware - Use it for any purpose you like.
//
///////////////////////////////////////////////////////////////////////////////
setup();
// sets up the PIC16F877 I2C port
clrscn();
// clears the LCD03 disply
cursor(2);
// sets cursor to 1st row of LCD03
sprintf(s,"SRF04 Ranger Test");// text, printed into our buffer
print(s);
// send it to the LCD03
while(1) {
// loop forever
range = get_srf04();// get range from srf04 (round trip flight time in 0.8uS units)
cursor(24);
// sets cursor to 2nd row of LCD03
sprintf(s,"Range = %dcm ", range/72);// convert to cm
print(s);
// send it to the LCD03
cursor(44);
// sets cursor to 3rd row of LCD03
sprintf(s,"Range = %dinch ", range/185);// convert to inches
print(s);
// send it to the LCD03
TMR1H = 0;
// 52mS delay - this is so that the SRF04 ranging is not too rapid
TMR1L = 0;
// and the previous pulse has faded away before we start the next one
T1CON = 0x21;
// 1:4 prescale and running
TMR1IF = 0;
while(!TMR1IF);// wait for delay time
TMR1ON = 0;
// stop timer
}
}