/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.4a Advanced
Automatic Program Generator
 Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

     Ni-Cd  Ni-MH   .

 - .
 30.01.2008   http://www.radiokot.ru/lab/controller/31/. 

     Ni-Cd  Ni-MH
.  1.0
   .   1 
 ,  ,   .  
15 .
   /     ,
     ,   ,
         EEPROM.
       1,1 ,
 ,   .
     ,  1,2 ,
 ,    .
     ,   
  .
  / ,   ר 
  .

AIN1 ( 11) -    .
ADC0 ( 20) -   .
ADC1 ( 19) -   .
PB7 ( 10) -  "RESET" -   5   , 
0,1   . 

   ( ):
AT26L - SUT1-0, SUT0-1, CKSEL3,2,1,0 - 1, 1, 1, 0.  

PB0 ( 1) -  "" -  1 -  , 0 - 
PB1 ( 2) -  "" -   1 - , 0 -  
PB2 ( 3) -  "" -  1 -  , 0 - 

Chip type               : ATtiny26
AVR Core Clock frequency: 4,096000 MHz
Memory model            : Tiny
External RAM size       : 0
Data Stack size         : 32
*****************************************************/

#include <tiny26.h>
#include <delay.h>

// Declare your global variables here
#define ADC_VREF_TYPE 0x00

//    []
#define xtal 4096000

//    []
#define fmove 1
//     
#define MAX_CHARGE_TIME 50000 
//54000 -     = 15 

//    :
// TCNT1=0x10000-(xtal/1024/fmove);

//     .
// ADC = 5000 = 5v
// Vin -    ADC1  .

#define BAT_MIN_LEVEL 1000 //  0,5  x 2.  
//    ,  ,     . 
#define BAT_DISCHARGE_LEVEL 2000 //  1   .
//      .
#define BAT_MAX_LEVEL 3600 //  1,8   .
#define POWER_MIN_LEVEL 4200 //  4,2   .
//     ,  ,     .
#define DISCHARG PORTB.0                   // DISCHARGE pin 1;
#define READY PORTB.1                      // READY pin  2
#define CHARG PORTB.2                  // CHARGE pin  3 
//   

// ,      
volatile unsigned int chargeTime=0; //   
volatile unsigned int U_CURENT=0; // 
volatile unsigned int average=0; //  
volatile enum  //   
{
    ready,     //  
    discharge, // 
    charge,    // 
    iddle      //   
}chargerStatus;


// ,      
eeprom unsigned int chargeTimeEeprom = 0xFFFF;
eeprom unsigned char chargerStatusEeprom = 0xFF;
