#ifndef _KSH148_H
#define _KSH148_H

#include "hardware.h"

#define CONST__LoBAND  0B00000001
#define CONST__MiBAND  0B00000010
#define CONST__HiBAND  0B00001100
#define CONST__GAINoff 0B10001000
#define CONST__GAINon  0B10001001 // Weak Signal Booster ON


volatile uint32_t FrcvWork  = 100000;
volatile uint8_t  TunerGain = 1;
volatile uint8_t  FindStep  =  7;
volatile uint16_t FrcvPCH2;
volatile uint8_t  flagBo = 0;
volatile uint8_t  Modulation = 0;
volatile uint32_t Step[12]={1,5,10,15,20,25,50,100,500,1000,5000, 10000};

void KSH14xPLL2(void)
{
  unsigned short fPCH1;
  unsigned char  Band;


  Band = CONST__LoBAND;

  if(FrcvWork > 155000L) Band = CONST__MiBAND;
  if(FrcvWork > 440000L) Band = CONST__HiBAND;

  fPCH1 = (unsigned short)((FrcvWork + RCVPCH1)/50);
    
  I2CStart();
  I2COutByte(0b11000000);   // Tuner Address
  I2COutByte(HiBYTE(fPCH1));
  I2COutByte(LoBYTE(fPCH1));
  I2COutByte((TunerGain)? CONST__GAINon:CONST__GAINoff);
  I2COutByte(Band);
  I2CStop();		 
  return;
}

#endif