Last year, I made a lithium battery capacity tester with 89C52+ad0804, but it was not successful. This year, I bought a new 12C5A60S2 with built-in AD, and started to make it again. I learned a lot of programs from experts in the forum. Due to my limited level, I did not use interrupts, but only used 1S delay. The experiment was successful on the development board. The discharge can imitate the LM358 electronic load + lithium battery charging board, so that the circuit can be simpler.
The program is very simple. Given my limited level, please feel free to give me your advice if you have any questions.
/*--------------------------------------------------------------*/
#include <STC12C5A60S2.H>
#include "LCD5510_V3.H"
#include "STC12ADC.C"
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
//Define variables
char a[10]={'0','1','2','3','4','5','6','7','8','9'};
int dianya, ge, shi, bai, qian, c=800; //c sets the minimum current
float cap4=0, cap5=0, cap6=0, cap7=0;
uint tims=0, cur;
//ulong cap;
/*--------------------------------------------------------------*/
//Time display function
void displaytime(uint dat)
{
uint tims1,tims2,timm1,timm2,timh; //define seconds 1 and 2, minutes 1 and 2, hours
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]);
}
/*
//Capacity display function
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]);
}
*/
//Header display function
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 timer interrupt function
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x15;
TL0 = 0x0A0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
*/
//1S delay function
void delay1s(void) //error -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, 1 second faster every 10 minutes; a=250, 1 second slower every 6 minutes, 1.4 seconds slower every 10 minutes
for(n=1;n>0;n--);
}
void delay1ms(void) //error 0us
{
unsigned char a,b;
for(b=129;b>0;b--)
for(a=45;a>0;a--);
}
//Main function
void main()
{
LCD5510_Init(); //5110 initialization
Init_ADC(); //ADC initialization
displaybiaotou(); //Display table header
while(1)
{
uchar lu;
for(lu=4;lu<8;)
{
Get_ADC_Result(lu); //Start conversion
//**********The following is the discharge current display statement*************************
dianya = Count(lu)*1000;
LCD_printn(3, lu-3, dianya, 5);
//**********The following is the battery capacity statement************************
if(lu == 4)
{
if(dianya > c) //minimum current, assuming the resistance is 1 ohm 5W, the voltage and current values are the same
{
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(); //Add delay, 0.6 seconds slower every 10 minutes
}
}
Previous article:PWM frequency generator
Next article:24c08 I2C bus protocol operation program assembly and C language 2 versions detailed explanation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Push-button start system power supply circuit
- Amplification issues of differential amplifiers
- New design approach improves smart meter performance
- How to view NPU clock power configuration and information for Allwinner V853 chip?
- USB PD fast charging communication principle
- [National Technology N32G430] 3. Timer
- How to obtain CCS License from TI
- The semiconductor industry is facing a cold winter. What do you think?
- How do I control AO3401?
- It was found that the build script of micropython converts the .py file into a c file and then compiles it.