'***USE INTRC OSCILLATOR IN PROGRAMMER CONFIGURATION*** define ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 20 OSCCON = %01100100 'sets the internal oscillator at 4MHz TRISB = %00000000 TRISA = %11111111 ADCON1 =%10000010 sensorVal var word temperature var word pauseBetween var word seconds var word seconds = 0 pause 500 'half second delay on startup main: 'formula: 'cricket chirps per minute: (degrees Farenheit - 39)*4 'Our longest sample is 4 seconds long, so our maximum sample rate is once every 4 seconds (15 times a minute), giving us a conversion rate of 16 in relation to cricket chirps per minute at any given temperature. '60/(chirps per minute/16)*1000 gives us milliseconds between samples. In order not to overflow our WORD variable type (16 bits), We've broken the delay into four chunks, since our delay should never fall below once every 4 minutes (240000 milliseconds) 'The sounds should go on for about 20 minutes before the program stops for the night. In the morning, the power will be reset by the solar cell, and the program will begin again at dusk. while seconds < 1200 adcin 2, sensorVal temperature = sensorVal/4+14 'get approx. temperature in Farenheit if (temperature < 40) then temperature = 40 endif pauseBetween = (960/((temperature-39)*4)*250)-750 'convert to milliseconds according to the temperature with cricket chirp math high portb.3 high portb.2 pause 50 LOW portb.3 pause 2500 LOW portb.2 pause pauseBetween pause pauseBetween pause pauseBetween pause pauseBetween seconds = seconds + 3 + (pauseBetween/1000)*4 wend if seconds > 1200 then LOW portb.2 endif goto main