#include "stc15.h"
#include "delay.h"
#include "timer.h"
#include "TM7707.h"
#include "LCD1602.h"
#include "eeprom.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#if (defined USE_TM7707)
#define TM_ADC_TO_VOLGATE?? ?1.49056e-4 //
#define TM_ADC_TO_CURRENT?? ?2.98023e-4
#elif (defined USE_TM7705)
#define TM_ADC_TO_VOLGATE?? ?3.81469e-2
#define TM_ADC_TO_CURRENT?? ?3.81469e-2
#endif
#define TM_VOLGATE_RATIO?? ?25
#define TM_REAL_VOLGATE?? ??? ?(TM_ADC_TO_VOLGATE*TM_VOLGATE_RATIO)
#define TM_REAL_CURRENT?? ??? ?(TM_ADC_TO_CURRENT)
static void System_Config(void);
static void ChoiceMode(void);
static unsigned char KeyScan(void);
unsigned char code releaseKey[15] = "Release key ? ?";
unsigned char code input0A[15] = "Input 0.000A ? ";
unsigned char code input5V[15] = "Input 5.000V ? ";
unsigned char code input3A[15] = "Input 3.000A ? ";
unsigned char code calibFinish[15] = "Finish ? ? ? ? ";
unsigned char code V_UP[2] = "V+";
unsigned char code V_DOWN[2] = "V-";
unsigned char code I_UP[2] = "A+";
unsigned char code I_DOWN[2] = "A-";
xdata float v_ratio=1.0f;
xdata float i_ratio=1.0f;
xdata long volgate=0;
xdata long current=0, i_offset=0;
xdata long power=0;
xdata long ohm=0;
xdata long AH=0;
xdata unsigned int timer_cnt=0;
xdata unsigned char dis_cnt=0;
xdata unsigned char sec=0;
xdata unsigned char min=0;
xdata unsigned char hour=0;
unsigned long sec_sum=0;
float ah_sec=0;
float ah_sum=0;
xdata unsigned char mode_flag=1;
xdata long mTemp=0;
bit isDisFlag=1;
bit isDisAhStop=1;
bit isUpdataAH = 0;
/***************************************************
*
*
*
*/
void main(void)
{
unsigned char keyCode=0;
System_Config();
LCD1602_Config();
Timer_Config();
TM770x_Config();
EA = 1;
ChoiceMode();
EA = 0;
mode_flag = IapReadByte(EEPROM_MODE_ADDR);
IapReadData(EEPROM_V_RATIO_ADDR, (long*)&volgate);
IapReadData(EEPROM_I_RATIO_ADDR, (long*)¤t);
IapReadData(EEPROM_I_ZERO_ADDR, (long*)&i_offset);
EA = 1;
v_ratio = volgate*1e-5;
i_ratio = current*1e-5;
if(mode_flag!=2 && mode_flag!=1)
{
mode_flag = 1;
IapSaveData(EEPROM_MODE_ADDR, (unsigned char*)&mode_flag, 1);
}
volgate = 0;
current = 0;
AH = 0;
LCD1602_Write(LCD_WR_CMD, 0x01);
delay_ms(10);
//?? ?volgate = 123456;
//?? ?DisplayNumber(0,0, volgate, 0xFF);
//?? ?DisplayTimer(hour,min,sec);
//?? ?while(1);
//?? ?mode_flag = 1;
for(;;)
{
keyCode = KeyScan();
if(keyCode==0)
{
if(mode_flag==2)
{
hour = 0;