
Department of Computer Science and Electronics
25
In this section the algorithm of the program is going to be explained. The
resultant C code can be found in Appendix A.
Main function
Call to init_function
While (forever)
Reset watchdog
Do nothing until data have been received and is ready to be read from UDR
Read UDR
If (address=uc’s address or broadcast) do:
If (calibration) do:
Call calibrate function
Call to the function that sends calibration results to EEPROM
Else do:
Call to the function that sends through USART the sensors’ state
End if
End if
End while
Initialize function
Enable watchdog (2seg)
Set microcontroller address
For (8 steps) do:
Read calibration results from EEPROM
Reset watchdog
End for
Initialize PORTB. Pin 2 and 3 as output
Initialize USART. 16MHz and 9600 bps
Initialize ADC. Enable ADC and prescaler 125kHz
Ignore the first conversion of the ADC
Disable transmission
Calibration function
Before illustrating the algorithm, an explanation of how the threshold of a single
sensor is calculated, is taking place.
First of all, as figure 4-10 shows, xprima value is calculated, being the half-sum
of the biggest and the smallest value read during the first half time period of the
calibration. However, this is not the optimal sensor’s threshold, thus in the next half
period of the calibration, a more concrete value is calculated taking advantage of
knowing the value of xprima.
Commentaires sur ces manuels