control/main.c
2024-10-20 10:53:08 +09:00

3144 lines
96 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <mega128a.h>
#include <delay.h>
#include <stdint.h>
#include <control_header.h>
#include <stdio.h>
#define DATA_REGISTER_EMPTY (1<<UDRE0)
#define RX_COMPLETE (1<<RXC0)
#define FRAMING_ERROR (1<<FE0)
#define PARITY_ERROR (1<<UPE0)
#define DATA_OVERRUN (1<<DOR0)
// USART0 Receiver buffer
#define RX_BUFFER_SIZE0 8
static uint8_t rx_buffer0[RX_BUFFER_SIZE0];
#if RX_BUFFER_SIZE0 <= 256
static volatile uint8_t rx_wr_index0=0,rx_rd_index0=0;
#else
static volatile uint32_t rx_wr_index0=0,rx_rd_index0=0;
#endif
#if RX_BUFFER_SIZE0 < 256
static volatile uint8_t rx_counter0=0U;
#else
static volatile uint16_t rx_counter0=0U;
#endif
// This flag is set on USART0 Receiver buffer overflow
bit rx_buffer_overflow0;
interrupt [TIM0_OVF] void timer0_ovf_isr(void);
static void usart0_err_check(void)
{
err_info_1 = link_data_buffer[91];
err_info_2 = link_data_buffer[90];
if((err_info_1 & 0x80U) == 0x80U){ac_err = ERROR;}else{ac_err = NOR;}
if((err_info_1 & 0x40U) == 0x40U){gen_high_temp = ERROR;}else{gen_high_temp = NOR;}
if((err_info_1 & 0x20U) == 0x20U){gen_low_fuel = ERROR;}else{gen_low_fuel = NOR;}
if((err_info_1 & 0x10U) == 0x10U){batt1_temp_err = ERROR;}else{batt1_temp_err = NOR;}
if((err_info_1 & 0x08U) == 0x08U){batt1_ovp = ERROR;}else{batt1_ovp = NOR;}
if((err_info_1 & 0x04U) == 0x04U){batt1_ocp = ERROR;}else{batt1_ocp = NOR;}
if((err_info_1 & 0x03U) == 0x02U){batt1_charge = ON;}else{batt1_charge = OFF;}
if((err_info_1 & 0x03U) == 0x01U){batt1_discharge = ON;}else{batt1_discharge = OFF;}
if((err_info_2 & 0x80U) == 0x80U){gen_ovp = ERROR;}else{gen_ovp = NOR;}
if((err_info_2 & 0x40U) == 0x40U){gen_ocp = ERROR;}else{gen_ocp = NOR;}
if((err_info_2 & 0x20U) == 0x20U){gen_low_presure_err = ERROR;}else{gen_low_presure_err= NOR;}
if((err_info_2 & 0x10U) == 0x10U){batt2_temp_err = ERROR;}else {batt2_temp_err = NOR;}
if((err_info_2 & 0x08U) == 0x08U){batt2_ovp = ERROR;}else{batt2_ovp = NOR;}
if((err_info_2 & 0x04U) == 0x04U){batt2_ocp = ERROR;}else{batt2_ocp = NOR;}
if((err_info_2 & 0x03U) == 0x02U){batt2_charge = ON;}else{batt2_charge = OFF;}
if((err_info_2 & 0x03U) == 0x01U){batt2_discharge = ON;}else{batt2_discharge = OFF;}
if((gen_high_temp == ERROR)||(gen_ovp == ERROR)||(gen_ocp == ERROR)||(gen_low_presure_err == ERROR)){gen_state_err = ERROR;}else{gen_state_err = NOR;}
if(((err_info_1 & 0x1cU) == 0x00U)&&((err_info_2 & 0x1cU) == 0x00U)){batt_err = NOR;}else{batt_err = ERROR;}
if(init_delay_count == 0U)
{
if((err_info_1 & 0x03U) != 0x00U){batt_link_1_err = NOR;}else{batt_link_1_err = ERROR;}
if((err_info_2 & 0x03U) != 0x00U){batt_link_2_err = NOR;}else{batt_link_2_err = ERROR;}
}
else
{
batt_link_1_err = NOR;
batt_link_2_err = NOR;
}
err_ch_ovp_1 = link_data_buffer[89];
if((link_data_buffer[89] & 0x01U)== 0x01U){ac_temp_err = ERROR;}else{ac_temp_err = NOR;}
if((link_data_buffer[89] & 0x02U)== 0x02U){ac_fault_err = ERROR;}else{ac_fault_err = NOR;}
err_ch_ovp_2 = link_data_buffer[88];
err_ch_lvp_1 = link_data_buffer[87];
err_ch_lvp_2 = link_data_buffer[86];
err_ch_current_1 = link_data_buffer[85];
err_ch_current_2 = link_data_buffer[84];
ch_status_1 = link_data_buffer[83];
ch_status_2 = link_data_buffer[82];
temp = link_data_buffer[81];
if((temp & 0x80U)==0x80U){divider_limit_alram = ERROR;}else{divider_limit_alram = NOR;}
if((temp & 0x40U)==0x40U){divider_work_alram = ERROR;}else{divider_work_alram = NOR;}
if((temp & 0x20U)==0x20U){gen_limit_alram = ERROR;}else{gen_limit_alram = NOR;}
if((temp & 0x10U)==0x10U){gen_work_alram = ERROR;}else{gen_work_alram = NOR;}
if((temp & 0x08U) == 0x08U){gen_link_err = NOR;}else{gen_link_err = ERROR;}
}
static void usart0_gen_info(void)
{
//generator info
if((link_data_buffer[15] & 0x80U)==0x80U){gen_volt_sensor_err = ERROR;}else{gen_volt_sensor_err = NOR;}
if((link_data_buffer[15] & 0x40U)==0x40U){gen_current_sensor_err = ERROR;}else{gen_current_sensor_err = NOR;}
if((link_data_buffer[15] & 0x20U)==0x20U){gen_temp_sensor_err = ERROR;}else{gen_temp_sensor_err = NOR;}
if((link_data_buffer[15] & 0x10U)==0x10U){gen_fuel_level_sensor_err = ERROR;}else{gen_fuel_level_sensor_err = NOR;}
if((link_data_buffer[15] & 0x08U)==0x08U){gen_oil_presure_sensor_err = ERROR;}else{gen_oil_presure_sensor_err = NOR;}
if((link_data_buffer[15] & 0x02U)==0x02U){gen_start_fail = ERROR;}else{gen_start_fail = NOR;}
if((link_data_buffer[15] & 0x01U)==0x01U){gen_em_stop = ERROR;}else{gen_em_stop = NOR;}
if((gen_volt_sensor_err == ERROR)||(gen_current_sensor_err == ERROR)||(gen_temp_sensor_err == ERROR)||(gen_fuel_level_sensor_err == ERROR)||(gen_oil_presure_sensor_err == ERROR)||(gen_start_fail == ERROR)||(gen_em_stop == ERROR)){gen_sensor_err = ERROR;}else{gen_sensor_err = NOR;}
if((gen_sensor_err == ERROR)||(gen_state_err == ERROR)||(gen_limit_alram == ERROR)||(gen_work_alram == ERROR)){gen_err = ERROR;}else{gen_err = NOR;}
//battery
//batt1 temperature
temp = link_data_buffer[14];
batt_temperature_1 = temp;
if(link_data_buffer[13] > 0U)
{
batt_volt_1 = link_data_buffer[13];
}
else
{
batt_volt_1 = 0;
}
batt_current_1 = link_data_buffer[12];
batt_health_1 = link_data_buffer[11];
//batt2 temperature
temp = link_data_buffer[10];
batt_temperature_2 = temp;
if(link_data_buffer[9] > 0U)
{
batt_volt_2 = link_data_buffer[9];
}
else
{
batt_volt_2 = 0U;
}
}
// USART0 Receiver interrupt service routine
interrupt [USART0_RXC] void usart0_rx_isr(void) //(422)to
{
uint8_t status;
uint8_t data;
status=UCSR0A;
data=UDR0;
if (((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))) == 0)
{
rx_buffer0[rx_wr_index0++]=data;
#if RX_BUFFER_SIZE0 == 256U
// special case for receiver buffer size=256
if (++rx_counter0 == 0U) {rx_buffer_overflow0=1;}
#else
if (rx_wr_index0 == (uint8_t)RX_BUFFER_SIZE0){rx_wr_index0 = 0;}
if (++rx_counter0 == (uint8_t)RX_BUFFER_SIZE0)
{
rx_counter0=0U;
rx_buffer_overflow0=1;
}
#endif
}
//<2F><><EFBFBD><EFBFBD>
if((link_data_buffer[3] == 0xaaU)&&(link_data_buffer[2] == 0x55U))
{
i2c_add = (uint16_t) (link_data_buffer[1] * 256U) + link_data_buffer[0];
i2c_w_data = data;
i2c_write_act = 1;
link_data_buffer[3] = 0x00;
link_data_buffer[2] = 0x00;
link_data_buffer[1] = 0x00;
link_data_buffer[0] = 0x00;
}
//<2F>б<EFBFBD>
if((link_data_buffer[2] == 0xaaU)&&(link_data_buffer[1] == 0x00U))
{
i2c_add = (link_data_buffer[0] * 256U) + data;
i2c_read_act = 1;
link_data_buffer[2] = 0x00;
link_data_buffer[1] = 0x00;
link_data_buffer[0] = 0x00;
}
//<2F>б<EFBFBD> list
if((link_data_buffer[2] == 0xaaU)&&(link_data_buffer[1] == 0xaaU))
{
i2c_add = (link_data_buffer[0] * 256U) + data;
i2c_read_all_act = 1;
link_data_buffer[2] = 0x00;
link_data_buffer[1] = 0x00;
link_data_buffer[0] = 0x00;
}
if(data == 0x0aU)
{
//ä<>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD>
if((link_data_buffer[5] == 0x7fU) && (link_data_buffer[4] == 0xfeU) && (link_data_buffer[3] == 0x55U) && (link_data_buffer[0] == 0x0dU))
{
ch_status_1 = link_data_buffer[2];
ch_status_2 = link_data_buffer[1];
link_data_buffer[5] = 0;
link_data_buffer[4] = 0;
link_data_buffer[3] = 0;
link_data_buffer[2] = 0;
link_data_buffer[1] = 0;
link_data_buffer[0] = 0;
for(buff_loop = 0U;buff_loop < 6U;buff_loop++)
{
link_data_buffer[buff_loop] = 0U;
}
}
//<2F>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if((link_data_buffer[94] == 0x7fU) && (link_data_buffer[93] == 0xfeU) && (link_data_buffer[92] == 0x00U) && (link_data_buffer[0] == 0x0dU))
{
//err info
usart0_err_check();
switch(temp & 0x07U)
{
case 1:
mode = BATT;
break;
case 2:
mode = GEN;
break;
case 4:
mode = AC;
break;
default:
break;
}
// ä<>κ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
voltage_ch1 = ((uint16_t)link_data_buffer[80] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[79]); //v ch1 CS
currunt_ch1 = ((uint16_t)link_data_buffer[78] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[77]);
voltage_ch2 = ((uint16_t)link_data_buffer[76] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[75]); //v ch2 SW
currunt_ch2 = ((uint16_t)link_data_buffer[74] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[73]);
voltage_ch3 = ((uint16_t)link_data_buffer[72] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[71]); //v ch3 EX
currunt_ch3 = ((uint16_t)link_data_buffer[70] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[69]);
voltage_ch4 = ((uint16_t)link_data_buffer[68] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[67]); //v ch4 MAST
currunt_ch4 = ((uint16_t)link_data_buffer[66] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[65]);
voltage_ch5 = ((uint16_t)link_data_buffer[64] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[63]); //v ch5 OC1
currunt_ch5 = ((uint16_t)link_data_buffer[62] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[61]);
voltage_ch6 = ((uint16_t)link_data_buffer[60] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[59]); //v ch6 ST1
currunt_ch6 = ((uint16_t)link_data_buffer[58] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[57]);
voltage_ch7 = ((uint16_t)link_data_buffer[56] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[55]); //v ch7 MC
currunt_ch7 = ((uint16_t)link_data_buffer[54] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[53]);
voltage_ch8 = ((uint16_t)link_data_buffer[52] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[51]); //v ch5 NAVI
currunt_ch8 = ((uint16_t)link_data_buffer[50] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[49]);
voltage_ch9 = ((uint16_t)link_data_buffer[48] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[47]); //v ch6 SB
currunt_ch9 = ((uint16_t)link_data_buffer[46] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[45]);
voltage_ch10 = ((uint16_t)link_data_buffer[44] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[43]); //v ch7 OC2
currunt_ch10 = ((uint16_t)link_data_buffer[42] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[41]);
voltage_ch11 = ((uint16_t)link_data_buffer[40] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[39]); //v ch5 ST2
currunt_ch11 = ((uint16_t)link_data_buffer[38] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[37]);
voltage_ch12 = ((uint16_t)link_data_buffer[36] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[35]); //v ch6 GETC
currunt_ch12 = ((uint16_t)link_data_buffer[34] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[33]);
voltage_ch13 = ((uint16_t)link_data_buffer[32] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[31]); //v ch5 GC
currunt_ch13 = ((uint16_t)link_data_buffer[30] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[29]);
voltage_ch14 = ((uint16_t)link_data_buffer[28] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[27]); //v ch6 CNIC
currunt_ch14 = ((uint16_t)link_data_buffer[26] * (uint16_t)0x100U) + (uint16_t)(link_data_buffer[25]);
//ac
ac_volt = (link_data_buffer[24] * 256U) + link_data_buffer[23];
//generator
gen_rpm = link_data_buffer[22];
gen_volt = ((link_data_buffer[21]*256U)+ link_data_buffer[20]);
gen_current = (uint16_t)link_data_buffer[19];
gen_fuel = link_data_buffer[18];
gen_status = link_data_buffer[17];
gen_temp = link_data_buffer[16];
usart0_gen_info();
batt_current_2 = link_data_buffer[8];
batt_health_2 = link_data_buffer[7];
batt_fuel_1 = link_data_buffer[6];
batt_fuel_2 = link_data_buffer[5];
//batt1 info
if((link_data_buffer[4] & 0xC0U) == 0x00U)
{
batt1_status = DISCONNECT;
}
else
{
if((link_data_buffer[4] & 0xC0U)!= 0xc0U)
{
if((link_data_buffer[4] & 0x80U) == 0x80U){batt1_status = CHARGE;}
if((link_data_buffer[4] & 0x40U) == 0x40U){batt1_status = DISCHARGE;}
if((link_data_buffer[4] & 0x20U) == 0x20U){batt1_heater = ON;}else{batt1_heater = OFF;}
}
}
//batt2 info
if((link_data_buffer[4] & 0x0cU) == 0x00U)
{
batt2_status = DISCONNECT;
}
else
{
if((link_data_buffer[4] & 0x0cU)!= 0x0cU)
{
if((link_data_buffer[4] & 0x08U) == 0x08U){batt2_status = CHARGE;}
if((link_data_buffer[4] & 0x04U) == 0x04U){batt2_status = DISCHARGE;}
if((link_data_buffer[4] & 0x02U) == 0x02U){batt2_heater = ON;}else{batt2_heater = OFF;}
}
}
//source 4,3
voltage_source = (link_data_buffer[3] * 256U) + link_data_buffer[2];
//check sum
check_sum = link_data_buffer[1];
for(buff_loop = 0U;buff_loop < 95U;buff_loop++)
{
link_data_buffer[buff_loop] = 0;
}
}
}
for(link_buffer_count = 93U;link_buffer_count > 0U;link_buffer_count--)
{
link_data_buffer[link_buffer_count + 1U] = link_data_buffer[link_buffer_count];
}
link_data_buffer[1] = link_data_buffer[0];
link_data_buffer[0] = data;
loss_count = 0U; //<2F><>ũ <20><><EFBFBD><EFBFBD> Ȯ<>ο<EFBFBD>
}
// Get a character from the USART0 Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
uint8_t getchar(void)
{
uint8_t data;
while (rx_counter0==0){};
data=rx_buffer0[rx_rd_index0++];
#if RX_BUFFER_SIZE0 != 256
if (rx_rd_index0 == RX_BUFFER_SIZE0){ rx_rd_index0=0;}
#endif
#asm("cli")
--rx_counter0;
#asm("sei")
return data;
}
#pragma used-
// USART1 Receiver buffer
#define RX_BUFFER_SIZE1 8
uint8_t rx_buffer1[RX_BUFFER_SIZE1];
#if RX_BUFFER_SIZE1 <= 256
uint8_t rx_wr_index1=0,rx_rd_index1=0;
#else
unsigned int rx_wr_index1=0,rx_rd_index1=0;
#endif
#if RX_BUFFER_SIZE1 < 256
uint8_t rx_counter1=0;
#else
unsigned int rx_counter1=0;
#endif
// This flag is set on USART1 Receiver buffer overflow
bit rx_buffer_overflow1;
// USART1 Receiver interrupt service routine
interrupt [USART1_RXC] void usart1_rx_isr(void) //(422) to lan
{
uint8_t status;
uint8_t data;
status=UCSR1A;
data=UDR1;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0U)
{
rx_buffer1[rx_wr_index1++]=data;
#if RX_BUFFER_SIZE1 == 256U
// special case for receiver buffer size=256
if (++rx_counter1 == 0U) rx_buffer_overflow1=1U;
#else
if (rx_wr_index1 == RX_BUFFER_SIZE1) {rx_wr_index1=0;}
if (++rx_counter1 == RX_BUFFER_SIZE1)
{
rx_counter1=0U;
rx_buffer_overflow1=1;
}
#endif
}
for(lan_buffer_count = 93U;lan_buffer_count > 0U;lan_buffer_count--)
{
lan_data_buffer[lan_buffer_count + 1U] = lan_data_buffer[lan_buffer_count];
}
lan_data_buffer[1] = lan_data_buffer[0];
lan_data_buffer[0] = data;
//ä<>λ<EFBFBD><CEBB><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>û
if((lan_data_buffer[12] == 0x9bU)&&(lan_data_buffer[11] == 0x22U)&&(lan_data_buffer[10] == (uint8_t )mc_id)&&(lan_data_buffer[9] == (uint8_t )power_control_id)&&(lan_data_buffer[7] == 0x04U)&&(lan_data_buffer[6] == 0x03U)&&(lan_data_buffer[5] == 0x00U)&&(lan_data_buffer[4] == 0x00U)&&(lan_data_buffer[3] == 0x00U))
{
ch_sel_2 = lan_data_buffer[2]; //<2F><>Ʋ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> <20><><EFBFBD><EFBFBD> 240408
ch_sel_1 = lan_data_buffer[1];
if((lan_data_buffer[0] & 0x80U) == 0x80U) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD>
{
em_off_time = lan_data_buffer[0];
ch_sel_2 = 0x00;
ch_sel_1 = 0x00;
}
else
{
em_off_time = 0;
}
for(buff_loop = 0U;buff_loop < 13U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
power_manage_control_response_act = 1U;
ch_set_act = 1U;
}
//start_bit
if((lan_data_buffer[10] == 0x94U)&&(lan_data_buffer[9] == 0x22U)&&(lan_data_buffer[8] == (uint8_t )mc_id)&&(lan_data_buffer[7] == (uint8_t )power_control_id)&&(lan_data_buffer[5] == 0x04U)&&(lan_data_buffer[4] == 0x01U)&&(lan_data_buffer[3] == 0x00U)&&(lan_data_buffer[2] == 0x00U)&&(lan_data_buffer[1] == 0x00U)&&(lan_data_buffer[0] == 0x01U))
{
power_manage_start_response_act = 1U;
for(buff_loop = 0U;buff_loop < 11U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
}
//pbit
if((lan_data_buffer[9] == (uint8_t )PBIT)&&(lan_data_buffer[8] == 0x24U)&&(lan_data_buffer[7] == (uint8_t )mc_id)&&(lan_data_buffer[6] == (uint8_t )power_control_id)&&(lan_data_buffer[4] == 0x04U)&&(lan_data_buffer[3] == 0x00U)&&(lan_data_buffer[2] == 0x00U)&&(lan_data_buffer[1] == 0x00U)&&(lan_data_buffer[0] == 0x00U))
{
power_management_pbit_response_act = 1U;
for(buff_loop = 0U;buff_loop < 10U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
}
//detail pit
if((lan_data_buffer[10] == 0x9aU)&&(lan_data_buffer[9] == 0x24U)&&(lan_data_buffer[8] == mc_id)&&(lan_data_buffer[7] == power_control_id)&&(lan_data_buffer[5] == 0x04U)&&(lan_data_buffer[4] == 0x01U)&&(lan_data_buffer[3] == 0x00U)&&(lan_data_buffer[2] == 0x00U)&&(lan_data_buffer[1] == 0x00U)&&(lan_data_buffer[0] == 0x01U))
{
power_manage_detail_response_act = 1U;
for(buff_loop = 0U;buff_loop < 11U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
}
//detail cbit
if((lan_data_buffer[10] == 0x9aU)&&(lan_data_buffer[9] == 0x24U)&&(lan_data_buffer[8] == mc_id)&&(lan_data_buffer[7] == power_control_id)&&(lan_data_buffer[5] == 0x04U)&&(lan_data_buffer[4] == 0x01U)&&(lan_data_buffer[3] == 0x00U)&&(lan_data_buffer[2] == 0x00U)&&(lan_data_buffer[1] == 0x00U)&&(lan_data_buffer[0] == 0x00U))
{
power_manage_detail_response_act = 1U;
for(buff_loop = 0U;buff_loop < 11U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
}
//heart_bit
if((lan_data_buffer[10] == 0x92U)&&(lan_data_buffer[9] == 0x10U)&&(lan_data_buffer[8] == mc_id)&&(lan_data_buffer[7] == power_control_id)&&(lan_data_buffer[5] == 0x04U)&&(lan_data_buffer[4] == 0x01U)&&(lan_data_buffer[3] == 0x00U)&&(lan_data_buffer[2] == 0x00U)&&(lan_data_buffer[1] == 0x00U)&&(lan_data_buffer[0] == 0x00U))
{
lan_reset_count = 0;
for(buff_loop = 0U;buff_loop < 11U;buff_loop++)
{
lan_data_buffer[buff_loop] = 0U;
}
}
}
// Get a character from the USART1 Receiver buffer
#pragma used+
uint8_t getchar1(void)
{
uint8_t data;
while (rx_counter1==0U){};
data=rx_buffer1[rx_rd_index1++];
#if RX_BUFFER_SIZE1 != 256U
if (rx_rd_index1 == RX_BUFFER_SIZE1) {rx_rd_index1=0U;}
#endif
#asm("cli")
--rx_counter1;
#asm("sei")
return data;
}
#pragma used-
// Write a character to the USART1 Transmitter
#pragma used+
static void putchar1(uint8_t c)
{
while ((UCSR1A & DATA_REGISTER_EMPTY)==0U){};
UDR1 = c;
}
#pragma used-
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if(count_a >= 6274U) //100ms
{
count_a = 0U;
sec_count++;
}
else
{
count_a++;
}
}
static void header_stx(void)
{
putchar(0x7fU);
putchar(0xfeU);
}
static void header_eot(void)
{
putchar((uint8_t)0x0dU);
putchar((uint8_t)0x0aU);
}
static void power_divider_chset(void)
{
header_stx();
putchar((uint8_t)0x55U);//data set
ch_status_1 = 0U;
if((ch_sel_1 & 0x01U) == 0x01U){ch_status_1 |= 0x80U;} //cs
if((ch_sel_2 & 0x20U) == 0x20U){ch_status_1 |= 0x40U;} //sw
if((ch_sel_1 & 0x02U) == 0x02U){ch_status_1 |= 0x20U;} //rec
if((ch_sel_2 & 0x80U) == 0x80U){ch_status_1 |= 0x10U;} //mast
if((ch_sel_2 & 0x02U) == 0x02U){ch_status_1 |= 0x08U;} //oc1
if((ch_sel_2 & 0x04U) == 0x04U){ch_status_1 |= 0x04U;} //streeng1
if((ch_sel_2 & 0x01U) == 0x01U){ch_status_1 |= 0x02U;} //mc
if((ch_sel_2 & 0x40U) == 0x40U){ch_status_1 |= 0x01U;} //navi
putchar(ch_status_1);
ch_status_2 = 0;
ch_status_2 |= 0x80U; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if((ch_sel_2 & 0x08U) == 0x08U){ch_status_2 |= 0x40U;}
if((ch_sel_2 & 0x10U) == 0x10U){ch_status_2 |= 0x20U;}
ch_status_2 |= 0x10U; //ge
ch_status_2 |= 0x08U; //getc
if((ch_sel_1 & 0x04U) == 0x04U){ch_status_2 |= 0x04U;}
putchar((uint8_t)ch_status_2);//data channel 2
putchar((uint8_t)em_off_time);//reserve1
header_eot();
ch_set_act = 0U;
}
static void power_divider_request(void)
{
header_stx();
putchar(0x00U);//request
putchar(0x00U);//reserve1
putchar(0x00U);//reserve2
putchar(0x00U);//reserve3
header_eot();
ch_req_act = 0U;
}
static void lan_sn(void)
{
putchar1(sn_count);
if(sn_count >= 255U){sn_count = 0;}else{sn_count++;}
}
/********************
lan coounication
********************/
static void power_management_status_report1(void)
{
putchar1(0x90U);//1001 0000 message type
putchar1(0x03U);//00000011 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//00001000 TM
putchar1(0x2AU);//message length1
putchar1(0x00);//message length2
putchar1(0x00);//message length3
putchar1(0x00);//message length4
switch(mode)
{
case BATT:
temp_lan = 0x02U;
break;
case AC:
temp_lan = 0x01U;
break;
case GEN:
temp_lan = 0x00U;
break;
default:
temp_lan = 0x01U;
break;
}
putchar1((uint8_t)temp_lan);//source
temp_lan = 0;
if((ch_status_1 & 0x10U) == 0x10U){temp_lan |= 0x80U;} //<2F><><EFBFBD><EFBFBD>Ʈ
if((ch_status_1 & 0x01U) == 0x01U){temp_lan |= 0x40U;} //NAVI
if((ch_status_1 & 0x40U) == 0x40U){temp_lan |= 0x20U;} //SW
if((ch_status_2 & 0x20U) == 0x20U){temp_lan |= 0x10U;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
if((ch_status_2 & 0x40U) == 0x40U){temp_lan |= 0x08U;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
if((ch_status_1 & 0x04U) == 0x04U){temp_lan |= 0x04U;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
if((ch_status_1 & 0x08U) == 0x08U){temp_lan |= 0x02U;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
if((ch_status_1 & 0x02U) == 0x02U){temp_lan |= 0x01U;} //<2F>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
putchar1((uint8_t)temp_lan);
temp_lan = 0;
if((ch_status_2 & 0x04U)== 0x04U){temp_lan |= 0x04U;} //cnic
if((ch_status_1 & 0x20U)== 0x20U){temp_lan |= 0x02U;} //<2F><><EFBFBD>ϱ<EFBFBD>
if((ch_status_1 & 0x80U)== 0x80U){temp_lan |= 0x01U;} //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
putchar1((uint8_t)temp_lan);
temp_lan = gen_status;
putchar1((uint8_t)temp_lan);
if(batt_volt_1 == 0U){temp_lan = 0U;}else{temp_lan = batt_volt_1;}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 volt
}
static void power_management_sub_status_report1(void)
{
temp_lan = batt_current_1;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 current
temp_lan = batt_health_1;
if((batt1_charge == 1U)&&(batt1_discharge == 0U)){temp_lan |= 0x80U;}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 current
temp_lan = batt_fuel_1;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 level
temp_lan = batt_temperature_1;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 temperature
if(batt_volt_2 == 0U){temp_lan = 0U;}else{temp_lan = batt_volt_2;}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery2 volt
temp_lan = batt_current_2;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery2 current
temp_lan = batt_health_2;
if((batt2_charge == 1U)&&(batt2_discharge == 0U)){temp_lan |= 0x80U;}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery2 current
temp_lan = batt_fuel_2;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery2 level
temp_lan = batt_temperature_2;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery1 temperature
temp_lan = 0x00U;
if(batt1_heater == ON){temp_lan |= 0x08U;}
if(batt2_heater == ON){temp_lan |= 0x02U;}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//battery heater status
}
static void power_management_status_report2(void)
{
//1 mcu
if((voltage_ch7 < 150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch7 - 150U);}
putchar1((uint8_t)temp_lan);//mcu_power volt
temp_lan = (uint8_t)currunt_ch7;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//mcu_power current
//2
if((voltage_ch5 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch5 - 150U);}
putchar1((uint8_t)temp_lan);//opu1_power volt
temp_lan = (uint8_t)currunt_ch5;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//opu1_power current
//3
if((voltage_ch6 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch6 - 150U);}
putchar1((uint8_t)temp_lan);//ocu1_power volt
temp_lan = (uint8_t)currunt_ch6;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//ocu1_power current
//4
if((voltage_ch10 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch10 - 150U);}
putchar1(temp_lan);//opu2_power volt
temp_lan = (uint8_t)currunt_ch10;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//opu2_power current
//5
if((voltage_ch11 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch11 - 150U);}
putchar1(temp_lan);//ocu2_power volt
if(power_divider_link_err == ERROR){temp_lan = 0U;}
temp_lan = (uint8_t)currunt_ch11;
putchar1((uint8_t)temp_lan);//ocu2_power current
//6
if((voltage_ch1 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch1 - 150U);}
putchar1((uint8_t)temp_lan);//b_station_power volt
temp_lan = (uint8_t)currunt_ch1;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t )(temp_lan % 256U));//b_station_power current //<2F><>Ʋ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> <20><><EFBFBD><EFBFBD>
putchar1((uint8_t )(temp_lan / 256U));//b_station_power current
//7
if((voltage_ch4 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch4 - 150U);}
putchar1((uint8_t)temp_lan);//ant_mast_power volt
temp_lan = (uint8_t)currunt_ch4;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//ant_mast_power current
//8 NAVI
if((voltage_ch8 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch8 - 150U);}
putchar1((uint8_t)temp_lan);//navi_power volt
temp_lan = (uint8_t)currunt_ch8;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//navi_power current
// 9 record
if((voltage_ch3 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch3 - 150U);}
putchar1((uint8_t)temp_lan);//ins_power volt
temp_lan = (uint8_t)currunt_ch3;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//ins_power current
//10
if((voltage_ch2 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch2 - 150U);}
putchar1((uint8_t)temp_lan);//switch_power volt
temp_lan = (uint8_t)currunt_ch2;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//switch_power current
//11
if((voltage_ch14 <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(voltage_ch14 - 150U);}
putchar1((uint8_t)temp_lan);//cnic_power volt
temp_lan = (uint8_t)currunt_ch14;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//cnic_power current
//12 generator
if((gen_volt <150U)||(power_divider_link_err == ERROR)){temp_lan = 0U;}else{temp_lan = (uint8_t)(gen_volt - 150U);}
putchar1((uint8_t)temp_lan);//gen voltage
temp_lan = (uint8_t)gen_current;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//gen_current
if(gen_temp > 250U)
{
temp_lan = 255U;
}
else
{
temp_lan = (uint8_t)gen_temp + 5U;
}
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//gen_temp
temp_lan = (uint8_t)gen_rpm;
if(power_divider_link_err == ERROR){temp_lan = 0U;}
putchar1((uint8_t)temp_lan);//gen_rpm
power_management_status_report_act = 0U;
}
static void pbit_cbit(void)
{
if((err_ch_ovp_1 != 0x00U)||(err_ch_ovp_2 != 0x00U)||(err_ch_lvp_1 != 0x00U)||(err_ch_lvp_2 != 0x00U)||(err_ch_current_1 != 0x00U)||(err_ch_current_2 != 0x00U)||(ac_err == ERROR))
{divider_total_err = ERROR;}else{divider_total_err = NOR;}
if((gen_link_err == ERROR)||(batt_link_1_err == ERROR)||(batt_link_2_err == ERROR)||(power_divider_link_err == ERROR)||(divider_total_err == ERROR))
{comm_total_err = ERROR;}else{comm_total_err = NOR;}
if((gen_volt_sensor_err == ERROR)||(gen_high_temp == ERROR)||(gen_low_presure_err == ERROR)||(gen_ovp == ERROR)||
(gen_ocp == ERROR)||(gen_em_stop == ERROR)||(gen_start_fail == ERROR))
{gen_main_err = ERROR;}else {gen_main_err = NOR;}
if((gen_low_fuel == ERROR)||(gen_current_sensor_err == ERROR)||(gen_temp_sensor_err == ERROR)||(gen_fuel_level_sensor_err == ERROR)||(gen_oil_presure_sensor_err == ERROR))
{gen_sub_err = ERROR;}else {gen_sub_err = NOR;}
if((batt1_temp_err == ERROR)||(batt1_ovp == ERROR)||(batt1_ocp == ERROR)){batt1_total_err = ERROR;}else{batt1_total_err = NOR;}
if((batt2_temp_err == ERROR)||(batt2_ovp == ERROR)||(batt2_ocp == ERROR)){batt2_total_err = ERROR;}else{batt2_total_err = NOR;}
//cs-control status
temp_lan = 0;
//function
//batt and dividier err
if((batt1_total_err == ERROR)||(batt1_total_err == ERROR)||(divider_total_err == ERROR)){temp_lan |= 0x20U;}//NOT WORK
//gen err
if(gen_main_err == ERROR) //||(cs_comm_err == ERR) cs comm err
{
temp_lan |= 0x08U;
}
else
{
if(gen_sub_err == ERROR)
{
temp_lan |= 0x04U;
}
}
if((divider_total_err == ERROR)||(comm_total_err == ERROR)||(ac_fault_err == ERROR)||(ac_err == ERROR)){temp_lan |= 0x02U;}//notice
if(temp_lan != 0x00U)
{
if(((temp_lan & 0x30U) == 0x20U)||((temp_lan & 0x0cU) == 0x08U)||((temp_lan & 0x03U) == 0x02U))
{
temp_lan |= 0x80U;
}
else
{
temp_lan |= 0x40U;
}
}
putchar1((uint8_t)temp_lan);
//device
//cs-control status
temp_lan = 0;
//gen err
if((gen_main_err == ERROR)||(gen_sub_err == ERROR)){temp_lan |= 0x04U;}
//divider err
if((divider_total_err == ERROR)||(ac_temp_err == ERROR)){temp_lan |= 0x02U;}//notice
//control err
if((batt1_total_err == ERROR)||(batt2_total_err == ERROR)||(divider_total_err == ERROR)){temp_lan |= 0x01U;} //||cs_comm_err == ERR
if(temp_lan != 0x00U){temp_lan |= 0x10U;}
putchar1((uint8_t)temp_lan);//4: <20>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD> 3:<3A>ܺ<EFBFBD> <20><><EFBFBD>͸<EFBFBD>2, 2:<3A>ܺ<EFBFBD> <20><><EFBFBD>͸<EFBFBD>1 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0:<3A><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>
}
static void heart_bit_sent(void)
{
putchar1(0x92U);//1001 0010 message type
putchar1(0x10U);//0001 0000 message id
putchar1((uint8_t)power_control_id);//sou1 e unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//0010 0100 TM 240925 0x24 ->0x04<30><34> <20><><EFBFBD><EFBFBD> <20><>ȭ <20><>û <20><><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8>
putchar1(0x01U);//message length1 <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ȱ<><C8B0>ȭ
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
putchar1(0x00U);//message length1 HEART BIT RESERVE
}
static void power_management_pbit_response(void)
{
putchar1(0x98U);//1001 1000 message type
putchar1(0x34U);//0011 0100 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//00000100 TM
putchar1(0x02U);//message length1 <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ȱ<><C8B0> ȭ
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
//putchar1(0x02U);//message length1 <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20><> Ȱ<><C8B0> ȭ
pbit_cbit();
response_power_management_pbit_act_p = 0;
}
static void power_management_start_response(void)
{
putchar1(0x94U);//1001 1000 message type
putchar1(0x32U);//0011 0100 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x24U);//00000100 TM
putchar1(0x02U);//message length1 <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> Ȱ<><C8B0> ȭ
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
putchar1(0x01U);//device
putchar1(VERSION);//VERSION
response_power_manage_start_act_p = 0;
}
static void power_management_cbit_report(void)
{
putchar1(0x99);//10011001 message type
putchar1(0x04U);//00000200 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//00001000 TM
putchar1(0x02U);//message length1
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
pbit_cbit();
power_managementbit_cbit_report_act = 0;
}
static void power_managementbit_detail_response(void)
{
putchar1(0x9aU);//10011010 message type
putchar1(0x34U);//00110100 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//00000100 TM
putchar1(0x04U);//message length1
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
temp_lan = 0;// response pbit 1 cbit 0
putchar1((uint8_t)temp_lan);
//link
temp_lan = 0;
if(gen_link_err == ERROR){temp_lan |= 0x40U;}
if(batt_link_1_err == ERROR){temp_lan |= 0x20U;}
if(batt_link_2_err == ERROR){temp_lan |= 0x10U;}
if(power_divider_link_err == ERROR){temp_lan |= 0x08U;}
if(divider_total_err == ERROR){temp_lan |= 0x02U;}
putchar1((uint8_t)temp_lan);
// <20>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD> 3:<3A>ܺ<EFBFBD> <20><><EFBFBD>͸<EFBFBD>2, 2:<3A>ܺ<EFBFBD> <20><><EFBFBD>͸<EFBFBD>1 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0:<3A><><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><D0B9><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
temp_lan = 0;
if(gen_volt_sensor_err == ERROR){temp_lan |= 0x80U;}
if(gen_high_temp == ERROR){temp_lan |= 0x40U;}
if(gen_low_presure_err == ERROR){temp_lan |= 0x20U;}
if(gen_ovp == ERROR){temp_lan |= 0x10U;}
if(gen_ocp == ERROR){temp_lan |= 0x08U;}
if(gen_em_stop == ERROR){temp_lan |= 0x04U;}
if(gen_start_fail == ERROR){temp_lan |= 0x02U;}
putchar1((uint8_t)temp_lan);
/*
temp_lan = 0; <20><><EFBFBD>͸<EFBFBD>1 <20>ҷ<EFBFBD>
if(batt1_temp_err == ERR){temp_lan |= 0x04;}
if(batt1_ocp == ERR){temp_lan |= 0x02;}
if(batt1_ovp == ERR){temp_lan |= 0x01;}
putchar1((uint8_t)temp_lan); <20><><EFBFBD>͸<EFBFBD>1 <20>µ<EFBFBD>:2 <20><><EFBFBD><EFBFBD>:1 <20><><EFBFBD><EFBFBD>:0
temp_lan = 0; <20><><EFBFBD>͸<EFBFBD>2 <20>ҷ<EFBFBD>
if(batt2_temp_err == ERR){temp_lan |= 0x04;}
if(batt2_ocp == ERR){temp_lan |= 0x02;}
if(batt2_ovp == ERR){temp_lan |= 0x01;}
putchar1((uint8_t)temp_lan); <20><><EFBFBD>͸<EFBFBD>2 <20>µ<EFBFBD>:2 <20><><EFBFBD><EFBFBD>:1 <20><><EFBFBD><EFBFBD>:0
*/
temp_lan = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD>
if(gen_low_fuel == ERROR){temp_lan |= 0x80U;}
if(gen_current_sensor_err == ERROR){temp_lan |= 0x40U;}
if(gen_temp_sensor_err == ERROR){temp_lan |= 0x20U;}
if(gen_fuel_level_sensor_err == ERROR){temp_lan |= 0x10U;}
if(gen_oil_presure_sensor_err == ERROR){temp_lan |= 0x08U;}
putchar1((uint8_t)temp_lan);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޱ<EFBFBD> 0:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
response_power_manage_detail_act_p = 0;
}
static void power_management_control_response(void)
{
putchar1(0x9bU);//10011011 message type
putchar1(0x32U);//00110010 message id
putchar1((uint8_t)power_control_id);//source unit
putchar1((uint8_t)mc_id);//00110001 destination unit
lan_sn();//SN DATA <20><><EFBFBD><EFBFBD> 0 ~ 255 <20><>ȯ
putchar1(0x04U);//00000100 TM
putchar1(0x03U);//message length1
putchar1(0x00U);//message length2
putchar1(0x00U);//message length3
putchar1(0x00U);//message length4
// ch_sel_2 = lan_data_buffer[2]; //<2F><>Ʋ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> <20><><EFBFBD><EFBFBD> 240408
temp_lan = ch_sel_2;
putchar1((uint8_t)temp_lan);
temp_lan = ch_sel_1;
putchar1((uint8_t)temp_lan);
temp_lan = 0;
if((em_off_time & 0x80U)== 0x80U)
{
temp_lan = em_off_time & 0x7fU;
}
putchar1((uint8_t)temp_lan);
response_power_manage_control_act_p = 0;
}
static void pulse1(void)
{
delay_us(2);
LED_CLK1 = 1;
delay_us(2);
LED_CLK1 = 0;
}
static void pulse2(void)
{
delay_us(2);
LED_CLK2 = 1;
delay_us(2);
LED_CLK2 = 0;
}
static void pulse3(void)
{
delay_us(2);
LED_CLK3 = 1;
delay_us(2);
LED_CLK3 = 0;
}
static void fnd_display1(void)
{
//FND 1 CONTROL
LED_LOAD1 = 0;
delay_us(2);
LED_DIN1 = 1;
for(count_temp = 0U; count_temp <4U; count_temp++)
{
pulse1();
}
//command digit 3
if((command & 0x08U) == 0x08U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//command digit 2
if((command & 0x04U) == 0x04U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//command digit 1
if((command & 0x02U) == 0x02U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//command digit 0
if((command & 0x01U) == 0x01U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 7
if((fnd_data & 0x80U) == 0x80U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 6
if((fnd_data & 0x40U) == 0x40U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 5
if((fnd_data & 0x20U) == 0x20U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 4
if((fnd_data & 0x10U) == 0x10U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 3
if((fnd_data & 0x08U) == 0x08U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 2
if((fnd_data & 0x04U) == 0x04U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 1
if((fnd_data & 0x02U) == 0x02U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
//data digit 0
if((fnd_data & 0x01U) == 0x01U){LED_DIN1 = 1;} else{LED_DIN1 = 0;}
pulse1();
LED_DIN1 = 1;
delay_us(1);
LED_LOAD1 = 1;
delay_us(1);
}
static void fnd_display2(void)
{
//FND 2 CONTROL
LED_LOAD2 = 0;
delay_us(1);
LED_DIN2 = 1;
for(count_temp = 0U; count_temp <4U; count_temp++)
{
pulse2();
}
//command digit 3
if((command & 0x08U) == 0x08U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//command digit 2
if((command & 0x04U) == 0x04U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//command digit 1
if((command & 0x02U) == 0x02U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//command digit 0
if((command & 0x01U) == 0x01U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 7
if((fnd_data & 0x80U) == 0x80U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 6
if((fnd_data & 0x40U) == 0x40U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 5
if((fnd_data & 0x20U) == 0x20U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 4
if((fnd_data & 0x10U) == 0x10U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 3
if((fnd_data & 0x08U) == 0x08U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 2
if((fnd_data & 0x04U) == 0x04U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 1
if((fnd_data & 0x02U) == 0x02U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
//data digit 0
if((fnd_data & 0x01U) == 0x01U){LED_DIN2 = 1;} else{LED_DIN2 = 0;}
pulse2();
LED_DIN2 = 1;
delay_us(1);
LED_LOAD2 = 1;
delay_us(1);
}
static void fnd_display3(void)
{
//FND 3 CONTROL
LED_LOAD3 = 0;
delay_us(1);
LED_DIN3 = 1 ;
for(count_temp = 0U; count_temp <4U; count_temp++)
{
pulse1();
}
//command digit 3
if((command & 0x08U) == 0x08U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//command digit 2
if((command & 0x04U) == 0x04U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//command digit 1
if((command & 0x02U) == 0x02U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//command digit 0
if((command & 0x01U) == 0x01U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 7
if((fnd_data & 0x80U) == 0x80U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 6
if((fnd_data & 0x40U) == 0x40U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 5
if((fnd_data & 0x20U) == 0x20U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 4
if((fnd_data & 0x10U) == 0x10U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 3
if((fnd_data & 0x08U) == 0x08U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 2
if((fnd_data & 0x04U) == 0x04U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 1
if((fnd_data & 0x02U) == 0x02U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
//data digit 0
if((fnd_data & 0x01U) == 0x01U){LED_DIN3 = 1;} else{LED_DIN3 = 0;}
pulse3();
LED_DIN3 = 1;
delay_us(1);
LED_LOAD3 = 1;
delay_us(1);
}
static void num_convert(uint8_t num)
{
switch(num)
{
case 0:
fnd_data = 0x7eU;
break;
case 1:
fnd_data = 0x30U;
break;
case 2:
fnd_data = 0x6dU;
break;
case 3:
fnd_data = 0x79U;
break;
case 4:
fnd_data = 0x33U;
break;
case 5:
fnd_data = 0x5bU;
break;
case 6:
fnd_data = 0x5fU;
break;
case 7:
fnd_data = 0x70U;
break;
case 8:
fnd_data = 0x7fU;
break;
case 9:
fnd_data = 0x7bU;
break;
case 15:
fnd_data = 0xffU;
break;
default:
fnd_data = 0x00U;
break;
}
}
static void fnd_init(void)
{
LED_LOAD1 = HIGH;
LED_LOAD2 = HIGH;
LED_LOAD3 = HIGH;
// scan limit
command = 0x0bU;
fnd_data = 0x05U;
fnd_display1();
fnd_data = 0x03U;
fnd_display2();
fnd_data = 0x05U;
fnd_display3();
// intensity
command = 0x0aU;
fnd_data = 0x07U;
fnd_display1();
fnd_display2();
fnd_display3();
// decode mode
command = 0x09U;
fnd_data = 0x00U;
fnd_display1();
fnd_display2();
fnd_display3();
// shut down
command = 0x0cU;
fnd_data = 0x01U;
fnd_display1();
fnd_display2();
fnd_display3();
// fnd test normar
command = 0x0fU;
fnd_data = 0x00U;
fnd_display1();
fnd_display2();
fnd_display3();
LED_LOAD1 = LOW;
LED_LOAD2 = LOW;
LED_LOAD3 = LOW;
}
static void charge_work_display(void)
{
switch(charge_display_count)
{
case 0:
fnd_data = 0x48; //a 0x40
break;
case 1:
fnd_data = 0x24; //b 0x20
break;
case 2:
fnd_data = 0x12; //c 0x10
break;
default:
break;
}
}
static void digit_low_sub(uint8_t digit_num, uint8_t temp1)
{
switch(digit_num)
{
case 6://current 1
command = 0x01U;
num_convert(temp1);
fnd_display1();
break;
case 7: //fuel 100
command = 0x03;
if(gen_link_err == ERROR)
{
num_convert(0);
}
else
{
num_convert(temp1);
}
if(p_bit == 0U)
{
if(gen_err == ERROR)
{
fnd_data = 0x4FU;//"E"
}
else
{
if((gen_low_fuel == 1U)&&(sec_500ms == 1U)){fnd_data = 0x00U;} //1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> blank
}
}
fnd_display2();
break;
case 8: //fuel 10
command = 0x02;
if(gen_link_err == ERROR)
{
num_convert(0);
}
else
{
num_convert(temp1);
}
if(p_bit == 0U)
{
if(gen_err == ERROR)
{
fnd_data = 0x05U;//"r"
}
else
{
if((gen_low_fuel == 1U)&&(sec_500ms == 1U)){fnd_data = 0x00U;} //1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> blank
}
}
fnd_display2();
break;
case 9: //fuel 1
command = 0x01U;
if(gen_link_err == ERROR)
{
num_convert(0);
}
else
{
num_convert(temp1);
}
if(p_bit == 0U)
{
if(gen_err == ERROR)
{
fnd_data = 0x05U;//"r"
}
else
{
if((gen_low_fuel == 1U)&&(sec_500ms == 1U)){fnd_data = 0x00U;} //1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> blank
}
}
fnd_display2();
break;
case 10: //sco1 100
command = 0x06U;
if((batt_link_1_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt1_status == FAIL)
{
fnd_data = 0x4F;//"E"
}
else
{
if(batt1_heater == ON){fnd_data = 0x00U;}//" "
else
{
if((batt1_charge == 1U)&&(batt1_discharge == 0U)&&(fnd_soc1 < 100U)&&(mode != BATT))
{
charge_work_display();
}
else
{
if((batt1_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00U;}else{num_convert(temp1);}
}
}
}
}
}
fnd_display3();
break;
default:
command = 0x00U;
break;
}
}
static void digit_low(uint8_t digit_num, uint8_t temp1)
{
switch(digit_num)
{
case 1: //voltage 100
command = 0x06U;
num_convert(temp1);
fnd_display1();
break;
case 2: //voltage 10
command = 0x05U;
num_convert(temp1);
if(p_bit == 0U){fnd_data |= 0x80U;} ///<2F><><EFBFBD><EFBFBD>
fnd_display1();
break;
case 3: //voltage 1
command = 0x04U;
num_convert(temp1);
fnd_display1();
break;
case 4: //current 100
command = 0x03U;
num_convert(temp1);
fnd_display1();
break;
case 5: //current 10
command = 0x02U;
num_convert(temp1);
if(p_bit == 0U){fnd_data |= 0x80U;} ///<2F><><EFBFBD><EFBFBD>
fnd_display1();
break;
default:
command = 0x00U;
break;
}
}
static void digit_high_sub(uint8_t digit_num, uint8_t temp1)
{
switch(digit_num)
{
case 13: //sco2 100
command = 0x03;
if((batt_link_2_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt2_status == FAIL)
{
fnd_data = 0x4FU;//"E"
}
else
{
if(batt2_heater == ON){fnd_data = 0x00U;}//" "
else
{
if((batt2_charge == 1U)&&(batt2_discharge == 0U)&&(fnd_soc2 < 100U)&&(mode != BATT))
{
charge_work_display();
}
else
{
if((batt2_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00U;}else{num_convert(temp1);}
}
}
}
}
}
fnd_display3();
break;
case 14: //sco2 10
command = 0x02U;
if((batt_link_2_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt2_status == FAIL)
{
fnd_data = 0x05U;//"r"
}
else
{
if(batt2_heater == ON){fnd_data = 0x37U;}//"H"
else
{
if((batt2_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00U;}else{num_convert(temp1);}
}
}
}
}
fnd_display3();
break;
case 15: //sco2 1
command = 0x01U;
if((batt_link_2_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt2_status == FAIL)
{
fnd_data = 0x05U; //"r"
}
else
{
if(batt2_heater == ON){fnd_data = 0x0fU;}//"t"
else
{
if((batt2_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00U;}else{num_convert(temp1);}
}
}
}
}
fnd_display3();
break;
default:
command = 0x00U;
break;
}
}
static void digit_high(uint8_t digit_num, uint8_t temp1)
{
switch(digit_num)
{
case 11: //sco1 10
command = 0x05;
if((batt_link_1_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt1_status == FAIL)
{
fnd_data = 0x05U; //"r"
}
else
{
if(batt1_heater == ON){fnd_data = 0x37U;}//"H"
else
{
if((batt1_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00U;}else{num_convert(temp1);}
}
}
}
}
fnd_display3();
break;
case 12: //sco1
command = 0x04U;
if((batt_link_1_err == ERROR)||(power_divider_link_err == ERROR))
{
num_convert(0);
}
else
{
if(p_bit == 0U)
{
if(batt1_status == FAIL)
{
fnd_data = 0x05U;//"r"
}
else
{
if(batt1_heater == ON){fnd_data = 0x0fU;}//"t"
else
{
if((batt1_soc_low == ERROR)&&(sec_500ms == 1U)){fnd_data = 0x00;}else{num_convert(temp1);}
}
}
}
}
fnd_display3();
break;
default:
command = 0x00U;
break;
}
}
static void digit(uint8_t digit_num, uint8_t temp1)//,char num)
{
if(digit_num < 11U)
{
if(digit_num < 6U){digit_low(digit_num, temp1);}else{digit_low_sub(digit_num, temp1);}
}
else
{
if(digit_num < 13U){digit_high(digit_num, temp1);}else{digit_high_sub(digit_num, temp1);}
}
}
static void display_culculate( void)
{
//volt
if(fnd_voltage < 1000U)
{
digit(1,(uint8_t)(fnd_voltage/100U));
digit(2,(uint8_t)((uint8_t)(fnd_voltage % 100U) / 10U));
digit(3,(uint8_t)(fnd_voltage % 10U));
}
else
{
digit(1,10U);
digit(2,10U);
digit(3,10U);
}
//current
if(fnd_current < 1000U)
{
digit(4,(uint8_t)(fnd_current / 100U));
digit(5,(uint8_t)((uint8_t)(fnd_current % 100U) / 10U));
digit(6,(uint8_t)(fnd_current % 10U));
}
else
{
digit(4,10U);
digit(5,10U);
digit(6,10U);
}
;
//fuel
if(fnd_fuel <= 100U)
{
digit(7,(uint8_t)(fnd_fuel / 100U));
digit(8,(uint8_t)((uint8_t)(fnd_fuel % 100U)/ 10U));
digit(9,(uint8_t)(fnd_fuel % 10U));
}
else
{
digit(7,10U);
digit(8,10U);
digit(9,10U);
}
//soc1
if(fnd_soc1 <= 100U)
{
digit(10,(uint8_t) (fnd_soc1 / 100U));
digit(11,(uint8_t)((uint8_t) (fnd_soc1 % 100U)/10U));
digit(12,(uint8_t) (fnd_soc1 % 10U));
}
else
{
digit(10,10U);
digit(11,10U);
digit(12,10U);
}
//soc2
if(fnd_soc2 <= 100U)
{
digit(13,(uint8_t) (fnd_soc2/100U));
digit(14,(uint8_t)((uint8_t) (fnd_soc2%100U)/10U));
digit(15,(uint8_t) (fnd_soc2%10U));
}
else
{
digit(13,10U);
digit(14,10U);
digit(15,10U);
}
}
static void display(void)
{
// LED <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(power_divider_link_err == ERROR)
{
fnd_voltage = 0U;
fnd_current = 0U;
display_culculate();
fnd_soc1 = 0U;
fnd_soc2 = 0U;
fnd_fuel = 0U;
LED_AC = OFF;
LED_GEN = OFF;
LED_BATT = OFF;
}
else
{
switch(mode)
{
case AC:
if(ac_err == ERROR)
{
if(sec_100ms == 1U){LED_AC = ON;}else{LED_AC = OFF;}
}
else
{
LED_AC = ON;
}
LED_GEN = OFF;
LED_BATT = OFF;
fnd_fuel = gen_fuel;
mode_sw_err = 0U;
break;
case GEN:
LED_AC = OFF;
if(gen_link_err == ERROR)
{
if(sec_500ms == 1U){LED_GEN = ON;}else{LED_GEN = OFF;}
}
else
{
if(gen_err == ERROR)
{
if(sec_100ms == 1U){LED_GEN = ON;}else{LED_GEN = OFF;}
}
else
{
LED_GEN = ON;
}
}
LED_BATT = OFF;
fnd_fuel = gen_fuel;
mode_sw_err = 0U;
break;
case BATT:
LED_AC = OFF;
LED_GEN = OFF;
if((batt_link_1_err == ERROR)||(batt_link_2_err == ERROR))
{
if(sec_500ms == 1U){LED_BATT = ON;}else{LED_BATT = OFF;}
}
else
{
if((batt_err == ERROR)||(batt1_status == FAIL)||(batt2_status == FAIL))
{
if(sec_100ms == 1U){LED_BATT = ON;}else{LED_BATT = OFF;}
}
else
{
LED_BATT = ON;
}
}
fnd_fuel = gen_fuel;
mode_sw_err = 0U;
break;
default:
LED_AC = OFF;
LED_GEN = OFF;
LED_BATT = OFF;
fnd_fuel = gen_fuel;
mode_sw_err = 1U;
break;
}
fnd_voltage = voltage_source;
current_sum = currunt_ch1 + currunt_ch2 + currunt_ch3 + currunt_ch4 + currunt_ch5 + currunt_ch6 + currunt_ch7 + currunt_ch8 +
currunt_ch9 + currunt_ch10 + currunt_ch11 + currunt_ch12 + currunt_ch13 + currunt_ch14;
fnd_current = current_sum;
display_culculate();
//soc battery charge level
fnd_soc1 = batt_fuel_1;
fnd_soc2 = batt_fuel_2;
if(init_delay_count == 0U)
{
if(fnd_soc1 < 15U){batt1_soc_low = ERROR;}
if(fnd_soc2 < 15U){batt2_soc_low = ERROR;}
if(fnd_soc1 >= 20U){batt1_soc_low = NOR;}
if(fnd_soc2 >= 20U){batt2_soc_low = NOR;}
}
else
{
batt1_soc_low = NOR;
batt2_soc_low = NOR;
}
}
}
static void buzzer_check(void)
{
//<2F><><EFBFBD><EFBFBD> <20>ϳ<EFBFBD><CFB3><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><E6BAB8> <20>˶<EFBFBD> <20>
if((power_divider_link_err == ERROR)||(gen_link_err == ERROR)||(batt_link_1_err == ERROR)||(batt_link_2_err == ERROR)||((err_info_1 & 0XFCU)!= 0U)||
((err_info_2 & 0XFCU)!= 0U)||(err_ch_ovp_1 != 0U)||(err_ch_ovp_2 != 0U)||(err_ch_lvp_1 != 0U)||(err_ch_lvp_2 != 0U)||(err_ch_current_1 != 0U)||
(err_ch_current_2 != 0U)||(gen_err == ERROR)||(gen_sensor_err == ERROR)||(batt1_soc_low == ERROR)||(batt2_soc_low == ERROR)){alram_count_flag = 1;}else{alram_count_flag = 0;}
if(alram_count >= ALRAM_COUNT_MAX){alram = 1U;}else{alram = 0U;}
if(alram == 1U)
{
if(buzzer_act == 0U)
{
buzzer_act = 1U;
}
}
else
{
buzzer_stop_act = 0U;
buzzer_act = 0U;
}
if(buzzer_act == 1U)
{
if(BUZZER_STOP_SW == 0U)
{
if((buzzer_act == 1U)&&(buzzer_stop_act == 0U))
{
buzzer_stop_act = 1U;
}
}
}
if((buzzer_act == 1U)&&(buzzer_stop_act == 0U))
{
buzzer_work = 1U;
}
else
{
buzzer_work = 0U;
}
if(buzzer_work == 1U)
{
BUZZER = ON;
}
else
{
BUZZER = OFF;
}
if(BUZZER_STOP_SW == 0U)
{
buzzer_press = 1U;
}
else
{
buzzer_press = 0U;
}
}
static void buzzer_pulse_one(void)
{
BUZZER = ON;
delay_ms(10);
BUZZER = OFF;
}
static void display_p_bit(void)
{
p_bit = 1U;
for(loop = 0U; loop < 2U; loop++)
{
LED_AC = ON;
LED_GEN = ON;
LED_BATT = ON;
for(fnd_digit_loop = 1U;fnd_digit_loop <16U;fnd_digit_loop++)
{
digit(fnd_digit_loop,0x0fU); //ȭ<><C8AD> <20><>ü full +
}
delay_ms(500);
LED_AC = OFF;
LED_GEN = OFF;
LED_BATT = OFF;
for(fnd_digit_loop = 1U;fnd_digit_loop <16U;fnd_digit_loop++)
{
digit(fnd_digit_loop,0x0aU); //ȭ<><C8AD> <20><>ü full
}
delay_ms(500);
}
fnd_voltage = 0U;
fnd_current = 0U;
fnd_fuel = 0U;
fnd_soc1 = 0U;
fnd_soc2 = 0U;
display();
if(p_bit == 1U){p_bit = 0U;}
}
static void i2c_pulse(void)
{
SW_LAN_SCL = 0U;
delay_us(30);
SW_LAN_SCL = 1U;
delay_us(30);//30
SW_LAN_SCL = 0U;
delay_us(30);
}
static void i2c_start_sw(void)
{
DDRE.7 = 1U;
SW_LAN_SDI = 1U;
SW_LAN_SCL = 1U;
delay_us(40);
DDRE.7 = 1U;
SW_LAN_SDI = 0U;
delay_us(40);
DDRE.7 = 1U;
SW_LAN_SCL = 0U;
delay_us(40);
}
static void i2c_stop_sw(void)
{
SW_LAN_SDI = 0U;
SW_LAN_SCL = 0U;
delay_us(40);
SW_LAN_SCL = 1U;
delay_us(40);
SW_LAN_SDI = 1U;
delay_us(40);
}
static void sw_head(void)
{
//TOUCH ADDRESS
//BC, B8, B4
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 0U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
//CHIP ID 0x
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
//WRITE 0
SW_LAN_SDI = 0U;
i2c_pulse();
delay_us(10);
DDRE.7 = 0U;
delay_us(50);
i2c_pulse();
DDRE.7 = 1U;
delay_us(50);
}
static void sw_head_r(void)
{
//BC, B8, B4
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 0U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
//CHIP ID 0xb4
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 1U;
i2c_pulse();
//read 1
SW_LAN_SDI = 1U;
i2c_pulse();
SW_LAN_SDI = 0U;
delay_us(10);
DDRE.7 = 0U;
delay_us(50);
i2c_pulse();
DDRE.7 = 1U;
delay_us(50);
}
static void sw_lan_cont_r(uint16_t temp_sw_add)
{
i2c_start_sw();
delay_us(10);
sw_head();
// //command digit 3
if((temp_sw_add & 0x8000U) == 0x8000U){ SW_LAN_SDI = 1U;} else { SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x4000U) == 0x4000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x2000U) == 0x2000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x1000U) == 0x1000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 3
if((temp_sw_add & 0x0800U) == 0x0800U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0400U) == 0x0400U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0200U) == 0x0200U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0100U) == 0x0100U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
delay_us(10);
DDRE.7 = 0;
//ACK
delay_us(10);
i2c_pulse();
DDRE.7 = 1;
delay_us(10);
// //command digit 3
if((temp_sw_add & 0x0080U) == 0x0080U){ SW_LAN_SDI = 1U;} else { SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0040U) == 0x0040U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0020U) == 0x0020U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0010U) == 0x0010U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 3
if((temp_sw_add & 0x0008U) == 0x0008U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0004U) == 0x0004U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0002U) == 0x0002U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0001U) == 0x0001U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
delay_us(10);
DDRE.7 = 0U;
//ACK
delay_us(10);
i2c_pulse();
DDRE.7 = 1U;
delay_us(10);
//data read
i2c_stop_sw();
delay_us(10);
delay_us(100);
i2c_start_sw();
sw_head_r();
delay_us(10);
SW_LAN_SDI = 0U;
DDRE.7 = 0U;
delay_us(100);
temp_sw = 0x00U;
//data digit 7
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 6
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1U;
i2c_pulse();
//data digit 5
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 4
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 3
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 2
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 1
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
temp_sw = temp_sw << 1;
i2c_pulse();
//data digit 0
if((SW_LAN_SDI_IN) == 1U)
{
temp_sw = temp_sw + 0x01U;
}
i2c_pulse();
delay_us(10);
i2c_pulse();
delay_us(10);
DDRE.7 = 1;
delay_us(10);
SW_LAN_SDI = 0;
delay_us(10);
i2c_stop_sw();
delay_us(10);
sw_result = temp_sw;
putchar(sw_result);
}
//sw control
static void sw_lan_cont(uint16_t temp_sw_add, uint8_t temp_sw_data)
{
i2c_start_sw();
delay_us(1);
sw_head();
// //command digit 3
if((temp_sw_add & 0x8000U) == 0x8000U){ SW_LAN_SDI = 1U;} else { SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x4000U) == 0x4000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x2000U) == 0x2000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x1000U) == 0x1000U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 3
if((temp_sw_add & 0x0800U) == 0x0800U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0400U) == 0x0400U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0200U) == 0x0200U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0100U) == 0x0100U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
SW_LAN_SDI = 0;
delay_us(10);
DDRE.7 = 0;
//ACK
delay_us(50);
i2c_pulse();
DDRE.7 = 1;
delay_us(50);
// //command digit 3
if((temp_sw_add & 0x0080U) == 0x0080U){ SW_LAN_SDI = 1U;} else { SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0040U) == 0x0040U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0020U) == 0x0020U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0010U) == 0x0010U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 3
if((temp_sw_add & 0x0008U) == 0x0008U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 2
if((temp_sw_add & 0x0004U) == 0x0004U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 1
if((temp_sw_add & 0x0002U) == 0x0002U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//command digit 0
if((temp_sw_add & 0x0001U) == 0x0001U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
SW_LAN_SDI = 0;
delay_us(10);
DDRE.7 = 0;
//ACK
delay_us(50);
i2c_pulse();
DDRE.7 = 1;
delay_us(50);
//data digit 7
if((temp_sw_data & 0x80U) == 0x80U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 6
if((temp_sw_data & 0x40U) == 0x40U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 5
if((temp_sw_data & 0x20U) == 0x20U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 4
if((temp_sw_data & 0x10U) == 0x10U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 3
if((temp_sw_data & 0x08U) == 0x08U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 2
if((temp_sw_data & 0x04U) == 0x04U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 1
if((temp_sw_data & 0x02U) == 0x02U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
//data digit 0
if((temp_sw_data & 0x01U) == 0x01U){ SW_LAN_SDI = 1U;} else{ SW_LAN_SDI = 0U;}
i2c_pulse();
SW_LAN_SDI = 0;
delay_us(50);
DDRE.7 = 0;
//ACK
delay_us(50);
i2c_pulse();
delay_us(50);
DDRE.7 = 1;
delay_us(50);
i2c_stop_sw();
delay_us(10);
putchar((uint8_t)(temp_sw_add / 256U));
putchar((uint8_t)(temp_sw_add % 256U));
putchar((uint8_t)temp_sw_data);
}
static void sw_list(void)
{
static uint16_t tt_count = 0;
for( tt_count = i2c_add ;tt_count < (i2c_add + 100U);tt_count++)
{
sw_lan_cont_r(tt_count);
}
}
static void lan_reset_work(void)
{
DDRE=(1<<DDE5); //LED 1_0<5F><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȯ
SW_LAN_SPEED_D_0_SET = 0;
RESET_N = HIGH;
delay_ms(200);
RESET_N = LOW;
delay_ms(200);
RESET_N = HIGH;
DDRE=(0<<DDE5); //LED 1_0<5F><30> <20>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD> <20><>ȯ
}
static void main_time_sub(void)
{
// make 1sec
if(sec_count >= 1U)
{
if(sec_100ms == 0U){sec_100ms = 1U;}else{sec_100ms = 0U;}
sec_count = 0;
count_b++;
ch_req_act = 1U;
fnd_init();
display();
if(sw_up_link_count >= 20U){ sw_up_link_count = 20U;}else{sw_up_link_count++;}
if(alram_count_flag == ERROR)
{
if(alram_count >= ALRAM_COUNT_MAX){alram_count = ALRAM_COUNT_MAX;}else{alram_count++;}
}
else
{
alram_count = 0;
}
if(init_delay_count > 0U){init_delay_count--;}
if(lan_reset_count < 100U)
{
lan_reset_count++;
}
if(lan_reset_count >= 100U)
{
lan_reset_count = 0;
lan_reset_work();
}
if(count_sent_time == 0U){if(power_management_status_report_act == 0U){power_management_status_report_act = 1U;}}
if(count_sent_time == 1U)
{
if(power_manage_start_response_act == 1U)
{
power_manage_start_response_act = 0;
if(response_power_manage_start_act_p == 0U){response_power_manage_start_act_p = 1U;}
}
}
if(count_sent_time == 2U)
{
if(power_management_pbit_response_act == 1U)
{
power_management_pbit_response_act = 0U;
if(response_power_management_pbit_act_p == 0U){response_power_management_pbit_act_p = 1;}
}
}
if(count_sent_time == 3U)
{
if(power_manage_detail_response_act == 1U)
{
power_manage_detail_response_act = 0;
if(response_power_manage_detail_act_p == 0U){response_power_manage_detail_act_p = 1U;}
}
}
if(count_sent_time == 4U){if(power_management_status_report_act == 0U){power_managementbit_cbit_report_act = 1U;}}
if(count_sent_time == 6U){if(heart_bit_sent_act == 0U){heart_bit_sent_act = 1U;}}
if(count_sent_time == 8U)
{
if(power_manage_control_response_act == 1U)
{
power_manage_control_response_act = 0;
if(response_power_manage_control_act_p == 0U){response_power_manage_control_act_p = 1;}
}
}
if(count_sent_time >= 9U){count_sent_time = 0;}else{count_sent_time++;}
}
}
static void main_time(void)
{
if(count_b >= 4U)
{
count_b = 0;
count_c++;
if(sec_500ms == 1U)
{
sec_500ms = 0U;
}
else
{
sec_500ms = 1U;
}
if(charge_display_count < 2U){charge_display_count++;}else{charge_display_count = 0U;} //5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ȸ<><C8B8> ǥ<>ÿ<EFBFBD>
}
main_time_sub();
if(count_c >= 2U)
{
count_c = 0U;
if(power_divider_link_err == LINK )
{
if(loss_count < 4U)
{
loss_count++;
}
else
{
loss_count = 4U;
}
}
if(loss_count >= 2U){ power_divider_link_err = ERROR;}else{power_divider_link_err = NOR;}
if(sec_1000ms == 1U){sec_1000ms = 0U;}else{sec_1000ms = 1U;}
//<2F><>ü ä<><C3A4> <20><><EFBFBD><EFBFBD> <20><> 5<><35><EFBFBD>̻<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ü ü<><C3BC> <20>ʱ<EFBFBD>ȭ ó<><C3B3>
if(buzzer_press == 1U)
{
if(buzzer_press_count >= 5U)
{
buzzer_press_count = 5U;
if(buzzer_press_act == 0U)
{
buzzer_press_act = 1U;
ch_sel_1 = 0xff;
ch_sel_2 = 0xff;
buzzer_pulse_one();
ch_set_act = 1U;
}
}
else
{
buzzer_press_count++;
}
}
else
{
buzzer_press_count = 0U;
buzzer_press_act = 0U;
}
}
if(sec_100ms == 1U)
{
LED_HEALTH = ON;
}
else
{
LED_HEALTH = OFF;
}
}
static void init(void)
{
delay_ms(100);
DDRE=(1<<DDE5); //LED 1_0<5F><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȯ
SW_LAN_SPEED_D_0_SET = 0;
LAN_ISP = HIGH;
RESET_N = HIGH;
LAN_RESET = HIGH;
delay_ms(500);
RESET_N = LOW;
delay_ms(10);
DDRE=(0<<DDE5); //LED 1_0<5F><30> <20>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD> <20><>ȯ
LAN_RESET = LOW;
delay_ms(500);
fnd_init();
LAN_RESET = HIGH;
RESET_N = HIGH;
display_p_bit();
SW_LAN_SDI = 0;
SW_LAN_SCL = 0;
SW_LAN_SCS_N = 0;
SW_LAN_TX_EN = 0;
SW_LAN_TX_ER = 0;
ch_sel_1 = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ұ<EFBFBD>
ch_sel_2 = 0;
power_divider_link_err = NOR;
batt_err = NOR;
gen_err = NOR;
rx_wr_index0=0;
rx_rd_index0=0;
sw_lan_cont(0x0334, 0x01);
delay_ms(10);
sw_lan_cont(0x0300, 0x01);
delay_ms(10);
sw_lan_cont(0x2112, 0x04);
delay_ms(10);
count_a = 0;
count_b = 0;
count_c = 0;
charge_display_count = 0;
init_delay_count = 50U;
lan_reset_count = 0;
count_temp = 0;
sec_count = 0;
fnd_digit_loop = 0;
count_sent_time = 0;
//TEMP
loop = 0;
buff_loop = 0;
link_buffer_count = 0;
lan_buffer_count = 0;
//mode
mode = 0;// AC:0/GEN:1/BATT:2 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//err
mode_sw_err = 0; //mode_Switch <20>ҷ<EFBFBD><D2B7><EFBFBD> 1
power_divider_link_err = 0;
batt_link_1_err = 0;
batt_link_2_err = 0;
batt_err = 0;
gen_link_err = 0;
gen_err = 0;
err_info_1 = 0;
err_info_2 = 0;
err_ch_ovp_1 =0;
err_ch_ovp_2= 0;
err_ch_lvp_1 =0;
err_ch_lvp_2= 0;
err_ch_current_1= 0;
batt1_soc_low = 0;
batt2_soc_low = 0;
alram = 0U;
//source
voltage_source = 0;
current_sum = 0;
//ac
ac_volt = 0;
ac_temp_err = 0;
ac_fault_err = 0;
//gen
gen_volt = 0;
gen_current = 0;
gen_rpm = 0;
gen_fuel = 0;
gen_status = 0;
gen_temp = 0;
gen_state_err = 0;
gen_sensor_err = 0;
//batt
batt_volt_1 = 0;
batt_current_1 = 0;
batt_fuel_1 = 0;
batt_temperature_2 = 0;
batt2_heater = 0;
batt_volt_2 = 0;
batt_current_2 = 0;
batt_fuel_2 = 0;
batt_temperature_2 = 0;
batt2_heater = 0;
//ch_value
voltage_ch1 = 0;
currunt_ch1 = 0;
voltage_ch2 = 0;
currunt_ch2 = 0;
voltage_ch3 = 0;
currunt_ch3 = 0;
voltage_ch4 = 0;
currunt_ch4 = 0;
voltage_ch5 = 0;
currunt_ch5 = 0;
voltage_ch6 = 0;
currunt_ch6 = 0;
voltage_ch7 = 0;
currunt_ch7 = 0;
voltage_ch8 = 0;
currunt_ch8 = 0;
voltage_ch9 = 0;
currunt_ch9 = 0;
voltage_ch10 = 0;
currunt_ch10 = 0;
voltage_ch11 = 0;
currunt_ch11 = 0;
voltage_ch12 = 0;
currunt_ch12 = 0;
voltage_ch13 = 0;
currunt_ch13 = 0;
voltage_ch14 = 0;
currunt_ch14 = 0;
//ch status
ch_status_1 = 0;
ch_status_2 = 0;
//etc
check_sum = 0;
em_off_time = 0;
temp = 0;
temp_lan = 0;
err_ch_current_2 = 0;
temp_sw = 0;
sw_result = 0;
//i2c<32>ӽ<EFBFBD>
i2c_add = 0;
i2c_w_data = 0;
i2c_read_act = 0;
i2c_write_act = 0;
i2c_read_all_act = 0;
//pulse
sec_1000ms = 0U;
sec_500ms = 0U;
sec_100ms = 0U;
response_power_management_pbit_act_p = 0;
response_power_manage_detail_act_p = 0;
response_power_manage_control_act_p = 0;
response_power_manage_start_act_p = 0;
}
static void init_sub(void)
{
//fnd
command = 0x00U;
fnd_data = 0x00U;
fnd_voltage = 0U;
fnd_current = 0U;
fnd_fuel = 0U;
fnd_soc1 = 0U;
fnd_soc2 = 0U;
//buzzer
buzzer_work = 0U;
buzzer_stop_act = 0U;
buzzer_act = 0U;
buzzer_press = 0U;
buzzer_press_act = 0U;
buzzer_press_count = 0U;
alram_count = 0U;
alram_count_flag = 0U;
//485 data
ch_sel_1 = 0U;
ch_sel_2 = 0U;
//BIT
p_bit = 0U;
ch_set_act = 0U;
ch_req_act = 0U;
//link
loss_count = 0;
sw_up_link_count = 0;
sw_up_link = 0;
sw_down_link = 0;
//err
comm_total_err = 0;
divider_total_err = 0;
ac_err = 0;
//lan
sn_count = 0;
power_management_status_report_act = 0;
power_management_pbit_response_act = 0;
power_managementbit_cbit_report_act = 0;
power_manage_detail_response_act = 0;
power_manage_control_response_act = 0;
heart_bit_sent_act = 0;
divider_limit_alram = 0;
divider_work_alram = 0;
// battery
batt1_temp_err = 0;
batt1_ocp = 0;
batt1_ovp = 0;
batt1_charge = 0;
batt1_discharge = 0;
batt1_status = 0;
batt1_total_err = 0;
batt_health_1 = 0;
batt2_temp_err = 0;
batt2_ocp = 0;
batt2_ovp = 0;
batt2_charge = 0;
batt2_discharge = 0;
batt2_status = 0;
batt2_total_err = 0;
batt_health_2 = 0;
//genelator
gen_high_temp = 0;
gen_low_fuel = 0;
gen_ovp = 0;
gen_ocp = 0;
gen_main_err = 0;
gen_sub_err = 0;
gen_temp_sensor_err = 0;
gen_volt_sensor_err = 0;
gen_current_sensor_err = 0;
gen_low_presure_err = 0;
gen_fuel_level_sensor_err = 0;
gen_oil_presure_sensor_err = 0;
gen_em_stop = 0;
gen_start_fail = 0;
gen_work_alram = 0;
gen_limit_alram = 0;
reserve1 = 0;
}
void main(void)
{
// Input/Output Ports initialization
// Port A initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
DDRA= 0XFFU;
//(1<<DDA7) | (1<<DDA6) | (1<<DDA5) | (1<<DDA4) | (1<<DDA3) | (1<<DDA2) | (1<<DDA1) | (1<<DDA0)
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
PORTA= 0X00U;
//(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0)
// Port B initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=Out Bit3=Out Bit2=In Bit1=In Bit0=In
DDRB=0xbc; //0B10111101
//1<<DDB7) | (0<<DDB6) | (1<<DDB5) | (1<<DDB4) | (1<<DDB3) | (1<<DDB2) | (0<<DDB1) | (1<<DDB0)
// State: Bit7=T Bit6=T Bit5=T Bit4=0 Bit3=0 Bit2=T Bit1=T Bit0=T
PORTB=0X00U;
//(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0)
// Port C initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=In Bit2=In Bit1=Out Bit0=Out
DDRC= 0xf3; //0B11110011
//(1<<DDC7) | (1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (0<<DDC3) | (0<<DDC2) | (1<<DDC1) | (1<<DDC0)
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=T Bit2=T Bit1=0 Bit0=0
PORTC= 0X00U;
//(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0)
// Port D initialization
// Function: Bit7=In Bit6=In Bit5=Out Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRD= 0x30; //0B00110000
//(0<<DDD7) | (0<<DDD6) | (1<<DDD5) | (1<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0)
// State: Bit7=T Bit6=T Bit5=0 Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTD= 0X00U;
//(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0)
// Port E initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRE= 0xa0; //0B10100000
//(1<<DDE7) | (0<<DDE6) | (1<<DDE5) | (0<<DDE4) | (0<<DDE3) | (0<<DDE2) | (0<<DDE1) | (0<<DDE0)
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTE= 0X00U;
//(0<<PORTE7) | (0<<PORTE6) | (0<<PORTE5) | (0<<PORTE4) | (0<<PORTE3) | (0<<PORTE2) | (0<<PORTE1) | (0<<PORTE0)
// Port F initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRF= 0X00U;
//(0<<DDF7) | (0<<DDF6) | (0<<DDF5) | (0<<DDF4) | (0<<DDF3) | (0<<DDF2) | (0<<DDF1) | (0<<DDF0)
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTF=0X00U;
//(0<<PORTF7) | (0<<PORTF6) | (0<<PORTF5) | (0<<PORTF4) | (0<<PORTF3) | (0<<PORTF2) | (0<<PORTF1) | (0<<PORTF0)
// Port G initialization
// Function: Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
DDRG=0X00U;
//(0<<DDG4) | (0<<DDG3) | (0<<DDG2) | (0<<DDG1) | (0<<DDG0)
// State: Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTG=0X00U;
//(0<<PORTG4) | (0<<PORTG3) | (0<<PORTG2) | (0<<PORTG1) | (0<<PORTG0)
ASSR= 0X00U;
//0<<AS0
TCCR0=0X01U;
//(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<CS01) | (1<<CS00)
TCNT0=0x00;
OCR0=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0X01U;
//(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (1<<TOIE0)
// Globally enable interrupts
#asm("sei")
/*
USART0 initialization
Communication Parameters: 8 Data, 1 Stop, No Parity
USART0 Receiver: On
USART0 Transmitter: On
USART0 Mode: Asynchronous
USART0 Baud Rate: 19200
*/
UCSR0A=0X00U;
//(0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (0<<UPE0) | (0<<U2X0) | (0<<MPCM0)
UCSR0B= 0x98; //0B10011000
//(1<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (1<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80)
UCSR0C= 0x06; //0B0000110
//(0<<UMSEL0) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0)
UBRR0H=0x00U;
UBRR0L=0x33U;
// USART1 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART1 Receiver: On
// USART1 Transmitter: On
// USART1 Mode: Asynchronous
// USART1 Baud Rate: 19200
UCSR1A=0X00U;
//(0<<RXC1) | (0<<TXC1) | (0<<UDRE1) | (0<<FE1) | (0<<DOR1) | (0<<UPE1) | (0<<U2X1) | (0<<MPCM1)
UCSR1B= 0x98; //0B10011000
//(1<<RXCIE1) | (0<<TXCIE1) | (0<<UDRIE1) | (1<<RXEN1) | (1<<TXEN1) | (0<<UCSZ12) | (0<<RXB81) | (0<<TXB81)
UCSR1C= 0x06; //0B0000110
//(0<<UMSEL1) | (0<<UPM11) | (0<<UPM10) | (0<<USBS1) | (1<<UCSZ11) | (1<<UCSZ10) | (0<<UCPOL1)
UBRR1H=0x00U;
UBRR1L=0x33U;
init();
init_sub();
while (1)
{
main_time();
buzzer_check();
if(ch_set_act == 1U)
{
power_divider_chset();
}
if(ch_req_act == 1U)
{
power_divider_request();
}
if((SW_LAN_SPEED_D_0 == HIGH)){LED_STATUS = HIGH;}else{LED_STATUS = LOW;}
if((sw_up_link == LINK)&&(sw_down_link == UNLINK))
{
LED_STATUS = HIGH;
}
else
{
LED_STATUS = LOW;
}
if(response_power_manage_start_act_p == 1U){power_management_start_response();}
if(response_power_management_pbit_act_p == 1U)
{
power_management_pbit_response();
}
if(power_management_status_report_act == 1U)
{
power_management_status_report1();
power_management_sub_status_report1();
power_management_status_report2();
}
if(response_power_manage_detail_act_p == 1U)
{
power_managementbit_detail_response();
}
if(power_managementbit_cbit_report_act == 1U)
{
power_management_cbit_report();
i2c_read_act = 0;
}
if(heart_bit_sent_act == 1U)
{
heart_bit_sent( );
heart_bit_sent_act = 0;
}
if(response_power_manage_control_act_p == 1U)
{
power_management_control_response();
}
if(i2c_write_act == 1U)
{
sw_lan_cont(i2c_add, i2c_w_data);
i2c_write_act = 0;
}
if(i2c_read_all_act == 1U)
{
sw_list();
i2c_read_all_act = 0U;
}
}
}