I think you may have overlooked this section in the readme:
Quote:
Software Use:
Call Ping_Sonar() to update the distance reading. Call Get_Sonar_Distance() to return the distance between the sonar sensor and an object in inches.
|
The functions: Hardware_Interrupt_Sonar() and Timer_Interrupt_Sonar() are only meant to be called internally in the sonar software. You only need to call two functions: Ping_Sonar() updates the distance between the sonar sensor and an object and Get_Sonar_Distance which will return the distance in inches.
I'm not familiar with your application but give this a shot. Note that I added comments about adding a time delay. It may take up to 50mS for the sonar to find an object.
]
Code:
#include <p18f452.h> // version 1.1
#include <usart.h>
#include "sonar.h"
/* Set configuration bits
* - set HS oscillator
* - disable watchdog timer
* - disable low voltage programming
*/
#pragma romdata CONFIG
_CONFIG_DECL(_CONFIG1H_DEFAULT & _OSC_HS_1H,\
_CONFIG2L_DEFAULT,\
_CONFIG2H_DEFAULT & _WDT_OFF_2H,\
_CONFIG3H_DEFAULT,\
_CONFIG4L_DEFAULT & _LVP_OFF_4L,\
_CONFIG5L_DEFAULT,\
_CONFIG5H_DEFAULT,\
_CONFIG6L_DEFAULT,\
_CONFIG6H_DEFAULT,\
_CONFIG7L_DEFAULT,\
_CONFIG7H_DEFAULT);
#pragma romdata
int i;
int distance;
void main(void)
{
int i=0;
Initialize_Sonar();
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 129); // open USART with baud of 9600
Ping_Sonar();
/* You might want to consider adding a time delay here */
while(i<10)
{
distance = Get_Sonar_Distance();
Ping_Sonar();
putrsUSART("A");
putrsUSART(distance);
putrsUSART("B");
i++;
/* You might want to consider adding a time delay here */
}
}