/****************************************************************************** ****************************************************************************** * main.c * * the program body */ /* Include the required header files */ #include "skp_bsp.h" // include SKP board support package #include "srf.h" #include "skp_lcd.h" char d_str[8]; #pragma INTERRUPT tb4_irq #pragma INTERRUPT tb1_irq void mcu_init(void); /***************************************************************************** Name: main() Parameters: none Returns: nothing Description: Init mcu, display and srf (should start srf state machine), then the loop simply triggers (ie 10us pulse out) if the srf is ready or records the measurement if the measurement is ready *****************************************************************************/ void main (void) { int temp = 0; int srf_state = 0; int i = 0; mcu_init(); InitDisplay(); DisplayString(16, "SRF04"); srf_init(); while (1) { DisplayString(20, ":"); srf_state = get_srf_state(); while (srf_state != SRF_READY) { ; }; srf_trigger(); #ifdef SRF_DEBUG DisplayString(21, "a"); #endif while (srf_state != SRF_MEASURE) { ; }; #ifdef SRF_DEBUG DisplayString(22, "b"); #endif temp = get_srf_reading_mm(); if (temp == -1) { DisplayString(16, "-"); } else if (temp < 100) { DisplayString(16, "0"); } else if ( (temp >= 100) || (temp < 200) ) { DisplayString(16, "1"); } else { DisplayString(16, "2"); }; }; } /************************************************************************************** **************************************************************************************/