中级会员
 
- 积分
- 425
- 金钱
- 425
- 注册时间
- 2019-5-12
- 在线时间
- 168 小时
|

楼主 |
发表于 2020-3-17 18:02:52
|
显示全部楼层
本帖最后由 hejun96 于 2020-3-18 11:38 编辑
- //global.h
- #ifndef __GLOBAL_H
- #define __GLOBAL_H
- #include "stm32f10x.h"
- #include <string.h>
- #include <stdio.h>//用来表示串口打印的函数的标准C库
- /* 按键持续检测相关宏 */
- #define KEY_DELAY_S //按键持续检测
- #define KEY_DELAY_S_LOW (0.1) //按键持续检测到低电平 (代表0.1s)
- #define KEY_DELAY_S_HIGH (2) //按键持续检测到高电平(代表2s)
- /*心跳包相关宏*/
- #define HEART_RATE_TIME (30)
- #define HEART_LOSE_TIMES (2 * 3)
- /*间断加热相关*/
- #define HOT_ON_TIME (10) // 单位:分钟
- #define HOT_OFF_TIME (2) // 单位:分钟
- /*ADC1的数据寄存器地址*/
- #define ADC1_DR_Address ((uint32_t)0x4001244C)
- #define BAUD_RATE (9600)
- #define VDDA (3.3)
- #define HIGH_AD_VALUE (4096)
- #define PRESS_PUMP_C (0.25)
- #define RELAY_CURRENT_C (1.1)
- /* 3475 = 2.8/3.3*4096 */
- #define PARAMETER_1 (3825)
- #define PARAMETER_2 (2000)/*缺水判断进入时间*/
- #define PARAMETER_3 (2000)/*缺水判断离开时间*/
- #define KEY_DELAY_MS (121)
- #define BEEP_DELAY_MS (500)
- #define CHILD_DELAY_MS (10000)
- #define UVLED_DELAY_MS (5*60*1000)
- #define NTC1_TEM_PARM (5)
- #define NTC2_TEM_PARM (5)
- //#define NULL (0)
- #define DATA_LENGTH (512)
- #define FIFO_LENGTH (10)
- #define CLEAN_SELF_TOTAL_TIME (48*60*60*1000) /*自清洗总时间,1000(ms)*60(s)*60(min)*48(h)*/
- #define CLEAN_SELF_HALF_TIME (24*60*60*1000) /*自清洗半程时间*/
- #define CLEAN_SELF_PRESSURE_PUMP_WORK_TIME (1000*60*35) /*自清洗时增压泵工作时间*/
- #define CL_TIME3 (1000*60*5) /*电磁阀E工作时间长度*/
- #define TDS_CHECK_TIME (5) /* 单位: S */
- #define TO_HEAT_CHECK_TIME (10000) // 连续加热检测时间 单位:分钟 最小为1
- #define CHOOSE_0_A(n) ((n<='9')?('0'):('7'))
- #define CL_WRITE_FLASH_TIME (1000*60*60) /*写入flash时间*/
- #define AT24C02_ADDR 0XA0
- #define AT24C02_REG 1
- #define AT24C02_REG_INDENTIFIER 24
- #define AT24C02_REG_TEM 28
- #define AT24C02_REG_DATE_TIME 50
- #define AT24C02_REG_NO_OUT_TIME 40
- /*采集的通道数*/
- #define SampleChannelNUM 5
- /*一次采集的次数*/
- #define SampleCount 10
- #define READ_CHILD_KEY_VALUE (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
- #define READ_HOT_KEY_VALUE (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1))
- #define READ_COLD_KEY_VALUE (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2))
- #define READ_VDD_VOL_VALUE (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1))
- #define READ_LEAK_WATER_VALUE (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2))
- //增加按键编码,由触摸延时改成编码形式
- #define LEAD_CODE_MARK 0x80
- #define GET_KEY_MARK 0x40
- #define END_CODE_MARK 0x20
- #define FALLING_MARK 0x10
- //数据前缀长度 7个固定前缀+4个数据长度+12个时间码+4个随机数+2C
- #define DPL (7+4+12+4+2) //
- extern volatile unsigned long gTick;
- extern volatile u8 Receive_data[DATA_LENGTH];
- extern volatile u8 Receive_data_len[3];/*缓存帧数长度*/
- extern volatile u8 Rec_dat_num;
- extern volatile u8 Transf_fifo[FIFO_LENGTH];
- extern volatile u16 TDS_ConvertedAverageValue[2];
- extern volatile u16 ADC_ConvertedValue[SampleChannelNUM*SampleCount];
- extern volatile u8 Rfid_receive_data[DATA_LENGTH];
- extern volatile u8 Rfid_rec_dat_num;
- extern volatile u32 COOL_DELAY_MS;
- extern volatile u32 HOT_DELAY_MS;
- extern volatile u8 sta0;
- extern unsigned long ticker;
- extern volatile unsigned char isat;
- extern volatile unsigned long gTick2;
- typedef void (*Set_Led) ( BitAction );
- extern volatile char ChildKeyOnFlag;
- typedef unsigned char (*Read_Key) (void);
- //编码按键结构体
- typedef struct{
- u16 val;//
- u8 cnt;//
- u8 sta;//
- u8 rec;//
- u8 keycode;//
- }KEY_OBJ;
- extern volatile KEY_OBJ child_detect;
- extern volatile KEY_OBJ hot_detect;
- extern volatile KEY_OBJ cold_detect;
- typedef union{
- u8 save_data[4];/*保存在AT24C02的一些数据*/
- struct{
- u8 self_clean_flag;/*保存掉电前的自清洗完成状态;0:完成 1:未完成,待继续*/
- u8 machine_type;/*机器型号;有4款:DY400\DY100A\DY400B\DY75*/
- u16 short_current;/*缺水电流 0--4000ma范围*/
- u8 software_version[12];/*软件版本号*/
- }s;
- }SAVE_DATA_UNION;
- extern volatile SAVE_DATA_UNION Save_Data;
- typedef union{
- u8 usart1_data[75];
- struct{
- u8 head[7];// /S00/1/
- u8 data_lentgh[4];/*from time data to checksum data*/
- u8 datetime[12];
- u8 random_number[4];
- u8 fault_code[2];
- u8 tds1_value[4];/*原水*/
- u8 tds2_value[2];/*净水*/
- u8 ntc0_temperature[2];/*不加热*/
- u8 ntc1_temperature[2];/*热水*/
- u8 ntc2_temperature[2];/*保温*/
- u8 fixed_state[8];//固定状态
- u8 percentage_of_filter_core[6];/*1 2 3*/
- u8 total_running_time_of_water_pump[8];/*单位:秒*/
- /// u8 PressurePumpCurrent[4];//增压泵电流,单位:mA
- u8 real_time_water_output[4];/*单位:毫升*/
- u8 the_rest_of_the_day_bucket[4];
- u8 fixtype[2];
- u8 end0[2];
- }s;
- }__attribute__ ((aligned (1)))USART1_TRANSFER0_DATA_UNION;
- extern volatile USART1_TRANSFER0_DATA_UNION Usart1_transf_data;
- typedef union{
- u8 all[4];
- struct{
- u8 checksum[4];
- u8 end[2];/*\r\n*/
- }s;
- }__attribute__ ((aligned (1)))USART1_DATA_END;
- extern volatile USART1_DATA_END Usart1_data_end;
- enum Work_Mode_Type
- {
- WORK_MODE_SYNERGY = 0,
- WORK_MODE_INDEPENDENCE,
- };
- enum Data_Type{
- BEGIN=0,
- STATE_00,
- STATE_01,
- STATE_02,
- STATE_03,
- STATE_04,
- STATE_05,
- REQUEST_RFID_CHANGE_06,
- ORDER_REPORT_04,
- WATER_ORDER_RESPONSE_05,
- PRESS_PUMP_RUN_TIME_07,
- STATE_08,
- STATE_12,
- STATE_13,
- STATE_15,
- STATE_16,
- STATE_17,
- PAD_SAT_REPORT_18,
- STATE_20,
- WATER_OUT_REPORT_21,
- STATE_22,
- STATE_23,
- STATE_24,
- STATE_26,
- STATE_27,
- STATE_28,
- STATE_29,
- STATE_30,
- STATE_38 = 38,
- STATE_42 = 42,
- END,
- };
- enum{
- FLAG_OFF=0,
- FLAG_ON,
- FLAG_PAUSE
- };
- enum{
- USART_RESET=0,
- USART_RECEIVING,
- USART_RECEIVED_END,
- };
- enum{
- TIMER_RESET=0,//定时器复位
- TIMER_RUN,//定时器运行
- TIMER_END,//定时器结束
- TIMER_PAUSE,//定时器暂停
- };
- typedef enum{
- HOT_LED=0,
- NORMAL_LED,
- COLD_LED,
- OFF_LED,
- }LED_TYPE;
- typedef enum{
- DY_100A=1,/*热冷*/
- DY_400,/*一个热胆+一个冷胆,用模拟量对应的是两个热继电器,云众机,本套修改程序中选择此机型*/
- DY_75,/*空*/
- DY_100B,/*两个热胆,即两个热继电器*/
- DY_NR
- }MACHINE_TYPE;
- extern volatile MACHINE_TYPE Machine_Type;
- typedef struct
- {
- vu8 hour;
- vu8 min;
- vu8 sec;
- vu16 w_year;
- vu8 w_month;
- vu8 w_date;
- vu8 week;
- }_calendar_obj;
- extern _calendar_obj calendar;
- typedef enum{
- CHILD_KEY=0,//童锁键
- HOT_KEY,//热水按键
- COLD_KEY,//冷水按键
- RESET_KEY,//按键编码增加复位按键,这个值无效,暂时不用
- OFF_KEY,//关闭键
- }KEY_TYPE;
- extern volatile KEY_TYPE key_type;
- extern volatile KEY_TYPE key_type_temp;
-
- enum{
- AD_RESET=0,
- AD_RUN,
- AD_END,
- };
- enum{
- PRESS_PUMP_AD=0,
- NTC1_AD,
- NTC2_AD,
- NTC3_AD,
- LEAK_WATER_AD,
- };
- typedef union{
- u32 sta[8];
- struct{
- u32 timer_flag:2;/*0:复位 1:运行 2:完成*/
- u32 pressure_pump_timer_flag:2;//增压泵运行标志位 0:复位 1:运行 2:完成 3:暂停
- u32 wait_water_tick_flag:2;/* 0:复位 1:等待出水计时开始 2:等待出水计时开暂停 */
- u32 pressure_pump_clean_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds1_update_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds2_update_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds1_delete_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds2_delete_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds1_update_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 EUV_update_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 tds2_update_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 key_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 beep_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 data_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停 串口1发送数据时间计时*/
- u32 not_out_water_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 out_water_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 child_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 uvled_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 uvled_switch_cmd:2;/*0:关闭 1:打开 2:无效 3:无效*/
- u32 Liquid_level_switch_on_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停 缺水计时状态位*/
- u32 Liquid_level_switch_off_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停 缺水计时状态位*/
- u32 hot_water_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 cold_water_timer_flag:2;/*0:复位 1:运行 2:完成 3:暂停*/
- u32 key_press_flag:2;/*0:无按键按下 1:有按键按下*/
- u32 Liquid_full_flag:2;/*0:未处于满水状态中 1:处于满水状态中*/
- u32 Liquid_shortage_flag:2;/*0:未处于缺水状态中 1:处于缺水状态中*/
- u32 Liquid_supply_flag:2;/*0:未处于补水状态中 1:处于补水状态中*/
- u32 Liquid_to_supply_flag:2;/*0:未有补水指令 1:有补水指令*/
- u32 ad_collection_flag:2;/*0:复位 1:采集过程中 2:采集完成*/
- u32 ad_average_collection_flag:2;/*0:复位 1:采集过程中 2:采集完成*/
- u32 ad2_collection_flag:2;/*0:复位 1:采集过程中 2:采集完成*/
- u32 ad2_average_collection_flag:2;/*0:复位 1:采集过程中 2:采集完成*/
- u32 tds1_Probe_Short_Connect:2;/*0:未短接 1:短接*/
- u32 tds2_Probe_Short_Connect:2;/*0:未短接 1:短接*/
- u32 leak_water_flag:2;/*0:未漏水 1:漏水*/
- u32 clean_self_cmd:2;/*0:未收到自清洗命令 1:已收到自清洗命令*/
- u32 clean_self_flag:2;/*0:未处于自清洗状态中 1:已处于自清洗状态中*/
- u32 rfid_balance_flag:2;/*0:余额为零 1:余额不足单次出水 2:余额充足*/
- u32 child_Tkey_on_flag:2;/*0:处于童锁状态中 1:未处于童锁状态中*/
- u32 hot_water_on_flag:2;/*0:未处于出热水状态中 1:处于出热水状态中*/
- u32 cold_water_on_flag:2;/*0:未处于出冷水状态中 1:处于出冷水状态中*/
- u32 normal_water_on_flag:2;/*0:未处于出温水状态中 1:处于出温水状态中*/
- u32 water_on_flag:2;/*0:未处于出水状态中 1:处于出水状态中*/
- u32 water_out_flag:2;/*0:未处于排水状态中 1:处于排水状态中*/
- u32 tds1_Freq_Det_Timer_Flag:2;/*0:复位状态 1:运行 2:完成*/
- u32 tds2_Freq_Det_Timer_Flag:2;/*0:复位状态 1:运行 2:完成*/
- u32 raw_water_flag:2;/*0:原水未缺水 1:原水缺水*/
- u32 heat1_water_flag:2;/*0:未加热状态 1:处于加热状态中*/
- u32 heat1_cmd_flag:2;/*0:首次加热复位 1:再次加热*/
- u32 to_heat1_cmd_flag:2;/*0:复位加热指令 1:开始加热指令*/
- u32 heat2_water_flag:2;/*0:未加热状态 1:处于加热状态中*/
- u32 heat2_cmd_flag:2;/*0:首次加热复位 1:再次加热*/
- u32 to_heat2_cmd_flag:2;/*0:复位加热指令 1:开始加热指令*/
- u32 refrigeration_water_flag:2;/*0:未制冷状态 1:处于制冷状态中*/
- u32 hot_tube1_flag:2;/*0:热罐1未发生异常 1:热罐1发生异常*/
- u32 hot_tube1_off_cmd:2;/*0:热罐1未停止加热 1:热罐1停止加热*/
- u32 hot_tube2_off_cmd:2;/*0:热罐2未停止加热 1:热罐2停止加热*/
- u32 ice_tube_off_cmd:2;/*0:冰胆未停止制冷 1:冰胆停止制冷*/
- u32 hot_tube1_on_cmd:2;/*0:热罐1收到停止制热命令 1:热罐1收到开始制热命令 2: 未收到命令*/
- u32 hot_tube2_on_cmd:2;/*0:热罐2收到停止制热命令 1:热罐2收到开始制热命令 2: 未收到命令*/
- u32 ice_tube_on_cmd:2;/*0:冰胆收到停止制冷命令 1:冰胆收到开始制冷命令 2: 未收到命令*/
- u32 ice_tube_flag:2;/*0:冰胆未处于制冷状态中 1:冰胆处于制冷状态中*/
- u32 hot_tube2_flag:2;/*0:热罐2未发生异常 1:热罐2发生异常*/
- u32 voltage_high_det_off_cmd:2;/*0:高压检测功能有效 1:高压检测功能无效*/
- u32 pump_non_stop_flag:2;/*0:泵正常停机 1:泵不停机(非正常)*/
- u32 make_water_error_flag:2;/*0:正常 1:制水异常 制水异常状态位*/
- u32 water_tank_floating_ball_flag:2;/*0:水箱浮球状态正常 1:水箱浮球状态不正常*/
- u32 water_production_flag:2;/*0:复位状态 1:制水状态中*/
- u32 water_in_cmd:2;/*0:复位状态 1:制水指令 2:停止制水指令*/
- u32 usart1_receive_flag:2;/* 0:复位状态 1:接收状态中 2:接收完成状态 */
- u32 usart3_receive_flag:2;/* 0:复位状态 1:接收状态中 2:接收完成状态 */
- u32 pad_show_flag:2;/* 0:黑屏 1:亮屏 2:菜单设置 */
- u32 rx1_wrong_flag:2;/* 0:正常 1:接收错误 */
- u32 pre_out_hot_water_flag:2;/* 0:正常 1:准备出热水标志 2:允许出热水标志 */
- u32 pre_out_cold_water_flag:2;/* 0:正常 1:准备出冷水标志 2:允许出冷水标志 */
- u32 pre_out_normal_water_flag:2;/* 0:正常 1:准备出温水标志 2:允许出温水标志 */
- u32 pad_control_out_water_flag:2;/* 0:复位 1:PAD允许底板放水 2:PAD禁止底板放水 */
- u32 pad_control_clean_cmd:2;/* 0:复位 1:PAD强制冲洗命令*/
- u32 Liquid_switch_error_flag:2;/* 0:复位 1:液位开关异常;液位开关异常标志位*/
- u32 Liquid_tem_error_flag:2;/* 0:复位 1:温度异常;温度异常标志位*/
- u32 Raw_water_short_flag:2;/* 0:复位 1:缺水;原水缺水标志位*/
- u32 Raw_water_short_tick_flag:2;/* 0:复位 1:运行;原水缺水计时标志位*/
- u32 Make_water_tick_flag:2;/* 0:复位 1:运行 2:暂停;制水状态计时标志位*/
- u32 Flushing_water_B_flag:2;/* 0:复位 1:运行 2:暂停;冲洗阀B打开计时标志位*/
- u32 nfc_tick_flag:2;/* 0:复位 1:运行 2:暂停;nfc离开计时标志位*/
- u32 Atmosphere_Led_cmd:2;/* 0:关闭 1:开启 2:暂停;氛围灯指令*/
- u32 d75_water_cmd:2;/* 0:关闭 1:开启 2:暂停;d75-出水指令:出水:响一声 关水:想2声*/
- u32 Update_Out_Water_Time_flag:2;/* 0:无效 1:有效 2:暂停;*/
- u32 is_allow_count1:2;/*0:禁止 1:允许*/
- u32 is_allow_count2:2;/*0:禁止 1:允许*/
- u32 is_start_mea_tds1:2;/*0:禁止 1:允许*/
- u32 tds1DetectionFlag:2; // tds1 detection flag
- u32 tds2DetectionFlag:2; // tds2 detection flag
- u32 isMakeCold:2; //
- u32 pump_tick_flag:2;
- u32 hot1_action_flag:2; // 热罐1动作标志位 0-关闭 1-打开
- u32 hot2_action_flag:2; // 热罐2动作标志位 0-关闭 1-打开
- u32 scaven_end_flag:2; // 扫码结束标志位
- u32 scaven_clear_flag:2; // 扫码清除标志位
- u32 scaven_hot_flag:2; // 扫码热水标志位
- u32 scaven_timer_flag:2; // 定时器
- u32 toHeat_timer_falg:2; // 连续加热定时器标志
- u32 heart_beat_falg:2; // 心跳包标志位
- u32 work_mode:2; // 工作模式:0-协同工作模式,需要上位机配合 1-独立工作模式,不需要上位机配合
- u32 hot_close_flag:2;//热罐关闭标志: 0-关闭 1-打开
- u32 first_time_cleam_flag:2; //第一次接收串口时间码
- }s;
- }STA_UNION;
- extern volatile STA_UNION System_Sta;
- typedef struct{
- u32 heart_beat_tick; // 心跳包计时
- u32 toHeat_tick; // 连续加热加热定时器
- u32 toHeat1_tick; // 连续加热1定时器
- u32 toHeat2_tick; // 连续加热2定时器
- u32 pump_tick;
- u32 pump_start_tick;/*增压泵开启时的计时*/
- u32 uvled_start_tick;/*UV灯开启时的计时*/
- u32 tds1_detection_timer_tick;
- u32 tds2_detection_timer_tick;
- u32 scaven_timer_tick;
- u32 timer_delay;//定时器延时
- u32 EUV_update_tick;/*EUV灯更新标志位*/
- u32 tds1_update_timer_tick;
- u32 tds2_update_timer_tick;
- u32 tds1_delete_timer_tick;
- u32 tds2_delete_timer_tick;
- u32 key_tick;
- u32 wait_water_tick;/*等待出水计时*/
- u32 beep_tick;
- u32 beep_tick_div;
- u32 atmos_tick;/*氛围灯计时*/
- u32 atmos_tick_num;/*氛围灯计时次数*/
- u32 uvled_tick;
- u32 make_water_tick;/*制水计时*/
- u32 flushing_water_B_tick;/*冲洗阀B打开计时*/
- u32 not_out_water_tick;
- u32 Liquid_level_switch_on_tick;
- u32 Liquid_level_switch_off_tick;
- u32 child_flag_tick;
- u32 raw_water_tick;/*原水缺水计时*/
- u32 data_tick;/*串口1发送数据计时*/
- u32 out_water_tick;/*每次的出水量计时*/
- u32 nfc_tick;/*nfc标签离开计时*/
- u32 hot_water_flag_tick;
- u32 hot_water_time; /*单位:秒*/
- u32 cold_water_time;/*单位:秒*/
- u32 cold_water_flag_tick;
- u32 pressure_pump_tick;
- u32 pressure_pump_clean_tick;//增压泵自清洁tick
- u16 pressure_pump_one_run_time;/* 单次运行时间 单位:秒*/
- u32 pressure_pump_all_run_time;/* 总共运行时间 单位:秒*/
- u16 ntc1_temperature;/*热罐1的实时温度*/
- u16 ntc2_temperature;/*热罐2的实时温度*/
- u16 ntc3_temperature;/*tds的实时温度*/
- u16 watertank_temperature;//水箱温度
- u16 tds1_measure_value; /*扩大10倍*/
- u16 tds1_measure_value_ori; /*扩大10倍*/
- u16 tds2_measure_value; /*扩大10倍*/
- u16 tds2_measure_value_ori; /*扩大10倍*/
- s16 press_pump_current; /*单位:mA*/
- s16 press_pump_current_limit; /*单位:mA 默认300ma*/
- s16 leak_water_current;
- s16 relay_ice_tube_current;
- s16 relay_hot_tube1_current;
- s16 relay_hot_tube2_current;
- u16 last_key_type;
- u16 ntc1_setting_temperature;/*热罐1的当前设置温度*/
- u16 ntc2_setting_temperature;/*热罐2的当前设置温度*/
- u8 current_water_out_number[20];
- u8 last_water_out_number[20];
- u8 rfid_number[15];/*12位ID ,2个状态位,1个末位设备编号*/
- u8 rfid_number_ascill[26];/*24位ID位ASCILL字符 2个状态位01出水 02出水暂停 03出水完成*/
- u8 scanf_number[22];/*20位订单编号,2个状态位*/
- u8 water_in_number[24];/*20位订单编号,4个状态位*/
- u8 pump_work_time[2];/*水泵每次做工时长*/
- u8 pad_flag[2];/*PAD的状态 00黑屏,01亮屏,02菜单设置*/
- u8 water_out_flag[2];/*s21数据帧上报出水状态*/
- u8 heart_beat_flag[2]; /*s38数据帧上报心跳包状态*/
- u8 nfc_water_out_flag;/*s06数据帧上报出水状态*/
- u8 fixed_state[8];/*上报开关加热制冷等状态*/
- u8 machine_type;/*01单热罐;02热罐+冷罐;03双热罐*/
- u8 fill_water_number[23];/*实时充水订单编号*/
- u8 flash_water_flag[2];/*清洗状态 01:开始清洗 02:禁止清洗*/
- float rfid_change;
- u8 rfid_change_array[6];
- float hot_water_price;
- float normal_water_price;
- float cool_water_price;
- u16 usart1_tran_data_len;
- u8 int_fault_code[2];
- u16 real_time_water_output;
- u16 the_rest_of_the_day_bucket;
- u8 fixtype;
- u16 tds1_freq;
- u16 tds2_freq;
- u16 setting_water_cap;/*当前每次的出水量 单位ml*/
- u8 chg_filt_num;/*更换的滤芯编号*/
- u16 filt_life;/*滤芯寿命*/
- }DATA_STRUCT;
- extern volatile DATA_STRUCT System_Data;
- //io.c
- //按键中断以及GPIO配置
- void EXTIX_Init(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
-
- GPIO_InitTypeDef GPIO_InitStructure;
- /*child key*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /*hot key*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /*cool key*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /*child key*/
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
- EXTI_InitStructure.EXTI_Line=EXTI_Line0;//PA0中断线初始化
-
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
-
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Rising
-
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
-
- EXTI_Init(&EXTI_InitStructure);
- /*hot key*/
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);
- EXTI_InitStructure.EXTI_Line=EXTI_Line1;//GPIOA.1中断线初始化函数
-
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
-
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Rising
-
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
-
- EXTI_Init(&EXTI_InitStructure);
- /*cool key*/
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2);
- EXTI_InitStructure.EXTI_Line=EXTI_Line2;//GPIOA.2中断线初始化
-
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
-
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Rising
-
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
-
- EXTI_Init(&EXTI_InitStructure);
- }
- //stm32f10x_it.c
- /*10us : arr=9 psc=107*/
- void TIM4Init(void)
- {
- //Timer4 clock enable
- RCC->APB1ENR|=1<<2;
-
- //Auto reload counter
- TIM4->ARR=9;
-
- //Prescaler
- TIM4->PSC=71;
- //Allow interrupt update
- TIM4->DIER|=1<<0;
- //Enable timer4
- TIM4->CR1|=0x01;
- }
- void TIM4_IRQHandler(void)
- {
- /*溢出中断*/
- if(TIM4->SR&0X0001)
- {
- /*按键编码定时器 us级别*/
- if(child_detect.sta & FALLING_MARK)
- {
- child_detect.val+=10;
- }
- if(hot_detect.sta & FALLING_MARK)
- {
- hot_detect.val+=10;
- }
- if(cold_detect.sta & FALLING_MARK)
- {
- cold_detect.val+=10;
- }
- }
- /*清除中断标志位*/
- TIM4->SR&=~(1<<0);
- }
- //脉冲编码按键中断
- volatile KEY_TYPE key_type = OFF_KEY;
- //电平触发按键改成编码形式的脉冲触发按键 外部中断由电平触发的延时改成脉冲触发形式2020-01-13
- volatile KEY_OBJ child_detect = {0};
- volatile KEY_OBJ hot_detect = {0};
- volatile KEY_OBJ cold_detect = {0};
- void EXTI0_IRQHandler(void)
- {
- /*
- if(TIMER_RESET==System_Sta.s.key_timer_flag)
- {
- System_Sta.s.key_timer_flag = TIMER_RUN;
- key_type = CHILD_KEY;
- }
- */
- if(READ_CHILD_KEY_VALUE)
- {
- child_detect.sta |= FALLING_MARK;
- child_detect.val = 0;
- }
- else if(!READ_CHILD_KEY_VALUE)
- {
- if(child_detect.sta & FALLING_MARK)
- {
- if(child_detect.sta & LEAD_CODE_MARK)
- {
- child_detect.rec <<= 1;
- if(child_detect.val>=600 && child_detect.val<=1600)//10*(600+1600)/2 = 11000us = 11ms
- {
- child_detect.rec |= 0;
- }
- else if(child_detect.val>=1700 && child_detect.val<=2700)//10*(1700+2700)/2 = 22000us = 22ms
- {
- child_detect.rec |= 1;
- }
- child_detect.cnt++;
- if(child_detect.cnt == 8)
- {
- child_detect.keycode = child_detect.rec;
- child_detect.cnt = 0;
- child_detect.val = 0;
- child_detect.rec = 0;
- child_detect.sta &= ~LEAD_CODE_MARK;
- child_detect.sta |= GET_KEY_MARK;
- if(child_detect.keycode == 0xAA)
- {
- key_type = CHILD_KEY;
- }
- else if(child_detect.keycode == 0x55)
- {
- key_type = RESET_KEY;
- }
- else
- {
- key_type = OFF_KEY;
- }
- }
- }
- else if(child_detect.val>=4000 && child_detect.val<=6000)//10*(4000+6000)/2 = 50000us = 50ms
- {
- child_detect.sta |= LEAD_CODE_MARK;
- child_detect.cnt = 0;
- }
- else if(child_detect.val>=9000 && child_detect.val<= 11000)//10*(9000+11000)/2 = 100000us = 100ms
- {
- child_detect.sta |= END_CODE_MARK;
- child_detect.sta &= ~GET_KEY_MARK;
- key_type = OFF_KEY;
- }
- }
- child_detect.sta &= ~FALLING_MARK;
- child_detect.val = 0;
- }
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- void EXTI1_IRQHandler(void)
- {
- /*
- if(TIMER_RESET==System_Sta.s.key_timer_flag)
- {
- System_Sta.s.key_timer_flag = TIMER_RUN;
- key_type = HOT_KEY;
- }
- */
- if(READ_HOT_KEY_VALUE)
- {
- hot_detect.sta |= FALLING_MARK;
- hot_detect.val = 0;
- }
- else if(!READ_HOT_KEY_VALUE)
- {
- if(hot_detect.sta & FALLING_MARK)
- {
- if(hot_detect.sta & LEAD_CODE_MARK)
- {
- hot_detect.rec <<= 1;
- if(hot_detect.val>=600 && hot_detect.val<=1600)
- {
- hot_detect.rec |= 0;
- }
- else if(hot_detect.val>=1700 && hot_detect.val<=2700)
- {
- hot_detect.rec |= 1;
- }
- hot_detect.cnt++;
- if(hot_detect.cnt == 8)
- {
- hot_detect.keycode = hot_detect.rec;
- hot_detect.cnt = 0;
- hot_detect.val = 0;
- hot_detect.rec = 0;
- hot_detect.sta &= ~LEAD_CODE_MARK;
- hot_detect.sta |= GET_KEY_MARK;
- if(hot_detect.keycode == 0xBB)
- {
- key_type = HOT_KEY;
- }
- else
- {
- key_type = OFF_KEY;
- }
- }
- }
- else if(hot_detect.val>=4000 && hot_detect.val<=6000)
- {
- hot_detect.sta |= LEAD_CODE_MARK;
- hot_detect.cnt = 0;
- }
- else if(hot_detect.val>=9000 && hot_detect.val<=11000)
- {
- hot_detect.sta |= END_CODE_MARK;
- hot_detect.sta &= ~GET_KEY_MARK;
- key_type = OFF_KEY;
- }
- }
- hot_detect.sta &= ~FALLING_MARK;
- hot_detect.val = 0;
- }
- EXTI_ClearITPendingBit(EXTI_Line1);
- }
- void EXTI2_IRQHandler(void)
- {
- /*
- if(TIMER_RESET==System_Sta.s.key_timer_flag)
- {
- System_Sta.s.key_timer_flag = TIMER_RUN;
- key_type = COLD_KEY;
- }
- */
- if(READ_COLD_KEY_VALUE)
- {
- cold_detect.sta |= FALLING_MARK;
- cold_detect.val = 0;
- }
- else if(!READ_COLD_KEY_VALUE)
- {
- if(cold_detect.sta & FALLING_MARK)
- {
- if(cold_detect.sta & LEAD_CODE_MARK)
- {
- cold_detect.rec <<= 1;
- if((cold_detect.val>=600 && cold_detect.val<=1600))
- {
- cold_detect.rec |= 0;
- }
- else if((cold_detect.val>=1700 && cold_detect.val<=2700))
- {
- cold_detect.rec |= 1;
- }
- cold_detect.cnt++;
- if(cold_detect.cnt == 8)
- {
- cold_detect.keycode = cold_detect.rec;
- cold_detect.cnt = 0;
- cold_detect.val = 0;
- cold_detect.rec = 0;
- cold_detect.sta &= ~LEAD_CODE_MARK;
- cold_detect.sta |= GET_KEY_MARK;
- if(cold_detect.keycode == 0xCC)
- {
-
- key_type = COLD_KEY;
- }
- else
- {
- key_type = OFF_KEY;
- }
- }
- }
- else if((cold_detect.val>=4000 && cold_detect.val<=6000))
- {
- cold_detect.sta |= LEAD_CODE_MARK;
- cold_detect.cnt = 0;
- }
- else if((cold_detect.val>=9000 && cold_detect.val<= 11000))
- {
- cold_detect.sta |= END_CODE_MARK;
- cold_detect.sta &= ~GET_KEY_MARK;
- key_type = OFF_KEY;
- }
- }
- cold_detect.sta &= ~FALLING_MARK;
- cold_detect.val = 0;
- }
- EXTI_ClearITPendingBit(EXTI_Line2);
- }
- //system.c
- /*读取童锁锁定按键的状态 1:有效*/
- u8 Read_ChildKey(void)
- {
- return !(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0));
- }
- /*读取热水出水按键的状态 1:有效*/
- u8 Read_HotWaterKey(void)
- {
- return !(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1));
- }
- /*读取冷水出水按键的状态 1:有效*/
- u8 Read_ColdWaterKey(void)
- {
- return !(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2));
- }
- /*按键工作*/
- void Key_Work(void)
- {
- // static KEY_TYPE key_type_temp = OFF_KEY;
- static unsigned long ColdKeyPressTick=0;
- static unsigned long HotKeyPressTick=0;
- static unsigned long ChildKeyPressTick=0;
- static unsigned long ResetKeyPressTick=0;
- static char HotKeyLongPressStatus = 0;// status hot
- static char ColdKeyLongPressStatus= 0;//status cold
- static char ChildKeyLongPressStatus = 0;//童锁
- static char ResetStatus = 0;
- static char HotKeyChange = 0,ColdKeyChange = 0;//hot change ,cold change 设置翻转
- #if 1
- if (key_type == CHILD_KEY)//读取童锁键值
- {
- if (gTick - ChildKeyPressTick >= 9*1000)//按键去抖动时间超过9*1000ms
- {
- ChildKeyLongPressStatus = 1;
- }
- }
- else
- {
- ChildKeyLongPressStatus = 0;
- ChildKeyPressTick = gTick;
- }
- if (ChildKeyLongPressStatus)
- {
- ChildKeyLongPressStatus = 0;
- ChildKeyPressTick = gTick;
- System_Sta.s.clean_self_cmd = FLAG_ON;
- //开启蜂鸣器
- if(TIMER_RESET==System_Sta.s.beep_timer_flag)
- {
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- }
- }
- #endif
- #if 1
- //增加复位键
- if(key_type == RESET_KEY)
- {
- if(gTick - ResetKeyPressTick >= 9*1000)
- {
- ResetStatus = 1;
- }
- }
- else
- {
- ResetStatus = 0;
- ResetKeyPressTick = gTick;
- }
- if(key_type == HOT_KEY)
- {
- if(gTick-HotKeyPressTick>=9*1000)//使用复位功能
- {
- HotKeyLongPressStatus = 1;
- }
- }
- else
- {
- HotKeyLongPressStatus = 0;
- HotKeyPressTick = gTick;
- }
-
- if(key_type == COLD_KEY)
- {
- if(gTick - ColdKeyPressTick >= 9*1000)//使用复位功能
- {
- ColdKeyLongPressStatus = 1;
- }
- }
- else
- {
- ColdKeyLongPressStatus = 0;
- ColdKeyPressTick = gTick;
- }
- if(ResetStatus)//if(1 == HotKeyLongPressStatus && 1 == ColdKeyLongPressStatus)
- {
- Save_Data.s.self_clean_flag = 0;
- i2cWriteBuffer1(AT24C02_ADDR,AT24C02_REG,sizeof(SAVE_DATA_UNION),(u8*)&Save_Data);/*写入数据*/
- for(int i=0;i<sizeof(STA_UNION);i++)
- {
- System_Sta.sta[i] = 0;
- }
- memset((void *)(&System_Data),0,sizeof(DATA_STRUCT));
- //开启蜂鸣器
- if(TIMER_RESET==System_Sta.s.beep_timer_flag)
- {
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- }
- System_Data.flash_water_flag[0]='0';
- System_Data.flash_water_flag[1]='2';/*停止清洗*/
- Trans_dat_append(STATE_23);
- while(1);
- }
- if(HotKeyLongPressStatus == 1 && READ_COLD_KEY_VALUE == 0)
- {
- if(key_type == HOT_KEY)
- {
- HotKeyChange = !HotKeyChange;//hot change
- key_type = OFF_KEY;
- if(1 == HotKeyChange)//System_Sta.s.hot_close_flag == 1
- {
- if(Bit_RESET==Read_WaterShortagDetection())
- {
- System_Data.fixed_state[1] = '1';
-
- ///System_Sta.s.hot_close_flag = 0;
- System_Data.ntc1_setting_temperature = 95;
- if (Save_Data.s.machine_type != DY_100B)
- {
- System_Data.ntc2_setting_temperature = 95;
- }
- else
- {
- System_Data.ntc2_setting_temperature = 0;
- }
- // u8 tem[2] = {0};
- // tem[0] = System_Data.ntc1_setting_temperature;
- // tem[1] = System_Data.ntc2_setting_temperature;
- // i2cWriteBuffer1(AT24C02_ADDR, AT24C02_REG_TEM, sizeof(tem), (u8*)&tem);/*写入数据*/
- u8 tem[2] = {0};
- tem[0] = System_Data.ntc1_setting_temperature;
- tem[1] = System_Data.ntc2_setting_temperature;
- i2cWriteBuffer1(AT24C02_ADDR, AT24C02_REG_TEM, sizeof(tem), (u8*)&tem);/*写入数据*/
- Trans_dat_append(STATE_12);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);//阻塞时间50ms
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- Block_Timer(200);//阻塞时间200ms
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);//阻塞时间50ms
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- // GPIO_WriteBit(GPIOC, GPIO_Pin_12, 1);
- // GPIO_WriteBit(GPIOA, GPIO_Pin_13, 1);
- System_Sta.s.to_heat1_cmd_flag = FLAG_ON;
- System_Sta.s.to_heat2_cmd_flag = FLAG_ON;
- Trans_dat_append(STATE_03);
- }
- else
- {
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- Block_Timer(200);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- Block_Timer(200);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- HotKeyChange = 0;//hot change
- }
- }
- else
- {
- // GPIO_WriteBit(GPIOC, GPIO_Pin_12, 0);
- // GPIO_WriteBit(GPIOA, GPIO_Pin_13, 0);
- System_Data.ntc1_setting_temperature = 0;
- if (Save_Data.s.machine_type == DY_100B)
- {
- System_Data.ntc2_setting_temperature = 0;
- }
- else
- {
- System_Data.ntc2_setting_temperature = 0;
- }
- u8 tem[2] = {0};
- tem[0] = System_Data.ntc1_setting_temperature;
- tem[1] = System_Data.ntc2_setting_temperature;
- i2cWriteBuffer1(AT24C02_ADDR, AT24C02_REG_TEM, sizeof(tem), (u8*)&tem);/*写入数据*/
- Trans_dat_append(STATE_12);
-
- System_Data.fixed_state[1] = '0';
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- Set_HotTube_1(Bit_RESET);
- Set_HotTube_2(Bit_RESET);
- ///System_Sta.s.hot_close_flag = 1;
- Trans_dat_append(STATE_03);
- }
- }
- }
- if(ColdKeyLongPressStatus == 1 && READ_HOT_KEY_VALUE == 0)
- {
- if(key_type == COLD_KEY)
- {
- ColdKeyChange = !ColdKeyChange;//冷键翻转
- //GPIO_WriteBit(GPIOA, GPIO_Pin_14, ColdKeyChange);
- key_type = OFF_KEY;
- Trans_dat_append(STATE_02);
- if(ColdKeyChange)
- {
- System_Data.fixed_state[2] = '1';
- Set_IceTube(Bit_SET);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- Block_Timer(200);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- }
- else
- {
- System_Data.fixed_state[2] = '0';
- Set_IceTube(Bit_RESET);
- System_Sta.s.beep_timer_flag = TIMER_RUN;
- Block_Timer(50);
- System_Sta.s.beep_timer_flag = TIMER_RESET;
- }
- Trans_dat_append(STATE_02);
- }
- }
- if(Bit_SET==Read_WaterShortagDetection()||System_Data.ntc1_temperature>=95||System_Data.ntc2_temperature>=95)
- {
- GPIO_WriteBit(GPIOC, GPIO_Pin_12, 0);//hot tube 1
- GPIO_WriteBit(GPIOA, GPIO_Pin_13, 0);//hot tube 2
- HotKeyChange = 0;
- }
- #endif
- if(Save_Data.s.machine_type==DY_75)/*按键失效*/
- {
- System_Sta.s.key_timer_flag = TIMER_RESET;
- }
- else if(Save_Data.s.machine_type==DY_400)/*童锁键改为温水键*/
- {
- Child_Key_On_Flag = 1;
- }
- <blockquote>if(child_detect.sta & GET_KEY_MARK)
复制代码
1208 发表于 2020-3-17 17:41
仿真看看,可以在长按10s后写个反馈信息,如串口打印
打印过了,两个定时器的变量,串口中的打印一直在计其中一个,另一个没记 |
|