/* * srf.h * defines the functions and constants required for the sonic range finder */ #ifndef SRF_H #define SRF_H #define B4TIME_CONFIG 0x4a /* 01001010 value to load into timer B0 mode register ||||||||_ TMOD0,TMOD1: PULSE MEASUREMENT MODE ||||||____ MR0,MR1: PULSE WIDTH MODE ||||_______MR2: = 0 FOR PULSE MEASUREMENT |||_______ MR3: OVERFLOW FLAG (INPUT) ||________ TCK0,TCK1: F DIVIDED BY 8 SELECTED */ #define B1TIME_CONFIG 0x40 /* 01000000 value to load into timer B0 mode register ||||||||_ TMOD0,TMOD1: TIMER MODE (00) ||||||____ MR0,MR1: NA =0 ||||_______MR2: =0 |||_______ MR3: =0 ||________ TCK0,TCK1: F DIVIDED BY 8 SELECTED (01)*/ #define TB1_10US 0x0025 // 24000000/8*0.00001 = 30 = 0x1E -> make it 0x25 to give some slack #define TB1_10MS 0x7600 // 24000000/8*0.01 = 30000 = 0x7530 -> make it 7600 #define TRIGGER_OUTPUT p9_7 #define TRIGGER_OUTPUT_PD pd9_7 #define ECHO_INPUT p9_4 #define ECHO_INPUT_PD pd9_4 #define TB4_IPL 0x03 // TB4 interrupt priority level #define TB1_IPL 0x03 // TB1 interrupt priority level // SRF state machine states, referenced by global int SRF_state #define SRF_INIT 1 #define SRF_READY 2 #define SRF_TRIGGER 3 #define SRF_TX 4 #define SRF_MEASURE 5 // prototypes void srf_init(void); void tb4_irq(void); void tb1_irq(void); int get_srf_reading_mm(void); void srf_trigger(void); int is_srf_ready(void); int is_srf_reading_ready(void); int get_srf_state(void); //#define DEBUG_SRF #endif