This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530 TIMER1

Other Parts Discussed in Thread: CC2530

I have written following code to high(bit) at port 0.7 for some time period. and wait for reply on port 0.5.

I know it is not good. Thanks for help

unsigned int get_distance(void)

  {

  T1CC0H=0x0C;                     //prepare timer for 10uS pulse

  T1CC0L=0xB1;                  

  T1CCTL0 |= 0x04;                //1:4 prescale and running

  T1IF = 0;

  P0_7^=1;                               // port 0.7 high

  while(!T1IF);                         // wait 10uS

  P0_7^=0;                               // port 0.7 low

  T1CTL = 0x00;                     // stop timer

  T1CC0H=0x00                      // prepare timer to measure pulse

  T1CC0L=0X01;                     //TMR3L = 0;

  T1CCTL0 &= 0x07               // 1:4 prescale but not running yet

  T1IF = 0;

  while(!P0^5 && !T1IF);        // wait for pulse to start (go high)

  T1CNTL = 0x01;                  // start timer to measure pulse

  while(P0^5 && !T1IF);         // wait for echo pulse to stop (go low)

  T1CNTL = 0x00;                  // stop timer

  return ((T1CC0H<<8)+T1CCOL);    // contains flight time of the pulse

}