亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? liion_bc_main.c

?? yright 2002 Cygnal Integrated Products, Inc. // // Filename: LIION_BC_MAIN.c // Target Device: 8051F
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
//
// Copyright 2002 Cygnal Integrated Products, Inc.
// 
// Filename:      LIION_BC_MAIN.c
// Target Device: 8051F300
// Created:       11 SEP 2002
// Created By:    DKC
// Tool chain:    KEIL Eval C51
//
// This is a stand alone battery charger for a Lithium ION battery.
// It utilizes a buck converter, controlled by the on-chip 8-bit PWM,
// to provide constant current followed by constant voltage battery charge.
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f300.h>
#include "LIION_BC_MAIN.h"              // Battery Hearder File
                   
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

void Config_F300(void)
{ RSTSRC   = 0x02;                      // Enable VDD Monitor     
  XBR0     = 0x70;                      // Skip P0.4,5,6; they're analog In
  XBR1     = 0x44;                      // Enable SMBus on P0.0, P0.1, and CEX0 
  XBR2     = 0x40;                      // as PWM at P0.2
                                        // Enable crossbar and weak pull-ups

  P0MDOUT  = 0x0C;                      // Set P0.2 & P0.3 output to push-pull 
  P0MDIN   = 0x8F;                      // Configure P0.4,5,6 as Analog Inputs

  OSCICN   = 0x07;                      // Set SYSCLK to 24.5MHz, internal osc.  

  ADC0CN   = 0xC0;                      // Turn on the ADC Module; 
                                        //   enable low power mode for settling
      
  REF0CN   = 0x0C;                      // Configure ADC's to use VDD for 
                                        //   Voltage Reference,
                                        //   Enable On-chip Temperature Sensor
//-----------------------------------------------------------------------------
// PCA Configuration
//-----------------------------------------------------------------------------
  PCA0MD   = 0x00;                      // Disable WDT
  PCA0MD   = 0x08;                      // Set PWM Time base = SYSCLK

  PCA0L    = 0x00;                      // Initialize PCA Counter to Zero
  PCA0H    = 0x00;   
   
  PCA0CN   = 0x40;                      // Enable PCA Counter
                                        // Clear PCA Counter Overflow flag
  //Module 0
  PCA0CPM0 = 0x00;                      // Configure CCM0 to 8-bit PWM mode
  PCA0CPL0 = 0xF0;                      // Initialize PCA PWM to small duty cycle
  PCA0CPH0 = 0xF0;                      // 0xF0 Ensures a Soft Initial Charge
   
  //Module 1
  PCA0CPM1 = 0x49;                      // Configure Module 1 as software timer
  PCA0CPL1 = 0xFF;                      // Initialize to 255 so that Interrupt
                                        //     is generated when PCA ends 
                                        // 8-bit PWM Cycle
  PCA0CPH1 = 0x00;                      // PCA0CPH is the high byte of the 
                                        //    Output Compare Module

  EIE1     = 0x08;                      // Enable PCA Overflow Interrupt 
}

//-----------------------------------------------------------------------------
// Reset_Time_Base - Resets all Time Counting Values
//-----------------------------------------------------------------------------
void Reset_Time_Base()
{
  TIME.sec     = 0x00;
  TIME.min     = 0x00;
  TIME.hour    = 0x00;
  TIME.t_count = PWM_CLOCK; 
}

//-----------------------------------------------------------------------------
// Delay - This is a Delay to permit time for Switches to Debounce
//-----------------------------------------------------------------------------
void Delay_Loop (void)
{
  long i=0;
  for (i=0;i<100000;i++);
}

//-----------------------------------------------------------------------------
// Initialize CalibrateADCforVoltageMeasurement
//-----------------------------------------------------------------------------
// This function calibrates the voltage channel and stores the calibration
// coefficients in the parameters volt_slope and volt_offset.
//
void CalibrateADCforMeasurement()
// This calibration routine uses a 2 point cal.  
{ unsigned char xdata *pwrite;          // FLASH write pointer
   
  EA = 0;                               // Disable All Interrupts

  // Wait until 1st calibration voltage is ready for cal
  while (SW0 == 1);                     // Wait until SW0 pushed
  Delay_Loop();                         // Wait for Switch Bounce

  // Once ready, Get the first calibration voltage
  AMX0SL = VBAT;                        // Select appropriate input for AMUX
  ADC0CF = (SYSCLK/5000000) << 3;       // ADC conversion clock = 5.0MHz
  ADC0CF &=0xF8;                        // Clear any Previous Gain Settings
  ADC0CF |= 0x01;                       // PGA gain = 1
  temp_INT_1.i = Measure(); 
   
  // Wait until 2nd calibration voltage is ready for cal
  while (SW0 == 1);                     // Wait until SW0 pushed
  Delay_Loop();                         // Wait for Switch Bounce

  // Once ready, Get the 2nd calibration voltage
  AMX0SL = VBAT;                        //   Change Mux for second point
  temp_INT_2.i = Measure();
     
  // Calculate the SLOPE                // V1 and V2 are in tenth of a degree
  temp_LONG_1.l = (unsigned)(temp_INT_2.i-temp_INT_1.i);
  temp_LONG_1.l *= (unsigned)100;       // Account for Math Truncation Error
  temp_LONG_1.l /= (unsigned)(V2_CAL - V1_CAL);
  
     
  // Calculate the OFFSET
  temp_LONG_2.l  = (unsigned)temp_INT_1.i;
  temp_LONG_2.l -= (signed)(temp_LONG_1.l * V1_CAL/100);
 
  temp_LONG_1.l = 2050;                 // If no cal. use these
  temp_LONG_2.l = 0;                    //  as default values
    
  // Erased memory at page 0x1A00
  pwrite = (char xdata *)&(CHECK_BYTE.b[0]);

  PSCTL = 0x03;                         // MOVX writes target FLASH memory;
                                        // FLASH erase operations enabled

  FLKEY = 0xA5;                         // FLASH key sequence #1
  FLKEY = 0xF1;                         // FLASH key sequence #2
  *pwrite = 0x00;                       // initiate PAGE erase

  // Write the Volt SLOPE and OFFSET to Flash
  PSCTL = 1;                            // MOVX writes to Flash
   
  pwrite = (char xdata *)&(VOLT_SLOPE.b[0]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[0];
  pwrite = (char xdata *)&(VOLT_SLOPE.b[1]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[1];
  pwrite = (char xdata *)&(VOLT_SLOPE.b[2]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[2];
  pwrite = (char xdata *)&(VOLT_SLOPE.b[3]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[3];

  pwrite = (char xdata *)&(VOLT_OFFSET.b[0]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[0];
  pwrite = (char xdata *)&(VOLT_OFFSET.b[1]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[1];
  pwrite = (char xdata *)&(VOLT_OFFSET.b[2]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[2];
  pwrite = (char xdata *)&(VOLT_OFFSET.b[3]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[3];
  
  PSCTL = 0;                            // MOVX writes target XRAM

//-----------------------------------------------------------------------------
// Initialize CalibrateADCforCurrentMeasurement_NOAMP
//-----------------------------------------------------------------------------
// This function calibrates the current channel with no external amp
// and stores the calibration coefficients in the 
// parameters i_noamp_slope and i_noamp__offset.
//
// This calibration routine uses a 2 point cal.  
  // Wait until calibration voltage is ready for cal
  while (SW0 == 1);                     // Wait until SW0 pushed
  Delay_Loop();                         // Wait for Switch Bounce
  // Once ready, Get the first calibration voltage
  AMX0SL = IBAT;                        // Select appropriate input for AMUX
  ADC0CF = (SYSCLK/5000000) << 3;       // ADC conversion clock = 5.0MHz
  ADC0CF &=0xF8;                        // Clear any Previous Gain Settings
  ADC0CF |= 0x03;                       // Set PGA gain = 4
  temp_INT_1.i = Measure();             // Acquire 16-bit Conversion
  temp_INT_1.i *= 2;                    // Account for Differential Mode
  // Wait until 2nd calibration voltage is ready for cal
  while (SW0 == 1);                     // Wait until SW0 pushed
  Delay_Loop();                         // Wait for Switch Bounce

  // Once ready, Get the 2nd calibration voltage
  temp_INT_2.i = Measure();             // Acquire 16-bit Conversion   
  temp_INT_2.i *=2;                     // Account for Differential Mode
  
  // Calculate the SLOPE 
  temp_LONG_1.l =  (unsigned)(temp_INT_2.i - temp_INT_1.i);
  temp_LONG_1.l *= (unsigned)100;       // Account for Math Truncation Error
  temp_LONG_1.l /= (unsigned)(I2_CAL - I1_CAL);
  temp_LONG_1.l /= (unsigned)CURRENT_GAIN;// Account for Gain

  // Calculate the OFFSET
  temp_LONG_2.l =  (signed)(temp_INT_1.i/CURRENT_GAIN);
  temp_LONG_2.l -= (signed)(temp_LONG_1.l * V1_CAL/100);
   
  temp_LONG_1.l = 2050;                 // If no cal. use these
  temp_LONG_2.l = 0;                    //  as default values

  // Memory at 0x1A00 is already erased
  // Write the Volt SLOPE and OFFSET to Flash
  PSCTL = 1;                            // MOVX writes to Flash
   
  pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[0]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[0];
  pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[1]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[1];
  pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[2]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[2];
  pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[3]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_1.b[3];
  pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[0]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[0];
  pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[1]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[1];
  pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[2]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[2];
  pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[3]);
  FLKEY = 0xA5;
  FLKEY = 0xF1;                         // enable flash write
  *pwrite = temp_LONG_2.b[3];
  
  PSCTL = 0;                            // MOVX writes target XRAM
}

//-----------------------------------------------------------------------------
// Measure
//-----------------------------------------------------------------------------
//
// This routine averages 65536 ADC samples and returns a 16-bit unsigned 
// result.
// 
unsigned int Measure (void)
{
  unsigned i;                           // sample counter
  unsigned long accumulator=0L;         // here's where we integrate the
                                        // ADC samples

  // read the ADC value and add to running total
  i = 0;
  do {
    AD0INT = 0;                         // clear end-of-conversion indicator
    AD0BUSY = 1;                        // initiate conversion
    while(!AD0INT);                     // wait for conversion to complete
    accumulator += ADC0;                // read adc value and accumulate
    i++;                                // update counter
  } while (i != 0x0000);
   
  // the accumulator now contains 16 added bits of which 8 are usable 
  return (unsigned int) (accumulator >> 8);    
}

//-----------------------------------------------------------------------------
// Regulate_Current
//-----------------------------------------------------------------------------
// This routine monitors the battery's current and adjusts 
// the PWM (i.e. duty cycle) to keep the current at a known value
//
void Regulate_Current(int passed_current)
{ unsigned int temp = 0;
  
  do{
    temp = Monitor_Battery(CURRENT);    // Measure Current

   if (temp < passed_current)
      PCA0CPH0--;
    if (temp > passed_current)
        PCA0CPH0++;
  
  }while ((temp < (passed_current - CURRENT_TOLERENCE)) || 
          (temp > (passed_current + CURRENT_TOLERENCE)));  
                                        // I_BULK or I_LOWCURRENT is set now

  temp = Monitor_Battery(VOLTAGE_PWM_OFF);
                                        // If VOLTAGE within range, 
                                        // change from constant CURRENT charge
                                        // mode to constant VOLTAGE charge mode
  if ((temp >= (VOLT_LOWCURRENT - VOLT_TOLERANCE)) &&
   (temp <= (VOLT_LOWCURRENT + VOLT_TOLERANCE)))
  {
    CONST_C = 0;
    CONST_V = 1;
  }

}

//-----------------------------------------------------------------------------
// Regulate_Voltage
//-----------------------------------------------------------------------------
// This routine monitors the battery's voltage and adjusts 
// the PWM (i.e. duty cycle) to keep the voltage at a known value
//
void Regulate_Voltage(void)
{ unsigned int temp = 0;
                                        // set VOLT_BULK (with "soft start")
  do{
    temp = Monitor_Battery(VOLTAGE);
    
   if (temp < VOLT_BULK)
      PCA0CPH0--;
    if (temp > VOLT_BULK)
      PCA0CPH0++;

  }while ((temp < (VOLT_BULK - VOLT_TOLERANCE)) || 
            (temp > (VOLT_BULK + VOLT_TOLERANCE)));
                                        // VOLTAGE is set now
}

//-----------------------------------------------------------------------------
// Turn_PWM_Off
//-----------------------------------------------------------------------------
// This routine peforms a soft charge turn off by taking the PWM's  
// duty cycle slowly to zero.
//
void Turn_PWM_Off(void)
{ 
  do{
    if (PCA0CPH0 < 0xF0)
      PCA0CPH0++;
                  
  }while (PCA0CPH0 < 0xF0);                       
  // Duty Cycle is now small and safe to turn off.

  PCA0CPM0 = 0x00;                      // Disable PWM
}

//-----------------------------------------------------------------------------
// Monitor_Battery
//-----------------------------------------------------------------------------
// This routine acts as a switch when gathering different conversion types.
// It adjusts the throughput, adjust the AMUX and returns the current in mA,

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美成人a视频| 欧美xxxxx牲另类人与| 国产精品三级电影| 免费在线观看成人| 日本韩国欧美一区二区三区| 日韩有码一区二区三区| 国产精品久久看| 精品福利在线导航| 欧美日韩一区 二区 三区 久久精品| 国精产品一区一区三区mba桃花| 伊人夜夜躁av伊人久久| 国产婷婷一区二区| 欧美电影免费观看高清完整版在线| 色综合中文字幕国产 | 日本黄色一区二区| 国产一区二区在线免费观看| 亚洲午夜激情av| 亚洲人妖av一区二区| 久久美女艺术照精彩视频福利播放| 精品视频1区2区| 在线观看亚洲精品| 色综合久久66| 99久久精品国产毛片| 国产精品一区二区你懂的| 免费一级欧美片在线观看| 国产欧美精品在线观看| 久久久天堂av| 不卡的av中国片| 国产精品自拍毛片| 久久99蜜桃精品| 久久精品999| 毛片av中文字幕一区二区| 日韩精品电影在线| 图片区小说区区亚洲影院| 亚洲国产精品一区二区久久恐怖片| 自拍视频在线观看一区二区| 国产精品福利影院| 亚洲欧洲日产国码二区| 欧美高清在线精品一区| 国产精品天天看| 国产精品毛片久久久久久久| 欧美国产精品久久| 国产精品久久久久久久久快鸭| 欧美国产日本韩| 亚洲天堂福利av| 一区二区三区免费观看| 亚洲一区二区三区中文字幕 | 91丨porny丨蝌蚪视频| 国产伦精一区二区三区| 日本一区二区在线不卡| 久久综合色综合88| 免费精品视频在线| 久久精品国产色蜜蜜麻豆| 久久av老司机精品网站导航| 精品亚洲国内自在自线福利| 国产一区二区视频在线| 国产精品中文字幕一区二区三区| 国产成人免费9x9x人网站视频| 成人三级伦理片| 91亚洲男人天堂| 欧美福利视频导航| 亚洲精品一区二区三区蜜桃下载 | 99精品视频中文字幕| 97超碰欧美中文字幕| 欧美专区在线观看一区| 日韩一区国产二区欧美三区| 欧美精品一区二区三区蜜桃视频| 中文字幕欧美区| 亚洲黄色在线视频| 日日夜夜免费精品| 精品视频资源站| 狠狠色丁香婷婷综合久久片| 一区二区三区精密机械公司| 亚洲电影一区二区| 精品一区中文字幕| 97久久精品人人澡人人爽| 欧美性做爰猛烈叫床潮| 亚洲精品在线一区二区| 综合中文字幕亚洲| 婷婷中文字幕综合| 国产不卡在线一区| 欧美色图天堂网| 国产欧美一区二区三区在线看蜜臀 | 欧美不卡一区二区| 中文字幕在线不卡| 美日韩一区二区| eeuss国产一区二区三区| 欧美群妇大交群中文字幕| 国产三级精品在线| 五月激情综合色| 国产精品99久久久久| 欧美日韩精品专区| 国产精品视频一二三区| 日本成人在线一区| 91麻豆产精品久久久久久| 日韩午夜三级在线| 一个色综合av| 国产成人av福利| 日韩欧美精品在线视频| 一区二区高清免费观看影视大全| 国产乱人伦精品一区二区在线观看| 91国产丝袜在线播放| jlzzjlzz亚洲日本少妇| 7777精品伊人久久久大香线蕉完整版 | 91精品国产综合久久福利| 国产精品久久久久久久久快鸭 | 一本大道久久精品懂色aⅴ| 欧美大尺度电影在线| 亚洲国产一二三| 91片在线免费观看| 欧美极品美女视频| 精品亚洲成a人| 欧美一区二区视频在线观看| 一区二区三区波多野结衣在线观看| 国产老肥熟一区二区三区| 欧美一级搡bbbb搡bbbb| 亚洲成人一区在线| 色94色欧美sute亚洲线路二 | 亚洲视频网在线直播| 国产丶欧美丶日本不卡视频| 国产精品一区二区三区网站| 欧美大片日本大片免费观看| 国产91在线看| 亚洲成a人片在线观看中文| 欧美一区二区三区不卡| 欧美理论在线播放| 一级女性全黄久久生活片免费| 成人黄页在线观看| 国产精品午夜在线观看| 国产福利视频一区二区三区| 精品国产露脸精彩对白| 久久精品72免费观看| 日韩一级大片在线观看| 琪琪一区二区三区| 欧美一级日韩一级| 麻豆91精品视频| 精品日韩成人av| 国产一区二区成人久久免费影院| 精品免费一区二区三区| 黄色日韩网站视频| 久久精品综合网| 国产成人av一区二区三区在线| 国产日韩精品视频一区| 国产a视频精品免费观看| 国产网站一区二区三区| 成人一级片网址| 自拍偷拍国产精品| 91精彩视频在线观看| 欧美午夜片在线观看| 日韩理论在线观看| 国产a久久麻豆| 亚洲欧洲日韩在线| 在线亚洲+欧美+日本专区| 亚洲一区二区视频| 欧美一级在线免费| 国产精品正在播放| 自拍视频在线观看一区二区| 欧美三级日韩在线| 麻豆精品国产91久久久久久| 国产色产综合色产在线视频| 99久久久久久99| 亚洲高清免费一级二级三级| 日韩视频在线观看一区二区| 国产一区二区主播在线| 国产精品伦理一区二区| 欧美午夜精品一区二区蜜桃| 偷偷要91色婷婷| 久久久欧美精品sm网站| 99r精品视频| 日韩精品成人一区二区三区 | 欧美日本一区二区| 国产乱色国产精品免费视频| 亚洲丝袜另类动漫二区| 欧美精品欧美精品系列| 国产宾馆实践打屁股91| 一个色妞综合视频在线观看| 日韩欧美资源站| av影院午夜一区| 蜜桃久久精品一区二区| 18欧美亚洲精品| 欧美成人aa大片| 91久久精品网| 国产一区二区在线观看视频| 一区二区三区中文字幕电影| 精品国偷自产国产一区| 色噜噜久久综合| 国产精品一区二区在线观看不卡 | 欧美一区二区人人喊爽| 从欧美一区二区三区| 亚洲一区二区三区爽爽爽爽爽| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 欧美视频自拍偷拍| 国产精品一区一区| 天堂午夜影视日韩欧美一区二区| 国产午夜精品一区二区三区视频| 欧美精品色综合| 91麻豆国产香蕉久久精品| 国产一区不卡在线| 日韩中文字幕一区二区三区| 中文字幕一区不卡|