- /*
- CH4226
- 电池包充电控制程序
- 2017/03/11
- */
- //头文件
- #include <hic.h>
- //全局变量
- unsigned char Cnt @0x3f;
- unsigned int ADV; //AD监测输出电压值
- unsigned int ADI; //AD监测输出电流值
- unsigned char COUNT;
- //标志位声明
- sbit t400ms_fg;
- //函数声明
- void delay(unsigned int n);
- unsigned int GetADC(unsigned char chl);
- void Sys_unit(void);
- //宏定义
- #define CLRWDT() __Asm CWDT
- //常量定义
- #define CurrentOpenLimit 60 //判定有充电电流限制值
- #define CurrentShutLimit 30 //判定没有充电电流限制值
- #define StopChargeLimit 2770 //判定停止充电电压限制值
- #define KongZaiLimit 2820 //判定进入空载限制值
- #define ChargeLimit 2730 //判定开始充电限制值
-
- void main()
- {
- unsigned char K0count,K1count,K2count,K3count,K4count,upcount,downcount; //状态标志位定义
- Sys_unit(); //初始化
- PA5=1; //开机红灯绿灯全灭
- PA4=1;
- PA1=0; //控制口置零
- delay(1000); //开机延时
- while(1)
- {
- ADV=GetADC(0); //将AD监测到的值
- ADI=GetADC(2);
-
-
- //判断当前状态
- ///*
- if( ADI > CurrentOpenLimit) //有充电电流
- {
- if((ADV-ADI)>StopChargeLimit) //且电池电压超过停止充电电压限制值,有电流时检流电阻存在压降进行补偿,电阻1.1欧姆
- {
- PA1=1; //停止充电,绿灯亮,红灯灭
- PA4=1;
- PA5=0;
- }
- else //且电池电压没有超过停止充电电压限制值
- {
- PA1=0; //红灯亮,不停止充电
- PA4=0;
- PA5=1;
- }
- }
- else if(ADI < CurrentShutLimit) //无充电电流
- {
- if(ADV > KongZaiLimit) //且电池电压达到空载限定值,判定进入空载
- {
- PA1=1; //停止充电,绿灯亮
- PA4=1;
- PA5=0;
- }
- else if(ADV<ChargeLimit) //且电池电压小于开始充电电压限定值
- {
- PA1=0; //开始充电,两灯皆灭
- PA4=1;
- PA5=1;
- }
- }
- //*/
- while(t400ms_fg == 0) CLRWDT(); //每4ms一个循环
- t400ms_fg = 0;
-
- }}
复制代码
|