Re: Using PIC16(L)F15323 with HC-SR04 sensor
Probably not your problem, but change every occurence of
Always write to LAT, read from PORT
Get rid of that return at the end of the main() function.
It's not hurting, but is totally pointless.
How are you testing this?
I see the only way to access your "distance" variable is via the I2C slave code, which means you're potentially debugging two things at once.
I know you say the I2C is working, but have you tried running this code under a debugger?