/* StrikeMeter v1.0 (c) 1998 Creative Control Concepts This program is used with a Lightning Strike sensor to monitor nearby lightning activity. When used with a LSU-2001 sensor from McCallie Manufacturing, the PIC will receive one pulse for each sensed lightning strike. This program will monitor these pulses and track the hits per minute of local storms. The method of doing this is to count pulses for 3 seconds and to store the previous 19 counts to get a 60 second total which will give us the counts per minute which will update every 3 seconds. To assist in determining if a storm is approaching or moving farther away, we will store a peak value which is reset when the rate falls below 5 hits/min If the peak is rising over 3 consecutive minutes, we treat the storm as approaching. If the opposite is true, we treat the storm as receeding. We will also store a peak value which is only reset by a button press from the user. A0/RTCC is the sensor input A1 is the peak count reset button A2-4 are config bits and also RS-485 I/O for the HCS interface B0-6 control the LCD display B7 is the alarm output *** LICENSE *** The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is "RS_485 based Lightening Strike Meter" The Initial Developer of the Original Code is Mike Baptiste (baptiste@cc-concepts.com) Contributor(s): None Yet Alternatively, the contents of this file may be used under the terms of the GNU General Public License Version 2 or later (the "GPL"), in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the GPL. *** LICENSE *** */ #INCLUDE <16f84.h> #FUSES HS, NOWDT, NOPROTECT, NOPUT // PUT is enabled on Parallax with this #USE DELAY (CLOCK=4000000) #ZERO_RAM #USE FAST_IO(A) #USE FAST_IO(B) #INCLUDE "lcd_l.c" void main () { int count_buffer[20]; // Will we ever get more than 256 strikes in 3 seconds?? int idx, tidx; long int present, peak; SET_TRIS_A(0b11101011); // Lets get the display up and running lcd_init(); // General Initialization setup_counters(rtcc_ext_h_to_l,wdt_18ms); // Gets us RTCC_DIV_1; // Now lets do the intro lcd_putc("CCC StrikeMeter\n v1.00 (c)1998"); delay_ms(5000); lcd_putc("\fNow: Peak:\n No Lightning"); // No need to init variables to 0 - already done. // Now we can loop and count while(1) { set_rtcc(0); // Lets zero out the count for (tidx=0;tidx < 30;tidx++) { // Lets check for a peak reset every 100ms (cheap debounce) if (!INPUT(PIN_A1)) { peak = 0; } delay_ms(100); } // Later we'll do more during this 3 seconds // Lets loop and each second, update the second line. // This way we can scan through up to 3 lines of info such as: // If no alarm - *** WARNING *** else // >>> ALARM ON <<< // STORM // APPROACHING // Perhaps we can add a beeper to grab attention? // STORM // RECEEDING // Strikes/Minute // No Lightning Now or // Strike Detected! tidx = idx; if (++idx > 19) { idx = 0; } count_buffer[idx] = get_rtcc(); set_rtcc(0); // Lets get the current hits per minute // Instead of summing 20 numbers each time, lets be smart. Subtract the old number and add the new present = present - count_buffer[tidx] + count_buffer[idx]; if (present > 999) { present = 999; // 1000 hits in a minute - I'd be outta here! } // Lets save the peak value! if (peak < present) { peak = present; } // Lets output the strike numbers lcd_gotoxy(1,5); printf(lcd_putc, "%3lu", present); lcd_gotoxy(1,14); printf(lcd_putc, "%3lu", peak); // Now lets output the status line if (count_buffer[idx] != 0) { lcd_putc("\nLightning Detect"); } else { lcd_putc("\n No Lightning "); } } }