Measurements of two analog signals - temperature T (°C) and wind speed V (km/h) - are to be taken once every second by a PIC18-based weather station. Noise in the measurements is to be reduced by averaging the measurements over one minute (i.e. 60 measurements). The average values are then used to calculate the windchill value W (°C) using the following equation: W = 33 - (2 x V + 15) x (33 - T)^2.
Write a 'main' program in C suitable for a PIC18 MCU to perform the measurement, averaging, and calculation of W. In your program, you must declare any variables you need, use a loop to sequence a 24-hour period of measurement, averaging, and calculating, and then stop (wait in an endless loop). You must write your program in a modular fashion, providing suitable subroutines or functions for the key steps of measurement, averaging, and calculation.
You are to assume the following routines are provided (you do not need to write these routines):
- A subroutine called "setup" initializes the ADC.
- A function called "temp" returns an integer value for T between 0 and -20 °C.
- A function called "wind" returns an unsigned integer value for V between 0 and 10 km/h.
- A subroutine called "dly1s" provides a delay of 1 second.
There is no requirement to write any other sections of the program or initialize the hardware (i.e. you do not need to initialize the ADC or write an ADC conversion program).