去年做了一个89C52+ad0804的锂电池容量测试仪,没有成功,今年新买入了12C5A60S2,自带AD,开始着手再次制作。学习了很多论坛里高手的程序,由于水平有限,没有运用中断,只会利用1S延时,在开发板实验成功。放电可以仿照LM358电子负载+锂电池充电板,这样电路可以简单一些。
程序很简单,鉴于水平有限,如有问题还请各位多多指教。
- /*--------------------------------------------------------------*/
- #include <STC12C5A60S2.H>
- #include "LCD5510_V3.H"
- #include "STC12ADC.C"
- #define uint unsigned int
- #define uchar unsigned char
- #define ulong unsigned long
- //定义变量
- char a[10]={'0','1','2','3','4','5','6','7','8','9'};
- int dianya, ge, shi, bai, qian, c=800; //c设定最小电流
- float cap4=0, cap5=0, cap6=0, cap7=0;
- uint tims=0, cur;
- //ulong cap;
- /*--------------------------------------------------------------*/
- //时间显示函数
- void displaytime(uint dat)
- {
- uint tims1,tims2,timm1,timm2,timh; //定义秒1秒2,分1分2,时
- timh=dat/3600;
- timm2=(dat-timh*3600)/600;
- timm1=(dat-timh*3600)/60%10;
- tims2=(dat-timh*3600-timm2*600-timm1*60)/10;
- tims1=dat%10;
- LCD_prints(0, 5, "RUN");
- LCD_printc(7, 5, a[timh]);
- LCD_prints(8, 5, ":");
- LCD_printc(9, 5, a[timm2]);
- LCD_printc(10, 5, a[timm1]);
- LCD_prints(11, 5, ":");
- LCD_printc(12, 5, a[tims2]);
- LCD_printc(13, 5, a[tims1]);
- }
- /*
- //容量显示函数
- void displaycap(uint dat)
- {
- LCD_printc(8, 1, a[dat/1000]);
- LCD_printc(9, 1, a[dat/100%10]);
- LCD_printc(10, 1, a[dat/10%10]);
- LCD_printc(11, 1, a[dat%10]);
- }
- */
- //表头显示函数
- void displaybiaotou()
- {
- LCD_prints(0, 0, "No");
- LCD_prints(3, 0, "I-mA");
- LCD_prints(8, 0, "CY-mAH");
- LCD_prints(1, 1, "1");
- LCD_prints(1, 2, "2");
- LCD_prints(1, 3, "3");
- LCD_prints(1, 4, "4");
- }
- /*
- //5ms定时器中断函数
- void InitTimer0(void)
- {
- TMOD = 0x01;
- TH0 = 0x15;
- TL0 = 0x0A0;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- */
- //1S延时函数
- void delay1s(void) //误差 -0.000000000056us
- {
- uchar a,b,c,n;
- for(c=70;c>0;c--)
- for(b=168;b>0;b--)
- for(a=249;a>0;a--); //a=249,每10分钟快1秒;a=250,每6分钟慢1秒,每10分钟慢1.4秒
- for(n=1;n>0;n--);
- }
- void delay1ms(void) //误差 0us
- {
- unsigned char a,b;
- for(b=129;b>0;b--)
- for(a=45;a>0;a--);
- }
- //主函数
- void main()
- {
- LCD5510_Init(); //5110初始化
- Init_ADC(); //ADC初始化
- displaybiaotou(); //显示表头
-
- while(1)
- {
- uchar lu;
- for(lu=4;lu<8;)
- {
- Get_ADC_Result(lu); //开始转换
-
- //**********以下为放电电流显示语句*********************
- dianya = Count(lu)*1000;
- LCD_printn(3, lu-3, dianya, 5);
- //**********以下为电池容量语句*********************
- if(lu == 4)
- {
- if(dianya > c) //最小电流,假设电阻为1欧姆5W,电压与电流数值相同
- {
- cap4 = (float)dianya/3600 + cap4;
- }
- else
- {
- cap4 = cap4;
- }
- LCD_printn(8, lu-3, cap4, 4);
- }
- if(lu == 5)
- {
- if(dianya > c)
- {
- cap5 = (float)dianya/3600 + cap5;
- }
- else
- {
- cap5 = cap5;
- }
- LCD_printn(8, lu-3, cap5, 4);
- }
- if(lu == 6)
- {
- if(dianya > c)
- {
- cap6 = (float)dianya/3600 + cap6;
- }
- else
- {
- cap6 = cap6;
- }
- LCD_printn(8, lu-3, cap6, 4);
- }
- if(lu == 7)
- {
- if(dianya > c)
- {
- cap7 = (float)dianya/3600 + cap7;
- }
- else
- {
- cap7 = cap7;
- }
- LCD_printn(8, lu-3, cap7, 4);
- }
- lu++;
- }
-
- displaytime(tims);
- tims++;
- delay1s();
- delay1ms(); //加入延时,每10分钟慢0.6秒
- }
- }
复制代码
全部资料51hei下载地址:
5110锂电池容量测试仪.rar
(57.61 KB, 下载次数: 115)
|