Looking for a better frequency counter library

Let me post it to save people the trouble of downloading:

/* The LCD is usually interfaced via 16 pins which are labelled as shown below:
    LCD Pin
    1. GND - Ground
    2. VDD - 3 - 5V
    3. VO  - Contrast
    4. RS  - Register Select - Command (0) or Character (1)
    5. RW  - Read/Write - Write (0) or Read (1)
    6. E   - Enable - Enable data transmit (0)
    7. DB0 - Data Bit 0
    8. DB1 - Data Bit 1
    9. DB2 - Data Bit 2
   10. DB3 - Data Bit 3
   11. DB4 - Data Bit 4 - used in 4 bit operation
   12. DB5 - Data Bit 5 - used in 4 bit operation
   13. DB6 - Data Bit 6 - used in 4 bit operation
   14. DB7 - Data Bit 7 - used in 4 bit operation
   15. BL1 - Backlight +
   16. BL2 - Backlight -
*/
                         //Connections to Arduino
                         //LCD        Ardunino
                         // 1. GND    N/A
                         // 2. VDD    N/A
                         // 3. VO     N/A  (Tap off a 5K - 10K pot across VCC and Ground)
#define LCD_RS       12  // 4. RS     D12
                         // 5. RW     GND
#define LCD_ENABLE   11  // 6. E      D11
                         // 7. DB0    None
                         // 8. DB1    None
                         // 9. DB2    None
                         //10. DB3    None
#define LCD_DB4       4  //11. DB4    D4
#define LCD_DB5       6  //12. DB5    D6
#define LCD_DB6       7  //13. DB6    D7
#define LCD_DB7       8  //14. DB7    D8
#define LCD_Backlight 9  //15. BL1    Emitter of 2N3904, Collector to VCC, Base to D9 via 10K resistor
                         //16. BL2    GND

#include <Wire.h>
#include <Time.h>
#include <DS1307.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(LCD_RS, LCD_ENABLE, LCD_DB4, LCD_DB5, LCD_DB6, LCD_DB7);

#define SAMPLE_SIZE  1
static  uint16_t iSample_Size = SAMPLE_SIZE;
volatile uint32_t iSample;
volatile char bSamplesCtl = -1; // -1= Stop, not taking samples  0=Start taking samples  1=Sample are ready


void setup () {
  Wire.begin();

  lcd.begin(16, 2);
  lcd.clear();
  pinMode(LCD_Backlight, OUTPUT); analogWrite(LCD_Backlight, 128); // Set the brightness of the backlight using PWM
  pinMode(2, INPUT_PULLUP);

  attachInterrupt(0, Pin2_ISR, FALLING);

//DS1307::SetSquaresWave(SQW_1Hz);
//DS1307::SetSquaresWave(SQW_4kHz);   // 4.096 kHz =  4096 Hz
//DS1307::SetSquaresWave(SQW_8kHz);   // 8.192 kHz =  8192 Hz
  DS1307::SetSquaresWave(SQW_32kHz);  //32.768 kHz = 32768 Hz
  bSamplesCtl = 0; // Start taking timing samples
}

void loop() {
  DisplayDateTime();
  delay(500);

  lcd.setCursor(0, 1);  lcd.print("                ");
  lcd.setCursor(0, 1);

  if (bSamplesCtl != 1) { // Sampling not complete
    lcd.print('*');
  } else {                // we have a set of samples
    uint32_t iFreq;
    if (iSample_Size <= 4000) {
      iFreq = (1000000L * iSample_Size) / iSample;
    } else {
      iFreq = 1000000L / (iSample / iSample_Size);
    }
    lcd.print(iFreq); lcd.print("Hz "); lcd.print(iSample); lcd.print(" "); lcd.print(iSample_Size);
    if (iSample < 1000) { // Less than one millisecond worth of samples
      iSample_Size *= 2; // double the samples
      if (iSample_Size > 4000) iSample_Size = 4000;
    }
    bSamplesCtl = 0; // Take another samples
  }
}

void DisplayDateTime(void)
{
  char szBuffer[16];
  strftime(szBuffer, sizeof(szBuffer), "%m/%d %T", DS1307::getTime());
  lcd.setCursor(0, 0);
  lcd.print(szBuffer);
}

void Pin2_ISR()
{
  static uint32_t iPrev = 0;
  static uint16_t iSampleCnt = 0;
  uint32_t iTemp = micros();

  if (bSamplesCtl == -1) return; // -1= Stop, not taking samples
  if (bSamplesCtl == 1)  return; //  1= Sample ready for use.
                                 //  0= Taking samples
  if (iSampleCnt == 0)
    iPrev = iTemp;

  iSampleCnt++;
  if (iSampleCnt > iSample_Size) { // Sampling complete
    iSample = iTemp-iPrev;        // Save results
    iPrev = 0; iSampleCnt = 0;    // Clean-up ready for next use.
    bSamplesCtl = 1;           //
  }
}