Im not sure if im right about this but try this...
I put the whole thing in an endless loop..
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 distance;
void main(void)
{
Initialize_Sonar();
while (1) // Endless loop
{
Ping_Sonar();
Hardware_Interrupt_Sonar();
Timer_Interrupt_Sonar();
distance = Get_Sonar_Distance(); // Get distance and update variable
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
putrsUSART("A");
putrsUSART(distance);
putrsUSART("B");
}
}
Try that and see if it works...
Good Luck