|
It looks nice, I hope you enjoyed the tutorial. The truth
is a project is never finished, it always remains under development as
we do. Even some commercial products do the same.
Just in case you haven't finished with the display temperature
routine, I'll give you some help. The last thing is to mask the two temperature
bytes to get the sign, the integer and decimal parts ...
void DispTempr (void)
{
u8 decimal=0;
u8 sign=0;
s8 temprdisp=0;
// mask decimal part, last 4 bits
decimal = (u8)(tempr & 0x000F);
// mask sign, first bit
sign = (u8)((tempr & 0x8000)>>15);
// mask the integer part, 7 bits
temprdisp = (s8)((tempr & 0x07F0)>>4);
if (decimal>7) temprdisp++;
if (sign) temprdisp=-temprdisp;
Display (temprdisp);
}
OK, what else? Hmm, you noticed that the thermo takes some time
to settle down also, there are times where it changes frequently between
two adjacent values. What I suggest is, get 24 measurements in an array,
discard the lowest and the highest 2 and average the rest 20 values. Repeat
every time a new measurement arrives, shift out of the buffer the oldest
value and add the new one in. By averaging (or low-pass filtering) your
data will produce a more stable (or trusted) output.
What about another feature? Yes, the button! It would be
nice to have Fahrenheit instead of Celcius on button release, then back
again to Celcius on the next button release. Don't forget debouncing.
What you can do is check at the beginning of the main loop the state of
the button, get temperature and then ckeck again the state of the button.
Remember that the total delay should be something around 500msec. Do some
tests to get the timing right, our users are not going to press the button
for more than 800msec. By the way, how long has your main loop become?
|