|
Listing 5: ow_read_var()
int ow_read_var(int bit_time, int pulse_time, int one_done) {
int capval
CONTROL = LOAD_COMPARE; //set up for pulse
COUNT = 0; COMPARE = SHORT; PERIOD = SHORT + pulse_time;
COUNT = 1; CONTROL = HOLD_COUNT; //lock period & compare values
/* the shadow registers will be loaded when the count restarts */
COMPARE = bit_time;
PERIOD = bit_time - SHORT - pulse_time;
CONTROL = CONTINUOUS_UP; //start timer
while (COMPARE == SHORT); // wait until we start the second time
while (COUNT == 0); // avoid a race with the counter reg
while (COUNT != 0); // wait for the timer to count down
/* if there is more than one capture event, look at the last */
while (CAPFIFO & CAP3MASK)
capval - CAP3FIFO;
if (capval > one_done) return 0;
else return 1;
}
|
|
|
|
Ready to take that job and shove it?
|
|