📄 counter.c
字号:
#include "sfr_r81b.h"
#include "global.h"
#include "iic.h"
#include "serial.h"
#include "timex.h"
void counter_jdq_init(void)
{
pd1_0 = 1 ;
pd1_1 = 1 ;
start_sign = 0x00 ;
}
void change_array(uchar *p,unsigned long *change_power);
void counter_process_func(uint *power_counter_temp,uint eeprom_address,unsigned long *power_save_input,uchar *power_save_check_temp,uint meter_number_temp);
void counter_init(void)
{
uchar i ;
// IO.PCR7 &= 0x7f ;
// IO.PCR8 &= 0xfe ;
pd1_2 = 0 ;
pd3_4 = 1 ;
p3_4 = 1 ;
pd3_4 = 0 ;
counter_check_sign = 0 ;
counter_high = 0 ;
counter_data = 0 ;
counter_ok = 0 ;
power_counter = 0 ;
power_save = 0 ;
}
void counter_process(void)
{
unsigned long power_save_temp ;
unsigned long fu_power_save_temp ;
uchar i ;
uchar check_temp ;
if(counter_check_sign == 0x55)
{
counter_check_sign = 0xaa ;
counter_data++;
//if((counter_data<100)&&(counter_data>60))
if((counter_data<100)||(counter_data>60)) //gap: (60-100)*8.192ms=491-819.2ms
{
counter_high = 0x55 ;
}
/*
if(counter_data<100)
{
counter_high = 0x55 ;
}
else if(counter_data>60)
{
counter_high = 0x55 ;
}
*/
else if(counter_data > 150)
{
counter_data = 0x00 ;
counter_high = 0x00 ;
counter_check_sign = 0x00;
counter_ok = 0x00 ;
}
}
else if(counter_check_sign == 0x00)
{
if(counter_high == 0x55)
{
counter_ok = 0x55 ;
counter_high = 0x00 ;
counter_check_sign = 0x00;
counter_data = 0x00;
}
else
{
counter_ok = 0x00 ;
counter_high = 0x00 ;
counter_check_sign = 0x00;
counter_data = 0x00;
}
}
reset_wdt();
if(counter_ok == 0x55)
{
counter_ok = 0x00 ;
power_counter++ ;
if((power_counter%16)== 0x00)
{
if(start_sign == 0x00)
{
start_sign = 0x55 ;
}
}
if(p3_4 == 0)
{
fu_power_counter++ ;
}
counter_process_func(&fu_power_counter,fu_now_power,&fu_power_save,&fu_power_save_check,0x00);
reset_wdt();
counter_process_func(&power_counter,now_total_power,&power_save,&power_save_check,0x00);
}
}
void change_array(uchar *p,unsigned long *change_power)
{
uchar i ;
i = *change_power%10 ;
array_temp[0] = array_temp[0] + i*0x10;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[1] = i ;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[1] = array_temp[1] + i*0x10 ;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[2] = i ;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[2] = array_temp[2] + i*0x10 ;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[3] = i ;
*change_power = *change_power/10 ;
i = *change_power%10 ;
array_temp[3] = array_temp[3] + i*0x10 ;
}
void counter_process_func(uint *power_counter_temp,uint eeprom_address,unsigned long *power_save_input,uchar *power_save_check_temp,uint meter_number_temp)
{
unsigned long power_save_temp ;
uchar i ;
uchar check_temp ;
if(*power_counter_temp>=320)
{
*power_counter_temp = 0 ;
power_save_temp = *power_save_input ;
change_array(array_temp,&power_save_temp);
check_temp = array_temp[0] + array_temp[1] + array_temp[2] + array_temp[3] ;
if(check_temp == *power_save_check_temp)
{
(*power_save_input)++ ;
}
else
{
Read_EeprData(0xa1,array_temp,5,eeprom_address,0);
check_temp = array_temp[0] + array_temp[1] + array_temp[2] + array_temp[3] ;
if(check_temp == array_temp[4])
{
*power_save_check_temp = check_temp ;
change_ulong(array_temp,power_save_input);
(*power_save_input) ++ ;
}
else
{
Read_EeprData(0xa1,array_temp,5,eeprom_address,0);
check_temp = array_temp[0] + array_temp[1] + array_temp[2] + array_temp[3] ;
if(check_temp == array_temp[4])
{
*power_save_check_temp = check_temp ;
change_ulong(array_temp,power_save_input);
(*power_save_input) ++ ;
}
else
{
*power_save_input = 0x01 ;
*power_save_check_temp = 0x00;
}
}
}
array_temp[0] = 0x00 ;
array_temp[1] = 0x00 ;
array_temp[2] = 0x00 ;
array_temp[3] = 0x00 ;
power_save_temp = *power_save_input ;
change_array(array_temp,&power_save_temp);
check_temp = array_temp[0] + array_temp[1] + array_temp[2] + array_temp[3] ;
*power_save_check_temp = check_temp;//array_temp[0] + array_temp[1] + array_temp[2] + array_temp[3] ;
data_add(array_temp,4) ;
Write_eeprom_function(0xa0,array_temp,5 ,eeprom_address) ;
Write_eeprom_function(0xa2,array_temp,5 ,eeprom_address) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -