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

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

?? liion_bc_main.c

?? 基于單片機的鋰電池充電源代碼
?? 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一区二区三区免费野_久草精品视频
久久99精品国产麻豆婷婷| 色综合欧美在线| 99精品视频在线观看| 欧美精品色综合| 中文字幕亚洲视频| 国产在线一区二区综合免费视频| 色天天综合久久久久综合片| 欧美精品一区二区三区高清aⅴ| 自拍偷拍亚洲综合| 精品亚洲aⅴ乱码一区二区三区| 91激情五月电影| 国产精品久久久久四虎| 国产一区二区三区电影在线观看| 一本久久a久久精品亚洲| 国产日产亚洲精品系列| 国产精品自拍毛片| 在线观看视频91| 中文字幕中文字幕在线一区| 国产一区二区三区久久悠悠色av | 欧美精三区欧美精三区| 亚洲欧洲国产日韩| 成人伦理片在线| 日本一区二区视频在线观看| 久久精品国产亚洲高清剧情介绍 | 国模无码大尺度一区二区三区| 欧美日韩在线电影| 亚洲综合色视频| 色女孩综合影院| 亚洲欧美日韩中文播放 | 国产一区二区影院| 精品国产一二三| 激情小说欧美图片| 久久中文娱乐网| 国产在线视频不卡二| 久久综合久久鬼色中文字| 日本v片在线高清不卡在线观看| 欧美性大战久久久久久久蜜臀| 一区二区三区在线视频观看| 91欧美一区二区| 一个色妞综合视频在线观看| 日本二三区不卡| 午夜精品爽啪视频| 日韩一区二区三区电影在线观看 | 国产精品456露脸| 国产亚洲欧美日韩在线一区| 丁香天五香天堂综合| 中文字幕第一区综合| 91网站最新网址| 亚洲精品免费在线播放| 精品视频色一区| 蜜桃av一区二区在线观看| 久久网站最新地址| 成人午夜电影久久影院| 亚洲欧美经典视频| 欧美日本乱大交xxxxx| 蜜桃av噜噜一区| 国产午夜精品久久| eeuss鲁片一区二区三区在线看| 一区二区三区电影在线播| 7777精品伊人久久久大香线蕉完整版 | 精品国产91乱码一区二区三区| 国产乱人伦偷精品视频免下载| 国产精品传媒在线| 欧美一区二区三区四区五区 | 婷婷一区二区三区| 久久久久亚洲综合| 91久久精品日日躁夜夜躁欧美| 午夜精品久久久久久久久久久| 精品免费国产二区三区 | 国产成人av电影在线| 亚洲最新在线观看| 久久精品夜色噜噜亚洲a∨| 在线观看一区二区视频| 极品少妇一区二区三区精品视频| 自拍偷在线精品自拍偷无码专区| 日韩一区二区三区在线| 99re这里只有精品6| 久久91精品久久久久久秒播| 一区二区三区在线影院| 亚洲精品一区二区三区99 | 成人国产在线观看| 日本欧美大码aⅴ在线播放| 国产精品色一区二区三区| 91麻豆精品国产自产在线 | 国产伦精品一区二区三区视频青涩| 亚洲日韩欧美一区二区在线| 2023国产精品自拍| 欧美老肥妇做.爰bbww视频| 成人av电影在线网| 国产在线不卡视频| 免费看欧美女人艹b| 亚洲一区二区高清| 亚洲欧洲综合另类| 亚洲国产高清在线观看视频| 精品久久久久久无| 欧美精品丝袜久久久中文字幕| 91麻豆成人久久精品二区三区| 韩国欧美国产1区| 蜜桃视频一区二区| 免费不卡在线观看| 日韩精品成人一区二区在线| 亚洲影视资源网| 一区二区不卡在线播放| 亚洲欧美色综合| 亚洲天堂成人在线观看| 国产精品狼人久久影院观看方式| 久久天堂av综合合色蜜桃网| 日韩精品综合一本久道在线视频| 欧美一区二区性放荡片| 欧美日韩电影在线| 91麻豆精品久久久久蜜臀| 欧美片在线播放| 欧美一激情一区二区三区| 欧美日韩一二三区| 在线不卡免费av| 日韩丝袜美女视频| 精品少妇一区二区三区日产乱码 | 奇米精品一区二区三区在线观看一| 一个色妞综合视频在线观看| 伊人夜夜躁av伊人久久| 洋洋av久久久久久久一区| 亚洲成人av一区| 免费精品99久久国产综合精品| 日本午夜精品一区二区三区电影 | 精品国产成人在线影院 | 日韩一区和二区| 欧美不卡激情三级在线观看| 亚洲精品在线免费观看视频| 久久久99精品免费观看不卡| 日本一区二区三区电影| 亚洲欧美在线视频| 亚洲国产综合色| 麻豆国产91在线播放| 国产高清在线精品| 91蝌蚪porny成人天涯| 欧美日韩国产电影| 26uuu亚洲婷婷狠狠天堂| 国产精品丝袜久久久久久app| 亚洲青青青在线视频| 日本怡春院一区二区| 国产精品一品二品| 色8久久精品久久久久久蜜| 欧美日韩另类一区| 久久亚洲春色中文字幕久久久| 中文字幕精品—区二区四季| 夜夜揉揉日日人人青青一国产精品 | 制服丝袜日韩国产| 国产女人18毛片水真多成人如厕| 亚洲影院久久精品| 国产一区二区三区久久久| 91在线国内视频| 91精品欧美久久久久久动漫| 国产日韩视频一区二区三区| 亚洲国产精品久久人人爱| 国产精品中文字幕一区二区三区| 色综合久久中文综合久久牛| 欧美成人伊人久久综合网| 综合精品久久久| 精品一区二区在线免费观看| 色婷婷亚洲综合| 国产午夜精品福利| 婷婷综合在线观看| av在线不卡网| 久久亚洲影视婷婷| 丝袜美腿一区二区三区| 99久久精品费精品国产一区二区| 日韩欧美激情一区| 一区二区三区日本| 成人午夜在线视频| 日韩欧美的一区二区| 亚洲综合一区二区| 成人av在线播放网站| 欧美r级电影在线观看| 五月婷婷综合网| 色伊人久久综合中文字幕| 亚洲国产精品成人综合| 免费av成人在线| 欧美精品三级在线观看| 亚洲免费伊人电影| 处破女av一区二区| 久久久久国产精品厨房| 蜜臀久久久99精品久久久久久| 91黄色在线观看| 亚洲免费资源在线播放| 91影院在线免费观看| 国产日韩精品一区二区三区在线| 久久99精品久久久久久久久久久久| 欧美揉bbbbb揉bbbbb| 一片黄亚洲嫩模| 91黄色在线观看| 亚洲综合成人网| 日本电影欧美片| 亚洲综合图片区| 色老汉一区二区三区| 亚洲人成亚洲人成在线观看图片| 成人免费va视频| 成人欧美一区二区三区| 成人黄色小视频在线观看| 国产精品久久影院| 91麻豆免费观看|