4403 lines
123 KiB
C
4403 lines
123 KiB
C
/*
|
||
******************************************************************************
|
||
* @file main.c / 2-control
|
||
* @author Jeep.zhang
|
||
* @version V1.0
|
||
* @date 13-Jan-2016
|
||
* @brief Main Service Routines.
|
||
******************************************************************************
|
||
* @attention
|
||
* AT+GMR
|
||
* AT version:0.50.0.0(Sep 18 2015 20:55:38)
|
||
* SDK version:1.4.0
|
||
* compile time:Sep 18 2015 21:46:52
|
||
* OK
|
||
* 1.Espressif-SDK,The Latest Version:esp_iot_sdk_v1.4.0_15_09_18
|
||
* 2.Please refer to:esp_iot_sdk_v1.4.0_15_09_18\esp_iot_sdk_v1.4.0\bin\at
|
||
* 3.or Reference information is as follows:
|
||
* ---------Flash size 32Mbit: 512KB+512KB-----------ESP-12F
|
||
* boot_v1.2+.bin 0x00000
|
||
* user1.1024.new.2.bin 0x01000
|
||
* esp_init_data_default.bin 0x3fc000 (optional)
|
||
* blank.bin 0x7e000 & 0x3fe000
|
||
* --------------------------------------------------
|
||
* 4.MCU Model: STM8S005K6,16MHz,FLASH(32K)/RAM(2K)/EEPROM(128bytes)
|
||
* 5.WIFI Module: ESP-WROOM-02(Espressif)/ESP-03(AiThinker)
|
||
*
|
||
* <h2><center>© COPYRIGHT 2015 www.ifish7.com</center></h2>
|
||
******************************************************************************
|
||
*/
|
||
|
||
#include "STM8S005K6.h"
|
||
#include <string.h>
|
||
//#include <stdio.h> /* for printf */
|
||
/**********************************************/
|
||
#define factory_data 0x0a // 厂商编号
|
||
#define pcb_data 0x0b // 硬件型号
|
||
#define mcu_data 0x01 // 版本号
|
||
// 按键值定义H
|
||
|
||
#define Lamp2_Key2 0xf0 // lamp2
|
||
#define Lamp_ShiDuan_Key5 0xf1 // 时段照明
|
||
|
||
#define Pump_Key3 0x02 // Pump
|
||
#define Lamp1_Key1 0x03 // lamp1
|
||
#define Adjust_Key4 0x04 // 调节键
|
||
#define Clock_Setup_Key6 0x05 // 时间设置
|
||
#define WIFI_Key6 0x06
|
||
|
||
//#define K1K3 0x7 // 组合键
|
||
//#define K2K4 0x8 // 组合键
|
||
//#define K3K5 0x9 // 组合键
|
||
//#define K4K6 0xa // 组合键
|
||
|
||
// (HT1621B:LCD)命令字定义:100 A5A4A3A2-A1A0D0D1-D2D3
|
||
//#define Read_Data 0xc0 // Read Data
|
||
//#define Write_Data 0xa0 // Write Data/Read-Modify-Write Data
|
||
#define Command 0x80 // Command
|
||
#define sysen 0x02 // 1 0 0 0000-0001-X
|
||
#define lcdon 0x06 // 1 0 0 0000-0011-X
|
||
#define lcdoff 0x04 // 1 0 0 0000-0010-X
|
||
#define rc256k 0x30 // 1 0 0 0001-10XX-X
|
||
#define bias 0x52 // 1/4 0x50 1/3
|
||
#define tone2k 0x80 // 1 0 0 100X-0XXX-X
|
||
#define toneon 0x12 // 1 0 0 0000-1001-X
|
||
#define toneoff 0x10 // 1 0 0 0000-1000-x
|
||
|
||
// 寄存器定义
|
||
#define RAMBIT 0x80
|
||
unsigned char state0 @RAMBIT;
|
||
//@near unsigned char state0;
|
||
unsigned char flag0 @RAMBIT+1;
|
||
unsigned char flag1 @RAMBIT+2;
|
||
unsigned char flag2 @RAMBIT+3;
|
||
unsigned char flag3 @RAMBIT+4;
|
||
unsigned char flag4 @RAMBIT+5;
|
||
unsigned char flag5 @RAMBIT+6;
|
||
//unsigned char flag6 @RAMBIT+7;
|
||
//unsigned char flag7 @RAMBIT+8;
|
||
|
||
// 寄存器flag各位变量定义
|
||
_Bool flag_TimeSetup_Jump @flag0:0;
|
||
_Bool flag_have_key @flag0:1;
|
||
_Bool flag_ClockTime_Change @flag0:2; // 钟表时间设置变化了,保存EEPROM
|
||
_Bool flag_TCP0_Connected @flag0:3;
|
||
_Bool flag_ScreenLock_Status @flag0:4;
|
||
_Bool flag_unlock_key @flag0:5;
|
||
_Bool flag_RS232_TimeoutStart @flag0:6;
|
||
_Bool flag_WiFi_ready @flag0:7;
|
||
|
||
// 寄存器flag1各位变量定义
|
||
_Bool flag_ClockTimeSetting @flag1:0;//s1
|
||
_Bool flag_Colon_Jump @flag1:1;
|
||
_Bool flag_Buzzering @flag1:2;
|
||
_Bool flag_Receive_NewFrame_Buffer0 @flag1:3;
|
||
_Bool flag_Receive_NewOneByte @flag1:4;
|
||
_Bool flag_WiFi_Connected @flag1:5;// 设备是否入网(路由器):1=入网,0=没入网;
|
||
_Bool flag_WiFi_Data_Sending @flag1:6; //=0数据发送完; =1正在发送数据
|
||
_Bool flag_Start_HeartBeat @flag1:7; //=1,启动心跳了
|
||
|
||
// 寄存器flag2各位变量定义
|
||
_Bool flag_RESTORE @flag2:0;
|
||
//_Bool flag_NoLoginBack150s_CIPSTART @flag2:0;
|
||
_Bool flag_Tempture_Abnormal @flag2:1;// 设备是否发送温度报警:1=可以,0=不可以
|
||
_Bool flag_TCP_Logined @flag2:2;// 设备是否登录服务器:1=登录,0=没登录;
|
||
_Bool flag_LoginTCP_SendOnce @flag2:3;
|
||
_Bool flag_HeartBeat10s @flag2:4;// 设备是否可以发心跳包10s:1=可以,0=不可以
|
||
_Bool flag_WiFi_Connect_Enable @flag2:5;// 设备是否发送设备状态信息5min:1=可以,0=不可以
|
||
_Bool flag_Buzzer @flag2:6;
|
||
_Bool flag_TCP0_Connecting @flag2:7;
|
||
|
||
// 寄存器flag3各位变量定义
|
||
_Bool flag_lamp4_onoff @flag3:0;
|
||
_Bool flag_lamp5_onoff @flag3:1;
|
||
_Bool flag_NoLoginBack150s_CIPSTART @flag3:2;
|
||
_Bool flag_ready5s_STARTSMART @flag3:3;
|
||
_Bool flag_DisConnect180s_StartRST @flag3:4;
|
||
_Bool flag_Have_STAMAC @flag3:5;
|
||
_Bool flag_Have_STAIP @flag3:6;
|
||
_Bool flag_ready_Monitoring5s @flag3:7;
|
||
|
||
// 寄存器flag4各位变量定义
|
||
_Bool flag_LampTimeSetting @flag4:0;
|
||
_Bool flag_LampTime_Change @flag4:1; // 灯的定时时间设置变化了,保存DS1302
|
||
_Bool flag_Open_Time @flag4:2;
|
||
_Bool flag_Close_Time @flag4:3;
|
||
_Bool flag_NoLoginBack_Monitoring150s @flag4:4;
|
||
_Bool flag_DisConnect_Monitoring180s @flag4:5;
|
||
_Bool flag_Tempture_Abnormal_Q0 @flag4:6;
|
||
_Bool flag_Tempture_Abnormal_Q1 @flag4:7;
|
||
|
||
// 寄存器flag5各位变量定义
|
||
_Bool flag_WiFi_Smarting @flag5:0;
|
||
_Bool flag_SEND_FAIL @flag5:1;
|
||
_Bool flag_RS232_Timeout @flag5:2;
|
||
_Bool flag_WiFi_Disconnect @flag5:3;
|
||
_Bool flag_UDP1_Connected @flag5:4;
|
||
_Bool flag_auto_hand_change @flag5:5;
|
||
_Bool flag_Restart_Connect_TCP @flag5:6;
|
||
_Bool flag_Enable_Connect_TCP @flag5:7;
|
||
|
||
// 寄存器state0各位变量定义
|
||
//_Bool flag_lamp2_onoff @state0:0;// t16 lamp2 灯光照明2
|
||
//_Bool flag_lamp1_onoff @state0:1;// t18 lamp1 灯光照明1
|
||
//_Bool flag_Pump_onoff @state0:2;// t19 //冲浪 lamp3 杀菌冲浪
|
||
//_Bool flag_WiFi_HaveSet @state0:3;// wifi已设置为1
|
||
//_Bool flag_auto_hand @state0:4;// 0=手动 1=自动
|
||
//_Bool flag_TemptureAlam @state0:5;// 0=
|
||
//_Bool flag_TemptureAlam_High @state0:6;
|
||
//_Bool flag_have_save_URL @state0:7;
|
||
|
||
unsigned char flag_lamp1_onoff=0;
|
||
unsigned char flag_lamp2_onoff=0;
|
||
unsigned char flag_Pump_onoff=0;
|
||
unsigned char flag_auto_hand=0;
|
||
|
||
// 端口定义*****(QT1696:TOUCH)*****
|
||
_Bool QT1696_B0 @PC_IDR:4;// PC4=QT1696_B0
|
||
_Bool QT1696_B1 @PC_IDR:5;// PC5=QT1696_B1
|
||
_Bool QT1696_B2 @PC_IDR:6;// PC6=QT1696_B2
|
||
_Bool QT1696_B3 @PC_IDR:7;// PC7=QT1696_B3
|
||
|
||
// 端口定义*****(DS1302:RTC)*****
|
||
_Bool DS1302_DATA_OUT @PC_ODR:1;// PC1=IO(DS1302) OUT
|
||
_Bool DS1302_DATA_IN @PC_IDR:1;// PC1=Data(DS1302) IN
|
||
_Bool DS1302_RST @PC_ODR:2;// PC2=RST(DS1302)
|
||
_Bool DS1302_CLK @PE_ODR:5;// PE5=CLK(DS1302)
|
||
|
||
// 端口定义*****(DENG1,DENG2,BENG,HEAT)*****
|
||
_Bool lamp2_PC5 @PC_ODR:5;//
|
||
_Bool Lamp1_PB2 @PB_ODR:2;// PB2=LAMP
|
||
_Bool Pump_PB3 @PB_ODR:3;// PB3=PUMP
|
||
_Bool LCD_LED @PB_ODR:1;// PB1=LED
|
||
|
||
// 端口定义*****(HT1621B:LCD)*****
|
||
_Bool HT1621B_IRQ @PD_IDR:0;// PD0=LCD_IRQ
|
||
_Bool HT1621B_DATA_OUT @PD_ODR:2;// PD3=LCD_Data OUT
|
||
_Bool HT1621B_DATA_IN @PD_IDR:2;// PD3=LCD_Data IN
|
||
_Bool HT1621B_WR @PD_ODR:3;// PD4=LCD_WR
|
||
_Bool HT1621B_RD @PD_ODR:4;// PD7=LCD_RD
|
||
_Bool HT1621B_CS @PD_ODR:7;// PD7=LCD_CS
|
||
|
||
unsigned int HeartBeat_0_TimeoutCounter=0;
|
||
unsigned int HeartBeat_1_TimeoutCounter=0;
|
||
unsigned int TCP0_TimeoutCounter=0;
|
||
unsigned int NoLoginBack150s_TimeoutCounter=0;
|
||
unsigned char WiFi_Disconnect_TimeoutCounter=0;
|
||
unsigned char Restart_Connect_TCP_TimeoutCounter=0;
|
||
unsigned char LockScreen_TimeoutCounter=0;
|
||
unsigned char UnLockScreen_TimeoutCounter=0;
|
||
unsigned char RS232_TimeoutCounter=0;
|
||
unsigned char DisConnect180s_TimeoutCounter=0;
|
||
unsigned char NoWiFi5s_TimeoutCounter=0;
|
||
unsigned char HeartBeat10s_TimeoutCounter=0; // 心跳时间是否到10s
|
||
unsigned char Lcd_Colon_TimeoutCounter=0;
|
||
unsigned char ThreeMS_Counter=0;
|
||
unsigned char auto_hand_TimeoutCounter;
|
||
unsigned char InBuffer_ID=0;
|
||
|
||
unsigned char Link_id='0';
|
||
unsigned char Key_Back=0;
|
||
unsigned char Key_Back_Config=0;
|
||
unsigned char Key_Shake=0;
|
||
unsigned char Key_Shake_Config=0;
|
||
|
||
unsigned char Disp_Year;
|
||
unsigned char Disp_Month;
|
||
unsigned char Disp_Day;
|
||
unsigned char Disp_Hour;
|
||
unsigned char Disp_Minute;
|
||
unsigned char Disp_Second;
|
||
unsigned char Disp_Week;
|
||
unsigned int Real_Tempture;
|
||
|
||
unsigned char LampTimeSetup_Stepper=0;
|
||
unsigned char ClockTimeSetup_Stepper=0;
|
||
unsigned char Tempture_Read_Counter=0;
|
||
unsigned char TemptureAlam_Close_Open_Setup=0;
|
||
unsigned char TemptureAlam_NormalLowHigh='N';// 'L'=低温状态,'H'=高温状态,'N'=正常状态
|
||
unsigned char System_Status=0; // flag_System_ERROR
|
||
unsigned int Set_High_Tempture=30;
|
||
unsigned int Set_Low_Tempture=5;
|
||
|
||
unsigned char Buzzer_TimeoutCounter=0;
|
||
unsigned char Receive_NewFrame_TimeoutCounter=0;
|
||
unsigned char Receive_Num0=0; // 单次接收帧,总字节数;
|
||
unsigned char Receive_Count0=0; // 单次接收帧,帧内字节索引号index;
|
||
unsigned char Receive_Count1=0;
|
||
unsigned char Send_Count=0; // 单次发送帧,帧内字节索引号index;
|
||
unsigned char Send_Num=0; // 单次发送帧,总字节数;
|
||
unsigned char Have_New_URL=0;
|
||
unsigned char Receive_NewFrame_Length=0;
|
||
unsigned char Function_Code=0; // ZDH,功能码=00~FEH,若=FFH,表明数据校验出错,重新发送上条命令
|
||
|
||
unsigned char * pStr1=NULL;
|
||
unsigned char * pStr0=NULL;
|
||
unsigned char AT_Command_Stepper=0; // 设备联网步骤;
|
||
unsigned char Connect_TCP_Counter=0;
|
||
|
||
//@tiny 由编译器自动在地址小于0x100的RAM中为其分配一个地址;
|
||
//@near 由编译器自动在地址大于0xFF 的RAM中为其分配一个地址;
|
||
@near unsigned char Timers_Enable[11]={0,0,0,0,0,0,0,0,0,0,0};
|
||
@near unsigned char Set_Open_Hour[10]={0,0,0,0,0,0,0,0,0,0};
|
||
@near unsigned char Set_Open_Minute[10]={0,0,0,0,0,0,0,0,0,0};
|
||
@near unsigned char Set_Close_Hour[10]={0,0,0,0,0,0,0,0,0,0};
|
||
@near unsigned char Set_Close_Minute[10]={0,0,0,0,0,0,0,0,0,0};
|
||
|
||
@near unsigned char LOC_IP_buf[4]={0,0,0,0}; // 本地IP
|
||
@near unsigned char RMT_IP_buf[4]={0,0,0,0}; // 远端IP
|
||
@near unsigned int RMT_IP_PORT=9954;
|
||
@near unsigned char LOC_MAC_buf[6]={0,0,0,0,0,0}; // 发送方MAC地址
|
||
@near unsigned char RMT_MAC_buf[6]={0,0,0,0,0,0}; // 接收方MAC地址
|
||
//@near unsigned char wifi_ssid[20];
|
||
//@near unsigned char wifi_password[20];
|
||
@near unsigned char Send_Buffer[120]; // 发送缓冲区
|
||
@near unsigned char Receive_Buffer0[120]; // 接受缓冲区0
|
||
@near unsigned char Receive_Buffer1[120]; // 接受缓冲区1
|
||
|
||
// 【www.ifish7.com=120.55.190.56】
|
||
@near unsigned char URL_ADDR[]={'w','w','w','.','i','f','i','s','h','7','.','c','o','m',0,0,0,0,0,0};
|
||
//@near unsigned char URL_ADDR[]={'1','2','0','.','5','5','.','1','9','0','.','5','6',0,0,0,0,0,0};
|
||
//@near unsigned char URL_ADDR[]={'1','9','2','.','1','6','8','.','6','1','.','1','2','8',0,0,0,0,0,0};
|
||
|
||
//AT+CIPSTART=0,"TCP","192.168.1.103",8080
|
||
//const unsigned char URL_TCP0_LOC103[]={'0',',','"','T','C','P','"',',','"','1','9','2','.','1','6','8','.','0','.','1','0','4','"',',','8','0','8','0'};
|
||
const unsigned char URL_UDP1_LOC104[]={'1',',','"','U','D','P','"',',','"','1','9','2','.','1','6','8','.','0','.','1','0','4','"',',','3','3','3'};
|
||
|
||
//AT+CIPSTART=0,"TCP","192.168.61.128",9955
|
||
//const unsigned char URL_TCP0_LOC128[]={'0',',','"','T','C','P','"',',','"','1','9','2','.','1','6','8','.','6','1','.','1','2','8','"',',','9','9','5','5'};
|
||
//const unsigned char URL_UDP1_LOC128[]={'1',',','"','U','D','P','"',',','"','1','9','2','.','1','6','8','.','6','1','.','1','2','8','"',',','3','3','3'};
|
||
|
||
//AT+CIPSTART=0,"TCP","www.ifish7.com",9955 【www.ifish7.com=120.55.190.56】
|
||
//const unsigned char URL_TCP0_ifish7[]={'0',',','"','T','C','P','"',',','"','w','w','w','.','i','f','i','s','h','7','.','c','o','m','"',',','9','9','5','5'};
|
||
const unsigned char URL_TCP0_ifish7[]={'0',',','"','T','C','P','"',',','"','1','2','0','.','5','5','.','1','9','0','.','5','6','"',',','9','9','5','5'};
|
||
//const unsigned char URL_UDP1_ifish7[]={'1',',','"','U','D','P','"',',','"','w','w','w','.','i','f','i','s','h','7','.','c','o','m','"',',','3','3','3'};
|
||
|
||
const unsigned char URL_UDP1_ifish7[]={'1',',','"','U','D','P','"',',','"','1','2','0','.','5','5','.','1','9','0','.','5','6','"',',','3','3','3'};
|
||
|
||
//**********************************AT CMD**************************************
|
||
// AT_Command_Stepper=1 // AT+RST重启模块;
|
||
const unsigned char RST[6]={"AT+RST"};
|
||
|
||
// AT_Command_Stepper=2 // 恢复出厂设置
|
||
const unsigned char RESTORE[10]={"AT+RESTORE"};
|
||
|
||
// AT_Command_Stepper=3 // AT+CWSMARTSTART=1 启动智能连接(安信可指令);
|
||
//const unsigned char CWSMARTSTART[17]={"AT+CWSMARTSTART=1"};
|
||
|
||
// AT_Command_Stepper=3 // AT+CWSTARTSMART=3 启动智能连接(乐鑫指令);
|
||
const unsigned char CWSTARTSMART[17]={"AT+CWSTARTSMART=3"};
|
||
|
||
// AT_Command_Stepper=4 // AT+CWMODE=1选择wifi应用模式1=STA,2=AP,3=AP+STA;
|
||
const unsigned char CWMODE[10] ={"AT+CWMODE="};
|
||
|
||
// AT_Command_Stepper=5 // AT+CIPMODE=0设置模块传输模式;=1透传
|
||
const unsigned char CIPMODE[11]={"AT+CIPMODE="};
|
||
|
||
// AT_Command_Stepper=6 // AT+CIPMUX=1 启动多路连接;Link id=0~4
|
||
const unsigned char CIPMUX[10] ={"AT+CIPMUX="};
|
||
|
||
// AT_Command_Stepper=7 // AT+CIFSR获取本地IP地址;
|
||
const unsigned char CIFSR[8]={"AT+CIFSR"};
|
||
|
||
// AT_Command_Stepper=8 // AT+CIPSTART=建立TCP连接或注册UDP端口号;
|
||
const unsigned char CIPSTART[12]={"AT+CIPSTART="};
|
||
|
||
// AT_Command_Stepper=9 // AT+CWSMARTSTOP 停止智能连接(安信可指令);
|
||
//const unsigned char CWSMARTSTOP[14]={"AT+CWSMARTSTOP"};
|
||
|
||
// AT_Command_Stepper=9 // AT+CWSTOPSMART 停止智能连接(乐鑫指令);
|
||
const unsigned char CWSTOPSMART[14]={"AT+CWSTOPSMART"};
|
||
|
||
// AT_Command_Stepper=10 // AT+CIPSEND =发送数据;
|
||
const unsigned char CIPSEND[11]={"AT+CIPSEND="};
|
||
|
||
// AT_Command_Stepper=11 // AT+CIPCLOSE=5关闭TCP/UDP传输;
|
||
const unsigned char CIPCLOSE[12]={"AT+CIPCLOSE="};
|
||
|
||
// AT_Command_Stepper=12 // AT+CIPSTATUS – 查询网络连接信息
|
||
const unsigned char CIPSTATUS[12]={"AT+CIPSTATUS"};
|
||
|
||
// AT_Command_Stepper=13 // AT+CIPDINFO=1 – 接收网络数据时是否提示对端IP和端口
|
||
const unsigned char CIPDINFO[12]={"AT+CIPDINFO="};
|
||
|
||
// AT_Command_Stepper=14 // 查看信息 :SDK and AT 版本;
|
||
//const unsigned char ATGMR[6]={"AT+GMR"};
|
||
// AT_Command_Stepper=15 // AT+CWJAP="SSID","PASSWORD" 加入AP;
|
||
//const unsigned char CWJAP[9]={"AT+CWJAP="};
|
||
// AT_Command_Stepper=16 // 开0/关1回显;
|
||
//const unsigned char ATE0[4]={"ATE"};
|
||
// AT_Command_Stepper=17 // 自动连接AP;
|
||
//const unsigned char CWAUTOCONN[15]={"AT+CWAUTOCONN=1"};
|
||
// AT_Command_Stepper=18 // 其他.....
|
||
//**********************************AT RETURN*******************************************
|
||
const unsigned char WIFI_CONNECTED[]="WIFI CONNECTED"; // - WiFi 已连接;
|
||
const unsigned char WIFI_GOT_IP[]="WIFI GOT IP"; // - ESP8266 station 已从 AP 获得 IP;
|
||
const unsigned char WIFI_DISCONNECT[]="WIFI DISCONNECT"; // - WiFi 连接断开;
|
||
const unsigned char Smart_get_wifi_info[]="Smart get wifi info"; // Smart Config 成功获取AP信息;
|
||
const unsigned char smarting_connected_wifi[]="smartconfig connected wifi"; // Smart Config 成功连接WIFI;
|
||
const unsigned char OK[]="OK";
|
||
const unsigned char FAIL[]="FAIL"; // AT+ CWJAP = 加入路由失败;
|
||
const unsigned char ERROR[]="ERROR";
|
||
const unsigned char ALREADY_CONNECT[]="ALREADY CONNECT"; // TCP/UDP连接已经存在
|
||
const unsigned char SEND_OK[]="SEND OK"; // AT+CIPSEND=0,n: 发送数据成功
|
||
const unsigned char plusIPD[]="+IPD,"; // 服务器发来数据开头;
|
||
const unsigned char send_logo[]="> ";
|
||
//收到CIPSEND命令后,8266先换行返回”> ”,然后开始接收串口数据=>等待本机发送数据;
|
||
const unsigned char ready[]="ready"; // 上电8266复位成功;等待状态;
|
||
|
||
const unsigned char TCP_0_CONNECT[]="0,CONNECT"; // TCP-0连接成功;
|
||
const unsigned char UDP_1_CONNECT[]="1,CONNECT"; // UDP-1连接成功;
|
||
|
||
const unsigned char TCP0_CLOSED[]="CLOSED"; // TCP/UDP连接失败;smartconfig connected wifi
|
||
const unsigned char DNS_Fail[]="DNS Fail";
|
||
const unsigned char STAMAC[]="STAMAC";
|
||
const unsigned char STAIP[]="STAIP";
|
||
const unsigned char link_is_not_valid[]="link is not valid";
|
||
|
||
//const unsigned char no_change[]="no change";
|
||
//const unsigned char OK_Linked[]="OK Linked";
|
||
//const unsigned char busy_now[]="busy now...";
|
||
//const unsigned char CONNECT_OK[]="CONNECT,OK";
|
||
//const unsigned char invalid[]="invalid";
|
||
//const unsigned char CLOSED[]="CLOSED"; // 断开 TCP/UDP 通信
|
||
//const unsigned char TCIPMUXandCIP_SERVER_mustbe0_ERROR[]="TCIPMUX and CIP SERVER must be 0 ,ERROR";
|
||
// ...............
|
||
//**********************************AT RETURN*******************************************
|
||
|
||
//**********************************AT CMD**************************************
|
||
const unsigned char Lcd_Table0123456789[10]={0xeb,0x60,0xc7,0xe5,0x6c,0xad,0xaf,0xe0,0xef,0xed};//0~9
|
||
const unsigned char lcd_day_tab[5]={0x00,0x0a,0x0d,0x0e,0x0f}; //0,1~3,f
|
||
const unsigned char Lcd_Hour_Tab[4]={0x00,0x0a,0x0d,0x0f}; //0,1~2,f
|
||
const unsigned char lcd_shiduan_tab[4]={0x00,0x09,0x07,0x0b}; //0~3
|
||
|
||
|
||
/**********************系统变量初始化************************/
|
||
void System_Init(void)
|
||
{
|
||
|
||
unsigned char len=0;
|
||
// ----------初始化:状态位;
|
||
if(flag_ScreenLock_Status)
|
||
flag0=0x10;
|
||
else
|
||
flag0=0x10;
|
||
flag0=0;
|
||
flag1=0;
|
||
flag2=0;
|
||
flag3=0;
|
||
flag4=0;
|
||
flag5=0;
|
||
//state0=0;
|
||
|
||
flag_WiFi_ready=0;
|
||
flag_WiFi_Connected=0;
|
||
flag_WiFi_Disconnect=0;
|
||
flag_TCP0_Connected=0;
|
||
//flag_ScreenLock_Status=1; // 开机设定面板是锁定的;
|
||
flag_have_key=0;
|
||
flag_Restart_Connect_TCP=0;
|
||
flag_Enable_Connect_TCP=0;
|
||
flag_Receive_NewFrame_Buffer0=0;
|
||
flag_Receive_NewOneByte=0;
|
||
flag_WiFi_Connect_Enable=0;
|
||
|
||
//lamp2_PC5=0; // 硬件信号没有输出 DENG2(PC5)
|
||
//Lamp1_PB2=0;
|
||
//Pump_PB3=0;
|
||
//LCD_LED=0;
|
||
//LCD_LED=1;
|
||
|
||
for(len=0;len<120;len++)
|
||
{
|
||
Receive_Buffer1[len]=0;
|
||
Receive_Buffer0[len]=0;
|
||
}
|
||
|
||
Connect_TCP_Counter=0;
|
||
Lcd_Colon_TimeoutCounter=0;
|
||
System_Status=0;
|
||
Key_Shake=0;
|
||
Key_Shake_Config=0;
|
||
|
||
WiFi_Disconnect_TimeoutCounter=0;
|
||
TCP0_TimeoutCounter=0;
|
||
ThreeMS_Counter=0;
|
||
Lcd_Colon_TimeoutCounter=0;
|
||
RS232_TimeoutCounter=0;
|
||
HeartBeat10s_TimeoutCounter=0;
|
||
UnLockScreen_TimeoutCounter=0;
|
||
LockScreen_TimeoutCounter=0;
|
||
NoLoginBack150s_TimeoutCounter=0;
|
||
DisConnect180s_TimeoutCounter=0;
|
||
NoWiFi5s_TimeoutCounter=0;
|
||
Receive_NewFrame_TimeoutCounter=0;
|
||
HeartBeat_0_TimeoutCounter=0;
|
||
HeartBeat_1_TimeoutCounter=0;
|
||
|
||
|
||
Receive_Num0=0;
|
||
InBuffer_ID=0;
|
||
Receive_Count0=0;
|
||
Receive_Count1=0;
|
||
Send_Num=0;
|
||
Send_Count=0;
|
||
|
||
pStr0=pStr1=NULL;
|
||
}
|
||
|
||
/* CRC余式表 */
|
||
const unsigned int crc_table[256]=
|
||
{
|
||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
|
||
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
|
||
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
|
||
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
|
||
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
|
||
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
|
||
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
|
||
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
|
||
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
|
||
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
|
||
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
|
||
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
|
||
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
|
||
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
|
||
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
|
||
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
|
||
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
|
||
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
|
||
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
|
||
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
|
||
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
|
||
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
|
||
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
|
||
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
|
||
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
|
||
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
|
||
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
|
||
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
|
||
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
|
||
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
|
||
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
|
||
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
|
||
};
|
||
//下面函数获得CRC校验码 采用标准CRC16 初始CRC=0XFFFF 运算多项式参数 8005 非1021
|
||
unsigned int GetRevCrc_16(unsigned char * pData, int nLength)
|
||
{
|
||
unsigned int cRc_16 = 0xffff;
|
||
unsigned char temp;
|
||
while(nLength-- > 0)
|
||
{
|
||
temp = cRc_16&0xff;
|
||
cRc_16 = (cRc_16 >> 8) ^ crc_table[(temp ^ *pData++) & 0xFF];
|
||
}
|
||
return cRc_16;
|
||
}
|
||
|
||
/**********************************************/
|
||
void Delay(unsigned int delay_num) // Delay(10000)=14ms
|
||
{
|
||
unsigned int i;
|
||
for(i=0;i<delay_num;i++); // 延时一段时间,至少7uS,保证ADC模块的上电完成
|
||
}
|
||
|
||
void Delay_ms(unsigned int delay_num) // Delay(715)=1ms
|
||
{
|
||
unsigned int i;
|
||
while(delay_num--)
|
||
{for(i=0;i<715;i++)
|
||
;}
|
||
}
|
||
|
||
/*********************DS1302时钟芯片,写1byte*************************/
|
||
void writeds1302(unsigned char byte,unsigned char address)
|
||
{
|
||
unsigned char i;
|
||
DS1302_CLK=0;
|
||
address=((address<<1) | 0x80);
|
||
DS1302_RST=1;
|
||
|
||
for(i=0;i<8;i++)
|
||
{
|
||
DS1302_CLK=0;
|
||
DS1302_DATA_OUT=(address & 0x01);
|
||
DS1302_CLK=1;
|
||
address=address>>1;
|
||
}
|
||
for(i=0;i<8;i++)
|
||
{
|
||
DS1302_CLK=0;
|
||
DS1302_DATA_OUT=(byte & 0x01);
|
||
DS1302_CLK=1;
|
||
byte=byte>>1;
|
||
}
|
||
DS1302_RST=0;
|
||
}
|
||
|
||
/*********************DS1302时钟芯片,读1byte**************************/
|
||
unsigned char readds1302(unsigned char address)
|
||
{
|
||
unsigned char i,byte=0;
|
||
DS1302_CLK=0;
|
||
DS1302_DATA_OUT=1; // 读=1
|
||
address=((address<<1) | 0x81);
|
||
DS1302_RST=1;
|
||
|
||
for(i=0;i<8;i++)
|
||
{
|
||
DS1302_DATA_OUT=(address & 0x01);
|
||
DS1302_CLK=1;
|
||
address=address>>1;
|
||
DS1302_CLK=0;
|
||
}
|
||
DS1302_DATA_OUT=1;
|
||
for(i=0;i<8;i++)
|
||
{
|
||
DS1302_CLK=0;
|
||
byte=byte>>1;
|
||
if(DS1302_DATA_IN){byte=byte | 0x80;}
|
||
//else { byte=byte & 0x7f;}
|
||
DS1302_CLK=1;
|
||
// nop;
|
||
// nop;
|
||
}
|
||
DS1302_RST=0;
|
||
return(byte);
|
||
}
|
||
|
||
/*******************读时间=》合成到数组***********************/
|
||
void Read_Time(void)
|
||
{
|
||
unsigned char temp=0;
|
||
if(flag_ClockTimeSetting==0)//&&flag_HeartBeat10s)
|
||
//if(flag_ClockTime_Change==1)
|
||
{
|
||
temp=readds1302(6);//
|
||
Disp_Year=(temp>>4)*10 + (temp & 0x0f);
|
||
|
||
temp=readds1302(5);
|
||
Disp_Week= temp & 0x07;
|
||
|
||
temp=readds1302(4);
|
||
Disp_Month=((temp & 0x10)>>4)*10 + (temp & 0x0f);
|
||
|
||
temp=readds1302(3);
|
||
Disp_Day= ((temp & 0x30)>>4)*10 + (temp & 0x0f);
|
||
|
||
temp=readds1302(2);
|
||
Disp_Hour= ((temp & 0x30)>>4)*10 + (temp & 0x0f);
|
||
|
||
temp=readds1302(1);
|
||
Disp_Minute= ((temp & 0x70)>>4)*10 + (temp & 0x0f);
|
||
|
||
temp=readds1302(0);
|
||
Disp_Second=((temp & 0x70)>>4)*10 + (temp & 0x0f);
|
||
}
|
||
}
|
||
|
||
/*******************数组=》写时间***********************/
|
||
void Write_Time(void)
|
||
{
|
||
unsigned char i;
|
||
|
||
//if(flag_ClockTimeSetting==0)//&&flag_HeartBeat10s)
|
||
//if(flag_ClockTime_Change==1)
|
||
//{
|
||
flag_ClockTime_Change=0;
|
||
if(Disp_Year>99){Disp_Year=99;}
|
||
if(Disp_Month>12){Disp_Month=12;}
|
||
if(Disp_Day>31){Disp_Day=31;}
|
||
if(Disp_Hour>23){Disp_Hour=23;}
|
||
if(Disp_Minute>59){Disp_Minute=59;}
|
||
|
||
writeds1302(0x0,7);
|
||
//writeds1302(0x0,7);writeds1302(0xa5,8);
|
||
i=((Disp_Year/10)<<4) | (Disp_Year%10);
|
||
writeds1302(i,6);
|
||
|
||
i=Disp_Week&0x7;
|
||
writeds1302(i,5);
|
||
|
||
i=((Disp_Month/10)<<4) | (Disp_Month%10);
|
||
writeds1302(i,4);
|
||
|
||
i=((Disp_Day/10)<<4) | (Disp_Day%10);
|
||
writeds1302(i,3);
|
||
|
||
i=((Disp_Hour/10)<<4) | (Disp_Hour%10);
|
||
writeds1302(i,2);
|
||
|
||
i=((Disp_Minute/10)<<4) | (Disp_Minute%10);
|
||
writeds1302(i,1);
|
||
|
||
i=((Disp_Second/10)<<4) | (Disp_Second%10);
|
||
writeds1302(i,0);
|
||
writeds1302(0x80,7);
|
||
//send_pc(0x71);
|
||
//}
|
||
}
|
||
|
||
/*********************HT1621,LCD送8位*************************/
|
||
void sendbit_MSBfirst(unsigned char dat,unsigned char bitcnt)
|
||
{
|
||
unsigned char i;
|
||
for(i=0;i<bitcnt;i++)
|
||
{
|
||
HT1621B_WR = 0;
|
||
HT1621B_DATA_OUT=dat & 0x80;
|
||
HT1621B_WR = 1;
|
||
dat=dat<<1;
|
||
}
|
||
}
|
||
void sendbit_LSBfirst_zdh(unsigned char dat,unsigned char bitcnt)
|
||
{
|
||
unsigned char i;
|
||
for(i=0;i<bitcnt;i++)
|
||
{
|
||
HT1621B_WR = 0;
|
||
HT1621B_DATA_OUT=dat & 0x01;
|
||
HT1621B_WR = 1;
|
||
dat=dat>>1;
|
||
}
|
||
}
|
||
|
||
/** HT1621,LCD送命令*12bit(3+9):100+C8C7C6C5C4C3C2C1C0 **/
|
||
void ht_writecmd(unsigned char cmd,unsigned char cmd_data)
|
||
{
|
||
HT1621B_CS = 0;
|
||
sendbit_MSBfirst(cmd,4); // 0x80 = Command
|
||
sendbit_MSBfirst(cmd_data,8);
|
||
HT1621B_CS = 1;
|
||
}
|
||
void BEEP_ms(unsigned int ms)
|
||
{
|
||
ht_writecmd(Command, toneon);
|
||
Delay_ms(ms);
|
||
ht_writecmd(Command, toneoff);
|
||
}
|
||
/** HT1621,LCD送数据*13bit(3+6+4):101+A5A4A3A2A1A0+D0D1D2D3 **/
|
||
void ht_writedata(unsigned char waddr,unsigned char wdata,unsigned char wnum)
|
||
{
|
||
HT1621B_CS = 0;
|
||
sendbit_MSBfirst(0xa0,3); // 0xa0 = Write Data/Read-Modify-Write Data
|
||
waddr = waddr << 2;
|
||
sendbit_MSBfirst(waddr,6);
|
||
wdata = wdata << (8-wnum);
|
||
sendbit_MSBfirst(wdata,wnum);// error 反了,应该LSB first send
|
||
HT1621B_CS = 1;
|
||
}
|
||
void ht_writedata_zdh(unsigned char waddr,unsigned char wdata,unsigned char wnum)
|
||
{
|
||
HT1621B_CS = 0;
|
||
sendbit_MSBfirst(0xa0,3); // 0xa0 = Write Data/Read-Modify-Write Data
|
||
waddr = waddr << 2;
|
||
sendbit_MSBfirst(waddr,6);
|
||
//wdata = wdata << (8-wnum);
|
||
sendbit_LSBfirst_zdh(wdata,wnum);
|
||
HT1621B_CS = 1;
|
||
}
|
||
|
||
/********************HT1621,LCD初始化***************************/
|
||
void ht1621_cmd_init(void)
|
||
{
|
||
unsigned char i;
|
||
LCD_LED=1; // LCD背灯 1=open;
|
||
|
||
ht_writecmd(Command,sysen); // 打开系统振荡器命令
|
||
ht_writecmd(Command,lcdon); // 打开LCD偏压发生器命令
|
||
ht_writecmd(Command,rc256k); // 系统时钟源片内RC振荡器命令
|
||
ht_writecmd(Command,bias); // LCD1/3偏压选项4个公共口命令
|
||
ht_writecmd(Command,tone2k); // 2k声音频率命令
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0x00,4);
|
||
Delay(500);
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0x0f,4);
|
||
// Delay(5000);
|
||
// ht_writecmd(Command, toneoff);
|
||
// Delay(50000);
|
||
// ht_writecmd(Command, toneoff);
|
||
}
|
||
/*
|
||
ht_writecmd(Command, toneon ); // 打开声音输出
|
||
ht_writecmd(Command, toneoff ); // 关闭声音输出
|
||
*/
|
||
/**********************温度显示*故障代码***********************/
|
||
void Lcd_Disp_Tempture(unsigned int Disp) //温度显示[XX:X]
|
||
{
|
||
/*
|
||
"8"字型段定义
|
||
---A--- ---A--- ---A---
|
||
| | | | | |
|
||
F B F B F B
|
||
| | | | | |
|
||
---G--- ---G--- ---G---
|
||
| | | | | |
|
||
E C E C E C
|
||
| | | | | |
|
||
---D--- ---D--- . ---D---
|
||
*/
|
||
unsigned char temp,lcd_high4,lcd_low4;
|
||
// 温度值小位数X;SEG14+SEG15
|
||
temp=Lcd_Table0123456789[Disp%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // S13="水温标记"
|
||
ht_writedata(14,lcd_high4,4); // SEG14:9A9B9C+S13
|
||
ht_writedata(15,lcd_low4,4); // SEG15:9F9G9E9D
|
||
|
||
// 温度值个位数X;SEG16+SEG17
|
||
temp=Lcd_Table0123456789[Disp%100/10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // DP="."
|
||
ht_writedata(16,lcd_high4,4); // SEG16:8A8B8C+DP
|
||
ht_writedata(17,lcd_low4,4); // SEG17:8F8G8E8D
|
||
|
||
// 温度值十位数X;SEG18+SEG19
|
||
temp=Lcd_Table0123456789[Disp/100];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // S14="Temperature"
|
||
ht_writedata(18,lcd_high4,4); // SEG18:7A7B7C+S14
|
||
ht_writedata(19,lcd_low4,4); // SEG19:7F7G7E7D
|
||
|
||
Delay_ms(250);
|
||
}
|
||
|
||
/********************读取”按键“值*************************
|
||
触键编号 B3 B2 B1 B0 备注
|
||
无有效触摸 1 1 1 1 无触摸状态
|
||
K0(=0) 0 0 0 0 0=VSS\1=VDD
|
||
K1(=1) 0 0 0 1 1
|
||
K2(=2) 0 0 1 0 2
|
||
K3(=3) 0 0 1 1 3
|
||
K4(=4) 0 1 0 0 4
|
||
K5(=5) 0 1 0 1 5
|
||
K6(=5) 0 1 1 0 6
|
||
K1+K3(=7) 0 1 1 1 7 K1、K3 同时压下
|
||
K2+K4(=8) 1 0 0 0 8 K2、K4 同时压下
|
||
K3+K5(=9) 1 0 0 1 9 K3、K5 同时压下
|
||
K4+K6(=10) 1 0 1 0 10 K4、K6 同时压下
|
||
|
||
《K1=灯光照明1》的键值=1
|
||
《K2=灯光照明2》的键值=2
|
||
《K3=杀菌冲浪》 的键值=3
|
||
《K4=调节键》 的键值=4
|
||
《K5=时段照明》 的键值=5
|
||
《K6=时间设置》 的键值=6
|
||
|
||
《K6时间设置》+ 《K4调节键》 =10
|
||
*/
|
||
unsigned char Read_Key_Num(void)
|
||
{
|
||
unsigned char temp=0;
|
||
if(QT1696_B0){temp|=0x1;}
|
||
if(QT1696_B1){temp|=0x2;}
|
||
if(QT1696_B2){temp|=0x4;}
|
||
if(QT1696_B3){temp|=0x8;}
|
||
|
||
if(temp<0xf)
|
||
{return(temp);}
|
||
else
|
||
{return(0xff);}
|
||
}
|
||
|
||
#define LOC_data 0
|
||
#define RMT_data 1
|
||
/**********************UART2-TXD************************/
|
||
void UART2_sendchar(unsigned char c)
|
||
{
|
||
while((UART2_SR & 0x80)==0x00); // 发送移位寄存器为空;
|
||
UART2_DR=c;
|
||
}
|
||
|
||
// 功能是求得一字符串str1在另一字符串str2中的首次出现的位置,
|
||
// 如果str1不在str2中,则返回-1。
|
||
// 例如'假设str1为do,str2为how do you do,则返回值为4 。
|
||
/*
|
||
int strloc(char *str2,char *str1)
|
||
{
|
||
int la=strlen(str1);// 子串;
|
||
int i,j;
|
||
int lb=strlen(str2); // 母串;
|
||
for(i=0;i<lb;i++)
|
||
{
|
||
for(j=0;j<la&&(i+j)<lb&&str1[j]==str2[i+j];j++);
|
||
|
||
if(j==la)
|
||
return i;
|
||
}
|
||
return -1;
|
||
}
|
||
*/
|
||
|
||
int strloc(char *str,char *str_sub)
|
||
{
|
||
int la=strlen(str_sub);
|
||
int i,j;
|
||
int lb=strlen(str);
|
||
for(i=0;i<lb;i++)
|
||
{
|
||
for(j=0;j<la&&(i+j)<lb&&str_sub[j]==str[i+j];j++);
|
||
|
||
if(j==la)
|
||
return i;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
/**********************************************/
|
||
void UART2_Send_Buffer_Check(unsigned char len)//发送数据缓冲区
|
||
{
|
||
unsigned char i;
|
||
|
||
flag_WiFi_Data_Sending=1;
|
||
InBuffer_ID=1;
|
||
Receive_Count1=0;
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer1[i]=0;
|
||
|
||
for(i=0;i<len;i++)
|
||
{
|
||
while((UART2_SR & 0x80)==0x00);// 发送移位寄存器为空;
|
||
UART2_DR = Send_Buffer[i];
|
||
//Delay(10);
|
||
}
|
||
flag_WiFi_Data_Sending=0;
|
||
//Delay_ms(10); // 为了返回进缓存
|
||
flag_RS232_TimeoutStart=1; // 启动串口超时机制
|
||
RS232_TimeoutCounter=0;
|
||
|
||
}
|
||
|
||
void UART2_Send_Buffer_NoCheck(unsigned char len)//发送数据缓冲区
|
||
{
|
||
unsigned char i;
|
||
|
||
//flag_WiFi_Data_Sending=1;
|
||
InBuffer_ID=0;
|
||
Receive_Count0=0;
|
||
//for(i=0;i<120;i++)
|
||
// Receive_Buffer0[i]=0;
|
||
|
||
for(i=0;i<len;i++)
|
||
{
|
||
while((UART2_SR & 0x80)==0x00);// 发送移位寄存器为空;
|
||
UART2_DR = Send_Buffer[i];
|
||
//Delay(10);
|
||
}
|
||
|
||
//Delay_ms(10); // 为了返回进缓存
|
||
//flag_WiFi_Data_Sending=0;
|
||
}
|
||
|
||
/********************核对数据包头**************************/
|
||
unsigned char Check_Header_15data(unsigned char start_byte)//启始位置
|
||
{
|
||
unsigned char i;
|
||
//Receive_Buffer0[start_byte]==0x01&&\
|
||
|
||
// if(Receive_Buffer0[start_byte+1]==Function_Code&&\
|
||
// Receive_Buffer0[start_byte+8]==LOC_MAC_buf[0]&&\
|
||
// Receive_Buffer0[start_byte+9]==LOC_MAC_buf[1]&&\
|
||
// Receive_Buffer0[start_byte+10]==LOC_MAC_buf[2]&&\
|
||
// Receive_Buffer0[start_byte+11]==LOC_MAC_buf[3]&&\
|
||
// Receive_Buffer0[start_byte+12]==LOC_MAC_buf[4]&&\
|
||
// Receive_Buffer0[start_byte+13]==LOC_MAC_buf[5]&&\
|
||
// Receive_NewFrame_Length==Receive_Buffer0[start_byte+14])
|
||
if(1)
|
||
{
|
||
for(i=0;i<6;i++)// 发送方MAC地址在前,接收方MAC地址在后
|
||
{
|
||
RMT_MAC_buf[i]=Receive_Buffer0[start_byte+2+i];
|
||
}
|
||
i=1;
|
||
}
|
||
else
|
||
i=0;
|
||
|
||
return(i);
|
||
|
||
}
|
||
|
||
// ******************装载数据包头15bytes******************
|
||
void Load_Header_15data(unsigned char temp,unsigned char str) // The Frame Header = 15bytes
|
||
{
|
||
unsigned char i;
|
||
if(str=='S') //发送消息类型填充0,回复类型填充1
|
||
{Send_Buffer[temp++]=0x0;}
|
||
//else if(str=='R')
|
||
//{Send_Buffer[temp++]=0x1;}
|
||
else
|
||
{Send_Buffer[temp++]=0x1;}
|
||
|
||
Send_Buffer[temp++]=Function_Code;
|
||
|
||
for(i=0;i<6;i++)// 发送方MAC地址
|
||
{Send_Buffer[temp+i]=LOC_MAC_buf[i];}
|
||
temp=temp+i;
|
||
|
||
for(i=0;i<6;i++)// 接收方MAC地址
|
||
{Send_Buffer[temp+i]=RMT_MAC_buf[i];}
|
||
temp=temp+i;
|
||
|
||
// 数据、帧长度L,
|
||
if(Function_Code==1) // 设备登录服务器指令(24字节),每次设备入网都会主动发送登陆指令
|
||
{Send_Buffer[temp]=24;}
|
||
else if(Function_Code==6)// 设备发送状态信息(17字节,周期5分钟,cancel)
|
||
{Send_Buffer[temp]=57;}
|
||
else if(Function_Code==7)// UDP设备入网(每次设备入网都会向局域网内发送一次指令);
|
||
{Send_Buffer[temp]=20;}
|
||
else if(Function_Code==8)// 发送心跳包(99字节,周期10秒),设备主动发;
|
||
{Send_Buffer[temp]=57;}
|
||
else if(Function_Code==9)// 温度报警,设备主动发;
|
||
{Send_Buffer[temp]=22;}
|
||
else if(Function_Code==11)// UDP广播
|
||
{Send_Buffer[temp]=20;}
|
||
else
|
||
{Send_Buffer[temp]=57;} // 其他命令,返回设备状态信息;
|
||
}
|
||
|
||
/**********************************************/
|
||
void UDP1_Return(unsigned char STR) // UDP1遍历发1~255
|
||
{
|
||
unsigned char i,temp;
|
||
unsigned int CRC16 = 0xffff;
|
||
|
||
if(11==STR||7==STR)// 11=UDP广播指令// 7=UDP回复指令
|
||
{
|
||
Function_Code=STR;
|
||
if(11==STR)
|
||
Load_Header_15data(0,'S'); // 'S'表示发送
|
||
if(7==STR)
|
||
Load_Header_15data(0,'R'); // 'R'表示回复
|
||
i=15;
|
||
|
||
Send_Buffer[15]=0x1; // 配置结果 1
|
||
Send_Buffer[16]=0x3; // 灯的个数 3
|
||
Send_Buffer[17]=0x6; // 定时器个数 6
|
||
|
||
CRC16=GetRevCrc_16(Send_Buffer,18);
|
||
Send_Buffer[18]=CRC16>>8;
|
||
Send_Buffer[19]=CRC16;
|
||
|
||
if(0xff==STR)
|
||
{
|
||
for(i=0;i<20;i++)
|
||
Send_Buffer[i]=0xff;
|
||
}
|
||
|
||
Send_Num=20;
|
||
//UART2_Send_Buffer_NoCheck(Send_Num);
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,SEND_OK))==NULL&&flag_RS232_TimeoutStart); // 等待出现"SEND OK"
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
// 打印了 "SEND OK"
|
||
flag_SEND_FAIL=0;
|
||
System_Status=11;
|
||
}
|
||
else
|
||
{
|
||
// 串口超时了
|
||
flag_SEND_FAIL=1;
|
||
flag_UDP1_Connected=0;
|
||
System_Status=10;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
}
|
||
}
|
||
/**********************************************/
|
||
void Heart_and_State_Return(unsigned char str) // 心跳包&状态返回
|
||
{
|
||
// 根据功能码,进行命令回复,Function_Code
|
||
unsigned char i,temp;
|
||
unsigned int CRC16 = 0xffff;
|
||
|
||
switch(Function_Code)
|
||
{
|
||
case 1: break;
|
||
case 2: break;
|
||
case 3: break;
|
||
case 4: break;
|
||
case 5: break;
|
||
case 6: break;
|
||
case 7: break;
|
||
case 8: break;
|
||
case 9: break;
|
||
case 10: break;
|
||
default:break;
|
||
}
|
||
Load_Header_15data(0,str); // str表示发放0还是回复1
|
||
i=15;
|
||
if(flag_auto_hand)
|
||
Send_Buffer[i++]=0x1;
|
||
else
|
||
Send_Buffer[i++]=0x0; // 设备当前工作模式
|
||
|
||
Send_Buffer[i++]=0x1; // 灯1: 1=on,0=off
|
||
if(flag_lamp1_onoff)
|
||
Send_Buffer[i++]=0x1;
|
||
else
|
||
Send_Buffer[i++]=0x0;
|
||
|
||
// Send_Buffer[i++]=0x2; // 灯2: 1=on,0=off
|
||
// if(flag_lamp2_onoff)
|
||
// Send_Buffer[i++]=0x1;
|
||
// else
|
||
// Send_Buffer[i++]=0x0;
|
||
|
||
Send_Buffer[i++]=0x2; // PUMP3: 1=on,0=off
|
||
if(flag_Pump_onoff)
|
||
Send_Buffer[i++]=0x1;
|
||
else
|
||
Send_Buffer[i++]=0x0;
|
||
|
||
// Send_Buffer[i++]=0x4; // 灯4: 1=on,0=off
|
||
// if(flag_lamp4_onoff)
|
||
// Send_Buffer[i++]=0x1;
|
||
// else
|
||
// Send_Buffer[i++]=0x0;
|
||
|
||
// Send_Buffer[i++]=0x5; // 灯5: 1=on,0=off
|
||
// if(flag_lamp5_onoff)
|
||
// Send_Buffer[i++]=0x1;
|
||
// else
|
||
// Send_Buffer[i++]=0x0;
|
||
|
||
for(temp=0;temp<4;temp++)//4个定时器
|
||
{
|
||
Send_Buffer[i++]=temp+1; // 定时器编号1~10,(1字节)
|
||
Send_Buffer[i++]=Timers_Enable[temp+1]; // 定时器开关:0关,1开(1字节)
|
||
Send_Buffer[i++]=Set_Open_Hour[temp]; // 定时时间开时;(1字节)
|
||
Send_Buffer[i++]=Set_Open_Minute[temp]; // 定时时间开分;(1字节)
|
||
Send_Buffer[i++]=Set_Close_Hour[temp]; // 定时时间关时;(1字节)
|
||
Send_Buffer[i++]=Set_Close_Minute[temp];// 定时时间关分;(1字节)
|
||
}
|
||
Send_Buffer[i++]=Real_Tempture/0x100;
|
||
Send_Buffer[i++]=Real_Tempture%0x100;//实际温度
|
||
Send_Buffer[i++]=0x0;
|
||
Send_Buffer[i++]=0x0;//PH值
|
||
Send_Buffer[i++]=0x0;
|
||
Send_Buffer[i++]=0x0;//湿度
|
||
|
||
Send_Buffer[i++]=TemptureAlam_Close_Open_Setup;
|
||
Send_Buffer[i++]=Set_Low_Tempture/0x100;
|
||
Send_Buffer[i++]=Set_Low_Tempture%0x100; // 报警温度-低
|
||
Send_Buffer[i++]=Set_High_Tempture/0x100;
|
||
Send_Buffer[i++]=Set_High_Tempture%0x100; // 报警温度-高
|
||
|
||
CRC16=GetRevCrc_16(Send_Buffer,i);
|
||
Send_Buffer[i++]=CRC16>>8;
|
||
Send_Buffer[i++]=CRC16;
|
||
|
||
Send_Num=i;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
if(0)
|
||
{
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,SEND_OK))==NULL&&flag_RS232_TimeoutStart); // 等待出现"SEND OK"
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
// 打印了 "SEND OK"
|
||
flag_SEND_FAIL=0;
|
||
System_Status=11;
|
||
}
|
||
else
|
||
{
|
||
// 串口超时了
|
||
flag_SEND_FAIL=1;
|
||
flag_TCP0_Connected=0;
|
||
System_Status=10;
|
||
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
}
|
||
}
|
||
|
||
/*****************************************************************/
|
||
//生成右边这样的指令,将参数a_len 改成10进制,右边这条指令 "AT+CIPSEND=id,XX" XX是发送的数量
|
||
void make_AT_CIPSEND(unsigned char len,unsigned char STR,unsigned char X) // 动态构造发送AT指令
|
||
{
|
||
// len数据长度 STR=255是否UDP广播 X='0'心跳TCP返回,其他根据Link_id
|
||
unsigned char i,j,k;
|
||
for(i=0;i<11;i++)
|
||
Send_Buffer[i]=CIPSEND[i]; // 发送数据命令
|
||
|
||
Send_Buffer[i]=Link_id; // <id>需要用于传输连接的 id 号
|
||
|
||
// 【设备登录服务器指令(24字节)每次设备入网都会主动发送登陆指令】
|
||
if(len==24)
|
||
{
|
||
Send_Buffer[i]='0';
|
||
Send_Buffer[++i]=',';
|
||
Send_Buffer[++i]='2';
|
||
Send_Buffer[++i]='4';
|
||
}
|
||
|
||
// 回复设备入网的指令(UDP方式)(20字节)每次设备入网都会向局域网内发送一次
|
||
else if(len==20)
|
||
{
|
||
Send_Buffer[i]='1'; // UDP=1 <id>需要用于传输连接的 id 号=1
|
||
Send_Buffer[++i]=',';
|
||
Send_Buffer[++i]='2';
|
||
Send_Buffer[++i]='0';
|
||
|
||
Send_Buffer[++i]=',';
|
||
Send_Buffer[++i]='"'; //i=16
|
||
if(STR==255)
|
||
{
|
||
// 第一次群发末端IP段:IP_buf[3]=255
|
||
//LOC_IP_buf[0]=192,LOC_IP_buf[1]=168,LOC_IP_buf[2]=61
|
||
if(LOC_IP_buf[0]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[0]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[0]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(LOC_IP_buf[1]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[1]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[1]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(LOC_IP_buf[2]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[2]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
}
|
||
if((LOC_IP_buf[2]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
Send_Buffer[++i]='2';
|
||
Send_Buffer[++i]='5';
|
||
Send_Buffer[++i]='5';
|
||
}
|
||
else
|
||
{
|
||
// 第二次指定UDP的IP
|
||
// RMT_IP_buf[0]=192,RMT_IP_buf[1]=168,RMT_IP_buf[2]=61,RMT_IP_buf[3]=128
|
||
if(RMT_IP_buf[0]/100)
|
||
{
|
||
Send_Buffer[++i]=RMT_IP_buf[0]/100+'0';
|
||
Send_Buffer[++i]=(RMT_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[0]%10+'0';
|
||
}
|
||
else if((RMT_IP_buf[0]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(RMT_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[0]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=RMT_IP_buf[0]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(RMT_IP_buf[1]/100)
|
||
{
|
||
Send_Buffer[++i]=RMT_IP_buf[1]/100+'0';
|
||
Send_Buffer[++i]=(RMT_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[1]%10+'0';
|
||
}
|
||
else if((RMT_IP_buf[1]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(RMT_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[1]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=RMT_IP_buf[1]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(RMT_IP_buf[2]/100)
|
||
{
|
||
Send_Buffer[++i]=RMT_IP_buf[2]/100+'0';
|
||
Send_Buffer[++i]=(RMT_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[2]%10+'0';
|
||
}
|
||
else if((RMT_IP_buf[2]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(RMT_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[2]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=RMT_IP_buf[2]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(RMT_IP_buf[3]/100)
|
||
{
|
||
Send_Buffer[++i]=RMT_IP_buf[3]/100+'0';
|
||
Send_Buffer[++i]=(RMT_IP_buf[3]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[3]%10+'0';
|
||
}
|
||
else if((RMT_IP_buf[3]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(RMT_IP_buf[3]/10)%10+'0';
|
||
Send_Buffer[++i]=RMT_IP_buf[3]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=RMT_IP_buf[3]%10+'0';
|
||
}
|
||
|
||
Send_Buffer[++i]='"';
|
||
Send_Buffer[++i]=',';
|
||
|
||
Send_Buffer[++i]='9'; // RMT_IP_PORT
|
||
Send_Buffer[++i]='9';
|
||
Send_Buffer[++i]='5';
|
||
Send_Buffer[++i]='4';
|
||
}
|
||
|
||
// 心跳或者返回(71字节)
|
||
else if(len==57)//else if(flag_HeartBeat10s)
|
||
{
|
||
if(X=='0')
|
||
Send_Buffer[i]='0'; // <id>需要用于传输连接的 id 号
|
||
|
||
Send_Buffer[++i]=',';
|
||
Send_Buffer[++i]='5';
|
||
Send_Buffer[++i]='7'; // 71bytes 【设备发送心跳包(71字节,周期10秒)】
|
||
}
|
||
|
||
// 报警温度信息(22字节)
|
||
else if(len==22)//else if(flag_Tempture_Abnormal)
|
||
{
|
||
//Send_Buffer[i]='0'; // <id>需要用于传输连接的 id 号
|
||
Send_Buffer[++i]=',';
|
||
Send_Buffer[++i]='2';
|
||
Send_Buffer[++i]='2'; // 22bytes 温度报警【返回状态信息(22字节)】
|
||
}
|
||
|
||
Send_Buffer[++i]='\r'; // '\r'=0x0d;
|
||
Send_Buffer[++i]='\n'; // '\n'=0x0a;
|
||
Send_Num=i+1;
|
||
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,send_logo))==NULL&&flag_RS232_TimeoutStart); // 等待出现"> "
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
// 打印了 "> "
|
||
flag_SEND_FAIL=0;
|
||
System_Status=211;
|
||
}
|
||
else
|
||
{
|
||
flag_SEND_FAIL=1;
|
||
if(len==20)
|
||
flag_UDP1_Connected=0;
|
||
else
|
||
flag_TCP0_Connected=0;
|
||
|
||
System_Status=210;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
}
|
||
|
||
#define MASS_KEY1 0xAE // flash' 秘钥1
|
||
#define MASS_KEY2 0x56 // flash' 秘钥2
|
||
#define EEP_BASE 0x4000 // eerom 起始地址
|
||
/********************STM8S内部EEPROM 初始化**************************/
|
||
void MCUeeprom_Init(void)
|
||
{
|
||
FLASH_CR1 = 0x00;
|
||
FLASH_CR2 = 0x00;
|
||
FLASH_NCR2 = 0xff;
|
||
FLASH_DUKR = MASS_KEY1;
|
||
FLASH_DUKR = MASS_KEY2;
|
||
while(!(FLASH_IAPSR & 0x08)); // 等待写保护解锁
|
||
}
|
||
|
||
/********************STM8S内部EEPROM 写1byte**************************/
|
||
void MCUeeprom_write_byte(unsigned int addr ,unsigned char dat) //不同芯片,EEPROM容量不同
|
||
{
|
||
*((unsigned char*)(addr + EEP_BASE)) = dat;
|
||
while(!(FLASH_IAPSR & 0x04)); //等待写完成
|
||
}
|
||
|
||
/********************STM8S内部EEPROM 读1byte**************************/
|
||
unsigned char MCUeeprom_read_byte(unsigned int addr)
|
||
{
|
||
return *((unsigned char*)(EEP_BASE + addr));
|
||
}
|
||
|
||
/********************STM8S内部批量写**************************/
|
||
void MCUeeprom_write_URL(void)
|
||
{
|
||
unsigned char i;
|
||
|
||
MCUeeprom_Init();
|
||
// 保存当前TCP服务器域名;
|
||
for(i=55;i<75;i++)
|
||
MCUeeprom_write_byte(i,URL_ADDR[i-55]);
|
||
}
|
||
|
||
void MCUeeprom_write(void)
|
||
{
|
||
unsigned char i;
|
||
//if(flag_LampTime_Change)
|
||
{
|
||
// flag_LampTime_Change=0;
|
||
|
||
MCUeeprom_Init();
|
||
//for(i=0;i<128;i++)
|
||
// MCUeeprom_write_byte(i,0);
|
||
|
||
for(i=0;i<10;i++)
|
||
{MCUeeprom_write_byte(i,Set_Open_Hour[i]);}
|
||
|
||
for(i=10;i<20;i++)
|
||
{MCUeeprom_write_byte(i,Set_Open_Minute[i-10]);}
|
||
|
||
for(i=20;i<30;i++)
|
||
{MCUeeprom_write_byte(i,Set_Close_Hour[i-20]);}
|
||
|
||
for(i=30;i<40;i++)
|
||
{MCUeeprom_write_byte(i,Set_Close_Minute[i-30]);}
|
||
|
||
for(i=40;i<50;i++)
|
||
{MCUeeprom_write_byte(i,Timers_Enable[i-39]);}
|
||
|
||
MCUeeprom_write_byte(50,TemptureAlam_Close_Open_Setup);
|
||
//Set_High_Tempture=0x2505;
|
||
MCUeeprom_write_byte(51,Set_High_Tempture/0x100);
|
||
MCUeeprom_write_byte(52,Set_High_Tempture%0x100);
|
||
//Set_Low_Tempture=0x1505;
|
||
MCUeeprom_write_byte(53,Set_Low_Tempture/0x100);
|
||
MCUeeprom_write_byte(54,Set_Low_Tempture%0x100);
|
||
|
||
MCUeeprom_write_byte(55,state0);
|
||
MCUeeprom_write_byte(56,flag_lamp1_onoff);
|
||
MCUeeprom_write_byte(57,flag_lamp2_onoff);
|
||
MCUeeprom_write_byte(58,flag_Pump_onoff);
|
||
MCUeeprom_write_byte(59,flag_auto_hand);
|
||
MCUeeprom_write_byte(60,Have_New_URL);
|
||
|
||
// 保存当前TCP服务器域名;
|
||
for(i=61;i<81;i++)
|
||
MCUeeprom_write_byte(i,URL_ADDR[i-61]);
|
||
|
||
}
|
||
}
|
||
|
||
/*******************STM8S内部批量读***************************/
|
||
void MCUeeprom_read(void)
|
||
{
|
||
unsigned char i,j;
|
||
unsigned int k;
|
||
if(0)
|
||
{
|
||
for(i=0;i<10;i++)
|
||
{
|
||
Set_Open_Hour[i]=0;
|
||
Set_Close_Hour[i]=0;
|
||
Set_Open_Minute[i]=0;
|
||
Set_Close_Minute[i]=0;
|
||
Timers_Enable[i+1]=0;
|
||
}
|
||
|
||
TemptureAlam_Close_Open_Setup = 0;
|
||
Set_High_Tempture = 0;
|
||
Set_High_Tempture = Set_High_Tempture*0x100;
|
||
Set_High_Tempture+= 0;
|
||
Set_Low_Tempture = 0;
|
||
Set_Low_Tempture = Set_Low_Tempture*0x100;
|
||
Set_Low_Tempture+= 0;
|
||
|
||
for(i=0;i<20;i++)
|
||
// URL_TCP0_ifish7[i]=0;
|
||
state0=0;
|
||
}
|
||
|
||
for(i=0;i<10;i++)
|
||
{Set_Open_Hour[i]=MCUeeprom_read_byte(i);}
|
||
for(i=10;i<20;i++)
|
||
{Set_Open_Minute[i-10]=MCUeeprom_read_byte(i);}
|
||
for(i=20;i<30;i++)
|
||
{Set_Close_Hour[i-20]=MCUeeprom_read_byte(i);}
|
||
for(i=30;i<40;i++)
|
||
{Set_Close_Minute[i-30]=MCUeeprom_read_byte(i);}
|
||
for(i=40;i<50;i++)
|
||
{Timers_Enable[i-39]=MCUeeprom_read_byte(i);}
|
||
|
||
TemptureAlam_Close_Open_Setup = MCUeeprom_read_byte(50);
|
||
|
||
i = MCUeeprom_read_byte(51);
|
||
j = MCUeeprom_read_byte(52);
|
||
Set_High_Tempture = i*0x100+j;
|
||
|
||
i = MCUeeprom_read_byte(53);
|
||
j = MCUeeprom_read_byte(54);
|
||
Set_Low_Tempture = i*0x100+j;
|
||
|
||
|
||
// 读取当前TCP服务器域名;(避免第一次读出来是空的)
|
||
/*
|
||
for(i=55;i<75;i++)
|
||
k+=MCUeeprom_read_byte(i);
|
||
|
||
if(k==0||k==20*0xff)
|
||
{}
|
||
else
|
||
{
|
||
for(i=55;i<75;i++)
|
||
URL_ADDR[i-55]=MCUeeprom_read_byte(i);
|
||
|
||
}
|
||
*/
|
||
state0=MCUeeprom_read_byte(55);
|
||
flag_lamp1_onoff=MCUeeprom_read_byte(56);
|
||
flag_lamp2_onoff=MCUeeprom_read_byte(57);
|
||
flag_Pump_onoff=MCUeeprom_read_byte(58);
|
||
flag_auto_hand=MCUeeprom_read_byte(59);
|
||
Have_New_URL=MCUeeprom_read_byte(60);
|
||
flag_lamp1_onoff&=0x01;
|
||
flag_lamp2_onoff&=0x01;
|
||
flag_Pump_onoff&=0x01;
|
||
flag_auto_hand&=0x01;
|
||
|
||
if(0xea==Have_New_URL)
|
||
{
|
||
for(i=61;i<81;i++)
|
||
URL_ADDR[i-61]=MCUeeprom_read_byte(i);
|
||
}
|
||
|
||
}
|
||
|
||
/***********************解析读取MAC和IP***********************/
|
||
const unsigned char test_IPMAC[]={'A','T','+','C','I','P','F','S','R','\r',
|
||
'+','C','I','P','F','S','R',':','S','T',
|
||
'A','I','P',',','"','1','9','2','.','1',
|
||
'6','8','.','0','.','1','0','8','"','\r','+',
|
||
'C','I','P','F','S','R',':','S','T','A',
|
||
'M','A','C',',','"','1','8',':','f','e',
|
||
':','3','4',':','d','b',':','0','d',':',
|
||
'3','3','"','\r','\n','O','K'};
|
||
//AT+CIPFSR 字符串转数字
|
||
//+CIFSR:STAIP,"192.168.0.108"
|
||
//+CIFSR:STAMAC,"18:fe:34:db:0d:33"
|
||
//OK
|
||
void Read_STAIP_STAMAC(void)
|
||
{
|
||
unsigned char temp,i,i_temp;
|
||
|
||
//for(i=0;i<100;i++)
|
||
// Receive_Buffer1[i]=test_IPMAC[i];
|
||
|
||
if((pStr1=strstr(Receive_Buffer1,STAIP))!=NULL);
|
||
{
|
||
LOC_IP_buf[0]=LOC_IP_buf[1]=LOC_IP_buf[2]=LOC_IP_buf[3]=0;
|
||
flag_Have_STAIP=1;
|
||
temp=strloc(Receive_Buffer1,STAIP); // (strstr(Receive_Buffer1,ready)==NULL);
|
||
temp=temp+7;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer1[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
LOC_IP_buf[0]=(Receive_Buffer1[temp]-'0');
|
||
else if(i==2)
|
||
LOC_IP_buf[0]=(Receive_Buffer1[temp]-'0')*10 +(Receive_Buffer1[temp+1]-'0');
|
||
else if(i==3)
|
||
LOC_IP_buf[0]=(Receive_Buffer1[temp]-'0')*100+(Receive_Buffer1[temp+1]-'0')*10+(Receive_Buffer1[temp+2]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer1[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
LOC_IP_buf[1]=(Receive_Buffer1[temp]-'0');
|
||
else if(i==2)
|
||
LOC_IP_buf[1]=(Receive_Buffer1[temp]-'0')*10+(Receive_Buffer1[temp+1]-'0');
|
||
else if(i==3)
|
||
LOC_IP_buf[1]=(Receive_Buffer1[temp]-'0')*100+(Receive_Buffer1[temp+1]-'0')*10+(Receive_Buffer1[temp+2]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer1[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
LOC_IP_buf[2]=(Receive_Buffer1[temp+i-1]-'0');
|
||
else if(i==2)
|
||
LOC_IP_buf[2]=(Receive_Buffer1[temp+i-2]-'0')*10+(Receive_Buffer1[temp+i-1]-'0');
|
||
else if(i==3)
|
||
LOC_IP_buf[2]=(Receive_Buffer1[temp+i-3]-'0')*100+(Receive_Buffer1[temp+i-2]-'0')*10+(Receive_Buffer1[temp+i-1]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer1[temp+i]=='"')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
LOC_IP_buf[3]=(Receive_Buffer1[temp+i-1]-'0');
|
||
else if(i==2)
|
||
LOC_IP_buf[3]=(Receive_Buffer1[temp+i-2]-'0')*10+(Receive_Buffer1[temp+i-1]-'0');
|
||
else if(i==3)
|
||
LOC_IP_buf[3]=(Receive_Buffer1[temp+i-3]-'0')*100+(Receive_Buffer1[temp+i-2]-'0')*10+(Receive_Buffer1[temp+i-1]-'0');
|
||
temp=temp+i+1;
|
||
}
|
||
//AT+CIPFSR\r 字符串转数字
|
||
//+CIFSR:STAIP,"192.168.1.104"\r
|
||
//+CIFSR:STAMAC,"5c:cf:7f:07:65:21"\r\n
|
||
//OK
|
||
if((pStr1=strstr(Receive_Buffer1,STAMAC))!=NULL) // >='a',<='f'
|
||
{
|
||
LOC_MAC_buf[0]=LOC_MAC_buf[1]=LOC_MAC_buf[2]=LOC_MAC_buf[3]=LOC_MAC_buf[4]=LOC_MAC_buf[5]=0;
|
||
flag_Have_STAMAC=1;
|
||
temp=strloc(Receive_Buffer1,STAMAC);
|
||
temp=temp+8;
|
||
|
||
for(i=0;i<6;i++)
|
||
{
|
||
if(Receive_Buffer1[temp]>='0'&&Receive_Buffer1[temp]<='9')
|
||
LOC_MAC_buf[i]=(Receive_Buffer1[temp]-'0');
|
||
if(Receive_Buffer1[temp]>='a'&&Receive_Buffer1[temp]<='f')
|
||
LOC_MAC_buf[i]=(Receive_Buffer1[temp]-'a')+10;
|
||
|
||
if(Receive_Buffer1[temp+1]>='0'&&Receive_Buffer1[temp+1]<='9')
|
||
LOC_MAC_buf[i]=LOC_MAC_buf[i]*16+(Receive_Buffer1[temp+1]-'0');
|
||
if(Receive_Buffer1[temp+1]>='a'&&Receive_Buffer1[temp]<='f')
|
||
LOC_MAC_buf[i]=LOC_MAC_buf[i]*16+(Receive_Buffer1[temp+1]-'a')+10;
|
||
temp=temp+3;
|
||
}
|
||
}
|
||
}
|
||
/*********************看门狗复位************************/
|
||
/**
|
||
* @brief Enables IWDG. "stm8s_iwdg.h"
|
||
* @param None
|
||
* @retval None
|
||
*/
|
||
void IWDG_Enable(void)
|
||
{
|
||
IWDG_KR = 0xcc; //IWDG_KEY_ENABLE;
|
||
}
|
||
|
||
/**********************模块复位************************/
|
||
void ESP8266_RST(void)
|
||
{
|
||
unsigned char i;
|
||
System_Init();
|
||
|
||
for(i=0;i<6;i++)
|
||
Send_Buffer[i]=RST[i];
|
||
Send_Buffer[6]='\r';
|
||
Send_Buffer[7]='\n';
|
||
Send_Num=8;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
// Monitoring
|
||
//Delay_ms(1000);
|
||
//BEEP_ms(200);
|
||
}
|
||
|
||
/********************模块出厂设置**********************/
|
||
void ESP8266_RESTORE(void)
|
||
{
|
||
unsigned char i;
|
||
|
||
for(i=0;i<10;i++)
|
||
Send_Buffer[i]=RESTORE[i];
|
||
Send_Buffer[10]='\r';
|
||
Send_Buffer[11]='\n';
|
||
Send_Num=12;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
// Monitoring
|
||
//Delay_ms(1000);
|
||
BEEP_ms(200);
|
||
|
||
}
|
||
|
||
/**********************ESP8266模块设置************************/
|
||
void ESP8266_CWMODE(unsigned char STR)
|
||
{
|
||
unsigned char i;
|
||
// 1-1.AT+CWMODE=1 station
|
||
for(i=0;i<10;i++)
|
||
Send_Buffer[i]=CWMODE[i];
|
||
Send_Buffer[10]=STR;
|
||
Send_Buffer[11]='\r';
|
||
Send_Buffer[12]='\n';
|
||
Send_Num=13;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);// 等待返回 OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
System_Status=41;
|
||
else
|
||
System_Status=40;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************ESP8266普通/透传模式************************/
|
||
void ESP8266_CIPMODE(unsigned char STR)
|
||
{
|
||
unsigned char i;
|
||
// 1-2.AT+CIPMODE=0 非透传,普通模式
|
||
for(i=0;i<11;i++)
|
||
Send_Buffer[i]=CIPMODE[i];
|
||
Send_Buffer[11]=STR;
|
||
Send_Buffer[12]='\r';
|
||
Send_Buffer[13]='\n';
|
||
Send_Num=14;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);// 等待返回 OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL) System_Status=51;
|
||
else System_Status=50;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************ESP8266多路连接************************/
|
||
void ESP8266_CIPMUX(unsigned char STR)
|
||
{
|
||
unsigned char i;
|
||
// 1-3.AT+CIPMUX=1 多路连接
|
||
for(i=0;i<10;i++)
|
||
Send_Buffer[i]=CIPMUX[i];
|
||
Send_Buffer[10]=STR;
|
||
Send_Buffer[11]='\r';
|
||
Send_Buffer[12]='\n';
|
||
Send_Num=13;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);// 等待返回 OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL) System_Status=61;
|
||
else System_Status=60;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************ESP8266显示对端IP和端口************************/
|
||
void ESP8266_CIPDINFO(unsigned char STR)
|
||
{
|
||
unsigned char i;
|
||
// 1-4.AT+CIPDINFO=1 显示对端IP和端口
|
||
for(i=0;i<12;i++)
|
||
Send_Buffer[i]=CIPDINFO[i];
|
||
Send_Buffer[i++]=STR;
|
||
Send_Buffer[i++]='\r';
|
||
Send_Buffer[i++]='\n';
|
||
Send_Num=i;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);// 等待返回 OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL) System_Status=61;
|
||
else System_Status=60;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************ESP8266关闭连接************************/
|
||
void ESP8266_CIPCLOSE(unsigned char STR)
|
||
{
|
||
unsigned char i;
|
||
// 1-5.AT+CIPCLOSE=0~4,5=关闭所有 TCP/UDP 传输
|
||
for(i=0;i<12;i++)
|
||
Send_Buffer[i]=CIPCLOSE[i];
|
||
|
||
Send_Buffer[12]=STR; //STR=id
|
||
Send_Buffer[13]='\r';
|
||
Send_Buffer[14]='\n';
|
||
Send_Num=15;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL) System_Status=141;
|
||
else System_Status=140;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************ESP8266智能启动************************/
|
||
void ESP8266_STARTSMART(void)
|
||
{
|
||
unsigned char i;
|
||
flag_WiFi_Smarting=1;
|
||
flag_WiFi_Connect_Enable=1;
|
||
|
||
flag_WiFi_Disconnect=0;
|
||
flag_WiFi_Connected=0;
|
||
flag_TCP0_Connected=0;
|
||
|
||
if(flag_WiFi_Connected==0)
|
||
{
|
||
for(i=0;i<14;i++)
|
||
Send_Buffer[i]=CWSTOPSMART[i];
|
||
Send_Buffer[14]='\r';
|
||
Send_Buffer[15]='\n';
|
||
Send_Num=16;
|
||
UART2_Send_Buffer_Check(Send_Num);// 智能连接先关一下
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);// 等待返回 OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL) System_Status=71;
|
||
else System_Status=70;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
|
||
for(i=0;i<17;i++)
|
||
Send_Buffer[i]=CWSTARTSMART[i];// 智能连接
|
||
Send_Buffer[17]='\r';
|
||
Send_Buffer[18]='\n';
|
||
Send_Num=19;
|
||
|
||
flag_WiFi_Connected=0;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
// Monitoring
|
||
}
|
||
}
|
||
|
||
/**********************模块获取MAC和IP************************/
|
||
void ESP8266_CIFSR(void)
|
||
{
|
||
unsigned char i;
|
||
// 在此发送:"AT+CIFSR" / ESP8266 station IP 需连上 AP 后,才可以查询。
|
||
for(i=0;i<8;i++)
|
||
Send_Buffer[i]=CIFSR[i];
|
||
Send_Buffer[8]='\r';
|
||
Send_Buffer[9]='\n';
|
||
Send_Num=10;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
Delay_ms(10);
|
||
while(((pStr1=strstr(Receive_Buffer1,STAIP))==NULL)&&\
|
||
((pStr1=strstr(Receive_Buffer1,STAMAC))==NULL)&&flag_RS232_TimeoutStart);
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
Read_STAIP_STAMAC();
|
||
System_Status=131;
|
||
}
|
||
else
|
||
System_Status=130;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
/**********************模块连接服务器*UDP1***********************/
|
||
void ESP8266_CIPSTART_UDP(unsigned char STR)
|
||
{
|
||
unsigned char i,j;
|
||
|
||
if(1)//if(STR==1)
|
||
{
|
||
for(i=0;i<12;i++) // AT+CIPSTART=1,"UDP",“IP0.IP1.IP2.255”,9954,333,0
|
||
Send_Buffer[i]=CIPSTART[i];
|
||
|
||
Send_Buffer[12]=STR;
|
||
Send_Buffer[13]=',';
|
||
Send_Buffer[14]='"';
|
||
Send_Buffer[15]='U';
|
||
Send_Buffer[16]='D';
|
||
Send_Buffer[17]='P';
|
||
Send_Buffer[18]='"';
|
||
Send_Buffer[19]=',';
|
||
Send_Buffer[20]='"';
|
||
i=20;
|
||
if(LOC_IP_buf[0]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[0]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[0]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[0]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[0]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(LOC_IP_buf[1]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[1]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[1]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[1]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[1]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(LOC_IP_buf[2]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[2]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[2]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[2]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[2]%10+'0';
|
||
Send_Buffer[++i]='.';
|
||
|
||
if(LOC_IP_buf[3]/100)
|
||
{
|
||
Send_Buffer[++i]=LOC_IP_buf[3]/100+'0';
|
||
Send_Buffer[++i]=(LOC_IP_buf[3]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[3]%10+'0';
|
||
}
|
||
else if((LOC_IP_buf[3]/10)%10)
|
||
{
|
||
Send_Buffer[++i]=(LOC_IP_buf[3]/10)%10+'0';
|
||
Send_Buffer[++i]=LOC_IP_buf[3]%10+'0';
|
||
}
|
||
else
|
||
Send_Buffer[++i]=LOC_IP_buf[3]%10+'0';
|
||
|
||
i++;
|
||
Send_Buffer[i++]='"';
|
||
Send_Buffer[i++]=',';
|
||
Send_Buffer[i++]='9';
|
||
Send_Buffer[i++]='9';
|
||
Send_Buffer[i++]='5';
|
||
Send_Buffer[i++]='4';
|
||
Send_Buffer[i++]=',';
|
||
Send_Buffer[i++]='3';
|
||
Send_Buffer[i++]='3';
|
||
Send_Buffer[i++]='3';
|
||
Send_Buffer[i++]=',';
|
||
Send_Buffer[i++]='0';
|
||
|
||
Send_Buffer[i++]='\r'; // '\r'=0x0d;
|
||
Send_Buffer[i++]='\n'; // '\n'=0x0a;
|
||
Send_Num=i;
|
||
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,OK))==NULL&&flag_RS232_TimeoutStart);
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
make_AT_CIPSEND(20,255,255); // AT+CIPSEND=1,20,全网群发
|
||
UDP1_Return(11);
|
||
// 完整通讯结束。。。
|
||
}
|
||
}
|
||
|
||
/**********************模块连接服务器*TCP0***********************/
|
||
void ESP8266_CIPSTART_TCP(unsigned char STR)
|
||
{
|
||
unsigned char i,j;
|
||
|
||
if(1)//if(STR==1) // 方式一,组合再发
|
||
{
|
||
for(i=0;i<12;i++) //AT+CIPSTART=0,"TCP","192.168.61.128",9955
|
||
Send_Buffer[i]=CIPSTART[i];
|
||
|
||
Send_Buffer[12]=STR;
|
||
Send_Buffer[13]=',';
|
||
Send_Buffer[14]='"';
|
||
Send_Buffer[15]='T';
|
||
Send_Buffer[16]='C';
|
||
Send_Buffer[17]='P';
|
||
Send_Buffer[18]='"';
|
||
Send_Buffer[19]=',';
|
||
Send_Buffer[20]='"';
|
||
|
||
for(j=0;j<20;j++)
|
||
{
|
||
if(URL_ADDR[j]==0)
|
||
break;
|
||
}
|
||
|
||
if(j>10)
|
||
{
|
||
for(i=21;i<(j+21);i++)
|
||
Send_Buffer[i]=URL_ADDR[i-21];
|
||
Send_Buffer[i++]='"';
|
||
Send_Buffer[i++]=',';
|
||
Send_Buffer[i++]='9';
|
||
Send_Buffer[i++]='9';
|
||
Send_Buffer[i++]='5';
|
||
Send_Buffer[i++]='5';
|
||
Send_Buffer[i++]='\r'; // '\r'=0x0d;
|
||
Send_Buffer[i++]='\n'; // '\n'=0x0a;
|
||
Send_Num=i;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
}
|
||
}
|
||
/*
|
||
else if(STR==2) // 方式二,固定直发
|
||
{
|
||
for(i=0;i<12;i++)
|
||
Send_Buffer[i]=CIPSTART[i];
|
||
for(i=12;i<40;i++)
|
||
{
|
||
//Send_Buffer[i]=URL_TCP0_LOC104[i-12];//i<40 0,"TCP","192.168.0.104",8080 28
|
||
//Send_Buffer[i]=URL_TCP0_LOC128[i-12]; //i<41 0,"TCP","192.168.61.128",9955 29
|
||
Send_Buffer[i]=URL_TCP0_ifish7[i-12]; //i<40 0,"TCP","120.55.190.56",9955 28
|
||
}
|
||
|
||
Send_Buffer[i++]='\r'; // '\r'=0x0d;
|
||
Send_Buffer[i++]='\n'; // '\n'=0x0a;
|
||
Send_Num=i;
|
||
UART2_Send_Buffer_NoCheck(Send_Num);
|
||
}
|
||
*/
|
||
}
|
||
|
||
|
||
/**********************LCD显示刷新*********SEG0~SEG31***************/
|
||
void Lcd_Display(void)
|
||
{
|
||
/*
|
||
"8"字型段定义 col
|
||
---A--- ---A--- ---A--- ---A---
|
||
| | | | | | | |
|
||
F B F B . F B F B
|
||
| | | | | | | |
|
||
---G--- ---G--- ---G--- ---G---
|
||
| | | | | | | |
|
||
E C E C . E C E C
|
||
| | | | | | | |
|
||
---D--- ---D--- ---D--- ---D---
|
||
*/
|
||
unsigned char temp,lcd_high4,lcd_low4;
|
||
/*
|
||
ClockTimeSetup_Stepper 时钟设置:(当前北京时间设置)
|
||
1. 年十位
|
||
2. 年个位
|
||
3. 月十位
|
||
4. 月个位
|
||
5. 日十位
|
||
6. 日个位
|
||
7. 时十位
|
||
8. 时个位
|
||
9. 分十位
|
||
10.分个位
|
||
*/
|
||
|
||
// 时间小时个位值;SEG24+SEG23:
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==2)
|
||
temp=0x0;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Hour%10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Hour%10];
|
||
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
if(flag_Colon_Jump){lcd_high4=lcd_high4|0x1;} // COL标记“:”,跳闪
|
||
ht_writedata(23,lcd_high4,4); // SEG23:2A2B2C+COL
|
||
ht_writedata(24,lcd_low4,4); // SEG24:2F2G2E2D
|
||
|
||
// 时间分钟十位值;SEG22+SEG21
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==3)
|
||
temp=0x0;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Minute/10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Minute/10];
|
||
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_high4=lcd_high4|0x1;// S2=时间设置
|
||
lcd_low4=temp&0xf;
|
||
ht_writedata(21,lcd_high4,4); // SEG21:3A3B3C+S2
|
||
ht_writedata(22,lcd_low4,4); // SEG22:3F3G3E3D
|
||
|
||
// 时间分钟个位值;SEG20+SEG19:
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==4)
|
||
temp=0x0;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Minute%10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Minute%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
|
||
lcd_high4=lcd_high4|0x1;
|
||
if(flag_ClockTimeSetting&&flag_Colon_Jump)
|
||
lcd_high4&=0xFE; // S3=时间设置LOGO
|
||
|
||
lcd_low4=temp&0xf;
|
||
ht_writedata(19,lcd_high4,4);// SEG19:4A4B4C+S18
|
||
ht_writedata(20,lcd_low4,4); // SEG20:4F4G4E4D
|
||
|
||
// 灯光照明1LOGO: S29=lamp1-1左三点闪, S30=lamp1-2中三点闪, S31=lamp1-3右三点闪, S32=lamp1-0内心 SEG9+10
|
||
if(flag_lamp1_onoff)
|
||
{
|
||
temp=0xd9;
|
||
if(Lcd_Colon_TimeoutCounter>=1&&Lcd_Colon_TimeoutCounter<=5)
|
||
temp|=0x04;
|
||
if(Lcd_Colon_TimeoutCounter>=2&&Lcd_Colon_TimeoutCounter<=5)
|
||
temp|=0x02;
|
||
if(Lcd_Colon_TimeoutCounter>=3&&Lcd_Colon_TimeoutCounter<=5)
|
||
temp|=0x20;
|
||
}
|
||
else
|
||
{temp=0xff;}
|
||
//if(Key_Back==Lamp1_Key1)
|
||
//{
|
||
// if(flag_Colon_Jump)
|
||
// temp=0xff;
|
||
// else
|
||
// temp=0xd9;
|
||
//}
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4|=1;
|
||
ht_writedata(10,lcd_high4,4);// SEG10:*S13S12S14
|
||
ht_writedata(9,lcd_low4,4); // SEG9 :S16S10S11S17
|
||
|
||
// 时间小时十位值;SEG25
|
||
if(flag_LampTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump)
|
||
temp=0x0;
|
||
else if(flag_Open_Time)
|
||
temp=Lcd_Hour_Tab[Set_Open_Hour[(LampTimeSetup_Stepper-1)/2]/10];
|
||
else if(flag_Close_Time)
|
||
temp=Lcd_Hour_Tab[Set_Close_Hour[(LampTimeSetup_Stepper-1)/2]/10];
|
||
}
|
||
else if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==1)
|
||
{temp=0x0;}
|
||
else
|
||
{temp=Lcd_Hour_Tab[Disp_Hour/10];}
|
||
}
|
||
else
|
||
{temp=Lcd_Hour_Tab[Disp_Hour/10];}
|
||
|
||
lcd_low4=temp&0xf;
|
||
ht_writedata(25,lcd_low4,4); // SEG25:1B(1AGD)1C1E
|
||
/*
|
||
LampTimeSetup_Stepper 时段设置:lamp1,lamp2,UV-C
|
||
1.lamp1(1时段):1 开 定时器0-开 Set_Open_Hour + Set_Open_Minute
|
||
2. 1 关 定时器0-关 Set_Close_Hour+ Set_Close_Minute
|
||
3. 2 开 定时器1-开
|
||
4. 2 关 定时器1-关
|
||
5.lamp2(2时段):1 开 定时器2-开
|
||
6. 1 关 定时器2-关
|
||
7. 2 开 定时器3-开
|
||
8. 2 关 定时器3-关
|
||
9.UV-C(3时段): 1 开 定时器4-开
|
||
10. 1 关 定时器4-关
|
||
11. 2 开 定时器5-开
|
||
12. 2 关 定时器5-关
|
||
定时器6~定时器9 备用
|
||
*/
|
||
|
||
// LL=仪表盘,S8=“℃”,S9=温标,S7=Temperature
|
||
lcd_low4=0x0f;
|
||
ht_writedata(11,lcd_low4,4); // SEG11:LL+S8+S9+S7
|
||
|
||
// 温度值小位数X;SEG12+SEG13
|
||
temp=Lcd_Table0123456789[Real_Tempture%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // S4=调节键
|
||
ht_writedata(12,lcd_high4,4); // SEG12:7A7B7C+S4
|
||
ht_writedata(13,lcd_low4,4); // SEG13:7F7G7E7D
|
||
|
||
// 温度值个位数X;SEG14+SEG15
|
||
temp=Lcd_Table0123456789[Real_Tempture%100/10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // DP="."
|
||
ht_writedata(14,lcd_high4,4); // SEG14:6A6B6C+DP
|
||
ht_writedata(15,lcd_low4,4); // SEG15:6F6G6E6D
|
||
|
||
// 温度值十位数X;SEG16+SEG17
|
||
temp=Lcd_Table0123456789[Real_Tempture/100];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // S5=调节键LOGO
|
||
ht_writedata(16,lcd_high4,4); // SEG16:5A5B5C+S5
|
||
ht_writedata(17,lcd_low4,4); // SEG17:5F5G5E5D
|
||
|
||
// 自动+手动+锁+S6=1:SEG18
|
||
lcd_low4=0x1;
|
||
if(flag_ScreenLock_Status){lcd_low4|=0x2;} // 锁
|
||
if(flag_auto_hand){lcd_low4|=0x8;}else{lcd_low4|=0x4;}
|
||
ht_writedata(18,lcd_low4,4);
|
||
|
||
// 日显示 "个" 位数:SEG7+SEG6
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==10)
|
||
temp=0x00;
|
||
else
|
||
{temp=Lcd_Table0123456789[Disp_Day%10];}
|
||
}
|
||
else
|
||
{temp=Lcd_Table0123456789[Disp_Day%10];}
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_high4|=0x01;
|
||
lcd_low4=temp&0xf;
|
||
if(flag_Colon_Jump&&flag_Pump_onoff)
|
||
lcd_high4&=0xfe; // S15=水泵LOGO
|
||
ht_writedata(7,lcd_high4,4); // SEG7:13A13B13C+S15
|
||
ht_writedata(6,lcd_low4,4); // SEG6:13F13G13E13D
|
||
|
||
// 日显示 "十" 位数:SEG5
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==9)
|
||
{temp=0x00;}
|
||
else
|
||
{temp=lcd_day_tab[Disp_Day/10];}
|
||
}
|
||
else
|
||
{temp=lcd_day_tab[Disp_Day/10];}
|
||
lcd_low4=temp&0xf;
|
||
ht_writedata(5,lcd_low4,4); // SEG23:12B(12AGD)12C12E
|
||
|
||
// 月份显示 "个" 位数:SEG4+SEG3
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==8)
|
||
temp=0x00;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Month%10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Month%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1;
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==7)
|
||
lcd_high4=lcd_high4&0xe; // 10B=月十的"|"=1,"[|"=0
|
||
ht_writedata(4,lcd_high4,4); // SEG4:11A11B11C+10B
|
||
ht_writedata(3,lcd_low4,4); // SEG3:11F11G11E11D
|
||
|
||
// 年份显示 "十" 位数:SEG0+SEG8
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==5)
|
||
temp=0x00;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Year/10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Year/10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
lcd_high4=lcd_high4|0x1; // S1="20 - - "
|
||
ht_writedata(0,lcd_high4,4); // SEG0:8A8B8C+S1
|
||
ht_writedata(8,lcd_low4,4); // SEG8:8F8G8E8D
|
||
|
||
// 年份显示 "个" 位数:SEG2+SEG1
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==6)
|
||
temp=0x00;
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Year%10];
|
||
}
|
||
else
|
||
temp=Lcd_Table0123456789[Disp_Year%10];
|
||
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_low4=temp&0xf;
|
||
|
||
lcd_high4|=0x01;
|
||
if(Disp_Month<10)
|
||
{
|
||
if(flag_TimeSetup_Jump&&ClockTimeSetup_Stepper==7)
|
||
lcd_high4&=0x0e;
|
||
else
|
||
lcd_high4|=0x01; // 10A:月十的"["
|
||
}
|
||
else
|
||
{
|
||
lcd_high4&=0x0e;
|
||
}
|
||
ht_writedata(2,lcd_high4,4); // SEG26:9A9B9C+10A
|
||
ht_writedata(1,lcd_low4,4); // SEG27:9F9G9E9D
|
||
|
||
// 【“WiFi”】+【K3”()”】+【K2”( )”】+【K1”( )”】 :SEG26
|
||
lcd_low4=0x00;
|
||
if((flag_WiFi_ready&&flag_WiFi_Connect_Enable))
|
||
{
|
||
if(flag_WiFi_Disconnect) // 仅"((( )))"闪
|
||
{
|
||
if(flag_Colon_Jump)
|
||
lcd_low4=0x0f;
|
||
else
|
||
lcd_low4=0x08;
|
||
}
|
||
else if(flag_WiFi_Smarting) // 全闪"(((WIFI)))"
|
||
{
|
||
if(flag_Colon_Jump)
|
||
lcd_low4=0x0f;
|
||
else
|
||
lcd_low4=0x00;
|
||
}
|
||
else if(flag_WiFi_Connected==0) // 仅"((( )))"闪
|
||
{
|
||
if(flag_Colon_Jump)
|
||
lcd_low4=0x0f;
|
||
else
|
||
lcd_low4=0x08;
|
||
}
|
||
else if(flag_TCP0_Connected==0) // 仅"WIFI"闪
|
||
{
|
||
if(flag_Colon_Jump)
|
||
lcd_low4=0x0f;
|
||
else
|
||
lcd_low4=0x07;
|
||
}
|
||
else if(flag_WiFi_Connected&&flag_TCP0_Connected) // 不闪
|
||
{
|
||
lcd_low4=0x0f;
|
||
}
|
||
}
|
||
ht_writedata(26,lcd_low4,4); // SEG30:WiFi+K3+K2+K1:"(((WiFi)))"
|
||
}
|
||
|
||
/*********************温度表查*************************/
|
||
const float tempture_tab[]=
|
||
{
|
||
34.467,32.946,31.508,30.147,28.835,
|
||
27.606,26.427,25.308,24.236,23.218,22.259,21.331,20.450,19.621,18.819,
|
||
18.018,17.322,16.641,15.968,15.337,14.750,14.615,13.618,13.081,12.581,
|
||
12.110,11.647,11.210,10.786,10.386,10.000,9.631,9.277,8.937,8.613,
|
||
8.302,8.003,7.718,7.445,7.182,6.929,6.688,6.457,6.233,6.019,
|
||
5.813,5.616,5.427,5.244,5.069,4.901,4.740,4.582,4.435,4.288,
|
||
4.151,4.016,3.880,3.764,3.644,3.527,3.416,3.308,3.205,3.106,
|
||
3.011,2.919,2.830,2.744,2.662,2.583,2.504,2.430,2.359,2.289,
|
||
2.224,2.158,2.096,2.036,1.978,1.921,1.867,1.814,1.764,1.714,
|
||
1.667,1.621,1.576,1.533,1.492,1.451,1.412,1.374,1.338,1.302,
|
||
1.268,1.235,1.203,1.171,1.141,1.112,1.083,1.056,1.029,1.003,0.9777
|
||
};
|
||
float cha_biao(float tem_num)
|
||
{
|
||
float temp;
|
||
unsigned char i;
|
||
|
||
for(i=0;i<106;i++)
|
||
{
|
||
if(tem_num>tempture_tab[i])
|
||
{break;}
|
||
}
|
||
|
||
if(i>=105)
|
||
{temp=99.9;}
|
||
else if(i<=5)
|
||
{temp=0;}
|
||
else
|
||
{temp=(tempture_tab[i-1]-tem_num)/(tempture_tab[i-1]-tempture_tab[i])-5-1+i;}
|
||
return(temp);
|
||
}
|
||
|
||
/*********************AD读温度值*************************/
|
||
float ADC_DATA=0;
|
||
void Read_Tempture(void)
|
||
{
|
||
float TEMP;
|
||
//static float ADC_DATA;
|
||
|
||
/*
|
||
if((ADC_CSR & 0x80) == 0x80)
|
||
{
|
||
//ADC_DATA=ADC_DATA>>2;
|
||
temp=10*(float)ADC_DRH/(0x100-(float)ADC_DRH);
|
||
// temp=10*(float)(ADC_DATA/(0x100-ADC_DATA));
|
||
temp=cha_biao(temp);
|
||
tempture_temp=tempture_temp+temp;
|
||
if(++Tempture_Read_Counter>39)
|
||
{
|
||
Tempture_Read_Counter=0;
|
||
Real_Tempture=(((int)tempture_temp>>2)+Real_Tempture)>>1;
|
||
tempture_temp=0;
|
||
}
|
||
ADC_CSR&=0x7f; //清转换结束标志
|
||
ADC_CR1|=0x01; // 再次将CR1寄存器的最低位置1//启动ad转换
|
||
}
|
||
*/
|
||
if((ADC_CSR & 0x80) == 0x80)
|
||
{
|
||
//ADC_DATA=ADC_DATA>>2;
|
||
TEMP=10*(float)ADC_DRH/(0x100-(float)ADC_DRH);
|
||
// temp=10*(float)(ADC_DATA/(0x100-ADC_DATA));
|
||
TEMP=cha_biao(TEMP);
|
||
ADC_DATA+=TEMP;
|
||
if(++Tempture_Read_Counter>39)
|
||
{
|
||
Tempture_Read_Counter=0;
|
||
|
||
if((Real_Tempture>Set_High_Tempture)||(Real_Tempture<Set_Low_Tempture))
|
||
flag_Tempture_Abnormal_Q0=1;
|
||
else
|
||
flag_Tempture_Abnormal_Q0=0;
|
||
|
||
//[Set_High_Tempture : Set_Low_Tempture],exp:[15C:35C]
|
||
Real_Tempture=(((int)ADC_DATA>>2)+Real_Tempture)>>1;
|
||
ADC_DATA=0;
|
||
//[Set_High_Tempture : Set_Low_Tempture],exp:[15C:35C]
|
||
|
||
if((Real_Tempture>Set_High_Tempture)||(Real_Tempture<Set_Low_Tempture))
|
||
flag_Tempture_Abnormal_Q1=1;
|
||
else
|
||
flag_Tempture_Abnormal_Q1=0;
|
||
|
||
if(Real_Tempture>Set_High_Tempture)
|
||
TemptureAlam_NormalLowHigh='H';
|
||
else if(Real_Tempture<Set_Low_Tempture)
|
||
TemptureAlam_NormalLowHigh='L';
|
||
else
|
||
TemptureAlam_NormalLowHigh='N';
|
||
|
||
if((Real_Tempture>Set_High_Tempture)||(Real_Tempture<Set_Low_Tempture))
|
||
{
|
||
if(flag_Tempture_Abnormal_Q0!=flag_Tempture_Abnormal_Q1)
|
||
flag_Tempture_Abnormal=1;
|
||
}
|
||
}
|
||
ADC_CSR&=0x7f; // 清转换结束标志
|
||
ADC_CR1|=0x01; // 再次将CR1寄存器的最低位置1//启动ad转换
|
||
}
|
||
|
||
}
|
||
|
||
//const unsigned char lcd_8tab[]={0xeb,0x60,0xc7,0xe5,0x6c,0xad,0xaf,0xe0,0xef,0xed,0x00,0x00,0x00,0x00,0x00};
|
||
/**********************LCD显示刷新*********SEG0~SEG31***************/
|
||
void Lcd_Disp_KeyDynamic(void)
|
||
{
|
||
unsigned char lcd_low4,lcd_high4,temp;
|
||
|
||
switch(Key_Back)
|
||
{ // 《灯光照明》的键值=3
|
||
case 3: lcd_low4=0x09;
|
||
if(flag_TimeSetup_Jump)
|
||
lcd_low4=0x0f;
|
||
ht_writedata(10,lcd_low4,4);
|
||
ht_writedata(9,lcd_low4,4);
|
||
break;
|
||
|
||
// 《水泵》 的键值=2
|
||
case 2: temp=Lcd_Table0123456789[Disp_Day%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
if(flag_TimeSetup_Jump)
|
||
lcd_high4|=0x01;
|
||
ht_writedata(7,lcd_high4,4);
|
||
break;
|
||
|
||
// 《调节键》 的键值=4
|
||
case 4: temp=Lcd_Table0123456789[Real_Tempture/100];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
if(flag_TimeSetup_Jump)
|
||
lcd_high4|=0x01;
|
||
ht_writedata(16,lcd_high4,4);
|
||
|
||
break;
|
||
|
||
// 《时间设置》的键值=5
|
||
case 5: temp=Lcd_Table0123456789[Disp_Minute%10];
|
||
lcd_high4=(temp&0xf0)>>4;
|
||
lcd_high4|=0x01;
|
||
if(flag_TimeSetup_Jump)
|
||
lcd_high4&=0xfe;
|
||
ht_writedata(19,lcd_low4,4);
|
||
break;
|
||
|
||
// (((WIFI))) 的键值=6
|
||
case 6: lcd_low4=0x00;
|
||
if(flag_TimeSetup_Jump)
|
||
lcd_low4=0x0f;
|
||
ht_writedata(26,lcd_low4,4);
|
||
break;
|
||
default:break;
|
||
}
|
||
}
|
||
|
||
//**************对于按键值进行分析**********************//
|
||
void Key_Scanning_OK(void)
|
||
{
|
||
unsigned char unit,decade,key_use,key_unlock;
|
||
|
||
key_use=Read_Key_Num(); // 读键值
|
||
|
||
if(Key_Back==key_use&&Key_Back!=0xff) // Key_Back=上一次键值
|
||
{
|
||
if(++Key_Shake>=25) // 去键抖动25
|
||
{
|
||
Key_Shake=0;
|
||
UnLockScreen_TimeoutCounter=0;
|
||
LockScreen_TimeoutCounter=0;
|
||
|
||
if(flag_ScreenLock_Status==1) // 判断屏状态
|
||
{
|
||
do
|
||
{
|
||
flag_have_key=1;
|
||
key_unlock=Read_Key_Num();
|
||
Lcd_Disp_KeyDynamic();
|
||
//Delay_ms(100);
|
||
Lcd_Display();
|
||
}while(flag_ScreenLock_Status==1&&key_unlock!=0xff);
|
||
if(flag_ScreenLock_Status==0)
|
||
{
|
||
Lcd_Display();
|
||
//if(flag_Buzzer==0){ht_writecmd(Command, toneoff);flag_Buzzer=1;}
|
||
}
|
||
if(key_unlock==0xff) // 防止半途松开按键
|
||
{
|
||
flag_ScreenLock_Status=1;
|
||
flag_have_key=0;
|
||
}
|
||
ht_writecmd(Command, toneon);
|
||
while(Read_Key_Num()!=0xff); // 等待键松开
|
||
ht_writecmd(Command, toneoff);
|
||
}
|
||
else
|
||
//if(flag_ScreenLock_Status==0) // 不锁屏的情况下直接按键操作
|
||
{
|
||
key_use=Read_Key_Num();
|
||
flag_have_key=1;
|
||
//if(flag_Buzzer==0){ht_writecmd(Command, toneoff);flag_Buzzer=1;}
|
||
|
||
switch(key_use)
|
||
{
|
||
case Lamp1_Key1:
|
||
if(flag_auto_hand==0)
|
||
{flag_lamp1_onoff=(~flag_lamp1_onoff)&0x01;}
|
||
break;
|
||
|
||
case Lamp2_Key2:
|
||
if(flag_auto_hand==0)
|
||
{flag_lamp2_onoff=(~flag_lamp2_onoff)&0x01;}
|
||
break;
|
||
|
||
case Pump_Key3:
|
||
if(flag_auto_hand==0)
|
||
{flag_Pump_onoff=(~flag_Pump_onoff)&0x01;}
|
||
break;
|
||
|
||
case Adjust_Key4:
|
||
/*
|
||
ClockTimeSetup_Stepper 时段设置:lamp1,lamp2,UV-C
|
||
1.lamp1(1时段):1 开 定时器0-开
|
||
2. 1 关 定时器0-关
|
||
3. 2 开 定时器1-开
|
||
4. 2 关 定时器1-关
|
||
5.lamp2(2时段):1 开 定时器2-开
|
||
6. 1 关 定时器2-关
|
||
7. 2 开 定时器3-开
|
||
8. 2 关 定时器3-关
|
||
9.UV-C(3时段): 1 开 定时器4-开
|
||
10. 1 关 定时器4-关
|
||
11. 2 开 定时器5-开
|
||
12. 2 关 定时器5-关
|
||
定时器6~定时器9 备用
|
||
*/
|
||
if(flag_LampTimeSetting) // 处于《灯的定时》设置状态...
|
||
{
|
||
switch(LampTimeSetup_Stepper) // 共12步,12个位置调节
|
||
{
|
||
case 1:
|
||
if(Set_Open_Minute[0]!=0)
|
||
{
|
||
Set_Open_Minute[0]=0;
|
||
if(++Set_Open_Hour[0]>=24)
|
||
{Set_Open_Hour[0]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[0]=30;}
|
||
break;
|
||
|
||
case 2:
|
||
if(Set_Close_Minute[0]!=0)
|
||
{
|
||
Set_Close_Minute[0]=0;
|
||
if(++Set_Close_Hour[0]>=24)
|
||
{Set_Close_Hour[0]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[0]=30;}
|
||
break;
|
||
|
||
case 3:
|
||
if(Set_Open_Minute[1]!=0)
|
||
{
|
||
Set_Open_Minute[1]=0;
|
||
if(++Set_Open_Hour[1]>=24)
|
||
{Set_Open_Hour[1]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[1]=30;}
|
||
break;
|
||
|
||
case 4:
|
||
if(Set_Close_Minute[1]!=0)
|
||
{
|
||
Set_Close_Minute[1]=0;
|
||
if(++Set_Close_Hour[1]>=24)
|
||
{Set_Close_Hour[1]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[1]=30;}
|
||
break;
|
||
|
||
case 5:
|
||
if(Set_Open_Minute[2]!=0)
|
||
{
|
||
Set_Open_Minute[2]=0;
|
||
if(++Set_Open_Hour[2]>=24)
|
||
{Set_Open_Hour[2]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[2]=30;}
|
||
break;
|
||
|
||
case 6:
|
||
if(Set_Close_Minute[2]!=0)
|
||
{
|
||
Set_Close_Minute[2]=0;
|
||
if(++Set_Close_Hour[2]>=24)
|
||
{Set_Close_Hour[2]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[2]=30;}
|
||
break;
|
||
|
||
case 7:
|
||
if(Set_Open_Minute[3]!=0)
|
||
{
|
||
Set_Open_Minute[3]=0;
|
||
if(++Set_Open_Hour[3]>=24)
|
||
{Set_Open_Hour[3]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[3]=30;}
|
||
break;
|
||
|
||
case 8:
|
||
if(Set_Close_Minute[3]!=0)
|
||
{
|
||
Set_Close_Minute[3]=0;
|
||
if(++Set_Close_Hour[3]>=24)
|
||
{Set_Close_Hour[3]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[3]=30;}
|
||
break;
|
||
|
||
case 9:
|
||
if(Set_Open_Minute[4]!=0)
|
||
{
|
||
Set_Open_Minute[4]=0;
|
||
if(++Set_Open_Hour[4]>=24)
|
||
{Set_Open_Hour[4]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[4]=30;}
|
||
break;
|
||
|
||
case 10:
|
||
if(Set_Close_Minute[4]!=0)
|
||
{
|
||
Set_Close_Minute[4]=0;
|
||
if(++Set_Close_Hour[4]>=24)
|
||
{Set_Close_Hour[4]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[4]=30;}
|
||
break;
|
||
|
||
case 11:
|
||
if(Set_Open_Minute[5]!=0)
|
||
{
|
||
Set_Open_Minute[5]=0;
|
||
if(++Set_Open_Hour[5]>=24)
|
||
{Set_Open_Hour[5]=0;}
|
||
}
|
||
else
|
||
{Set_Open_Minute[5]=30;}
|
||
break;
|
||
|
||
case 12:
|
||
if(Set_Close_Minute[5]!=0)
|
||
{
|
||
Set_Close_Minute[5]=0;
|
||
if(++Set_Close_Hour[5]>=24)
|
||
{Set_Close_Hour[5]=0;}
|
||
}
|
||
else
|
||
{Set_Close_Minute[5]=30;}
|
||
break;
|
||
|
||
default:
|
||
LampTimeSetup_Stepper=0;
|
||
flag_LampTimeSetting=0;
|
||
break;
|
||
}
|
||
}
|
||
/*
|
||
LampTimeSetup_Stepper 时钟设置:(当前北京时间设置)
|
||
1. 年十位
|
||
2. 年个位
|
||
3. 月十位
|
||
4. 月个位
|
||
5. 日十位
|
||
6. 日个位
|
||
7. 时十位
|
||
8. 时个位
|
||
9. 分十位
|
||
10.分个位
|
||
*/
|
||
else if(flag_ClockTimeSetting) // 处于《时钟调时》设置状态...
|
||
{
|
||
switch(ClockTimeSetup_Stepper) // 共10步,10个位置调节
|
||
{
|
||
case 1:
|
||
unit=Disp_Hour%10;
|
||
decade=Disp_Hour/10;
|
||
decade++;
|
||
decade%=3;
|
||
Disp_Hour=decade*10+unit;
|
||
break;
|
||
|
||
case 2:
|
||
unit=Disp_Hour%10;
|
||
decade=Disp_Hour/10;
|
||
unit++;
|
||
if(decade==2)
|
||
unit%=4;
|
||
else
|
||
unit%=10;
|
||
Disp_Hour=decade*10+unit;
|
||
break;
|
||
|
||
case 3:
|
||
unit=Disp_Minute%10;
|
||
decade=Disp_Minute/10;
|
||
decade++;
|
||
decade%=6;
|
||
Disp_Minute=decade*10+unit;
|
||
break;
|
||
|
||
case 4:
|
||
unit=Disp_Minute%10;
|
||
decade=Disp_Minute/10;
|
||
unit++;
|
||
unit%=10;
|
||
Disp_Minute=decade*10+unit;
|
||
break;
|
||
|
||
case 5:
|
||
unit=Disp_Year%10;
|
||
decade=Disp_Year/10;
|
||
decade++;
|
||
decade%=10;
|
||
Disp_Year=decade*10+unit;
|
||
break;
|
||
|
||
case 6:
|
||
unit=Disp_Year%10;
|
||
decade=Disp_Year/10;
|
||
unit++;
|
||
unit%=10;
|
||
Disp_Year=decade*10+unit;
|
||
break;
|
||
|
||
case 7:
|
||
unit=Disp_Month%10;
|
||
decade=Disp_Month/10;
|
||
decade++;
|
||
decade%=2;
|
||
Disp_Month=decade*10+unit;
|
||
break;
|
||
|
||
case 8:
|
||
unit=Disp_Month%10;
|
||
decade=Disp_Month/10;
|
||
unit++;
|
||
if(decade==1) unit%=3;
|
||
else unit%=10;
|
||
if(decade==0&&unit==0) unit=1;
|
||
Disp_Month=decade*10+unit;
|
||
break;
|
||
|
||
case 9:
|
||
unit=Disp_Day%10;
|
||
decade=Disp_Day/10;
|
||
decade++;
|
||
decade%=4;
|
||
if(decade==0&&unit==0) unit=1;
|
||
Disp_Day=decade*10+unit;
|
||
break;
|
||
|
||
case 10:
|
||
unit=Disp_Day%10;
|
||
decade=Disp_Day/10;
|
||
unit++;
|
||
if(decade==3) unit%=2;
|
||
else unit%=10;
|
||
if(decade==0&&unit==0) unit=1;
|
||
Disp_Day=decade*10+unit;
|
||
break;
|
||
|
||
default:
|
||
ClockTimeSetup_Stepper=0;
|
||
flag_ClockTimeSetting=0;
|
||
break;
|
||
}
|
||
}
|
||
else // 手动自动切换
|
||
{
|
||
flag_auto_hand_change=1;
|
||
do
|
||
{
|
||
flag_have_key=1;
|
||
key_use=Read_Key_Num();
|
||
Lcd_Disp_KeyDynamic();
|
||
//Delay_ms(100);
|
||
Lcd_Display();
|
||
}while(flag_auto_hand_change==1&&key_use!=0xff);
|
||
|
||
if(flag_auto_hand_change==0)
|
||
{
|
||
flag_auto_hand=(~flag_auto_hand)&0x01;
|
||
Lcd_Display();
|
||
}
|
||
|
||
if(key_use==0xff) // 防止半途松开按键
|
||
{
|
||
flag_auto_hand_change=0;
|
||
flag_have_key=0;
|
||
}
|
||
//ht_writecmd(Command, toneon);
|
||
//while(Read_Key_Num()!=0xff); // 等待键松开
|
||
//ht_writecmd(Command, toneoff);
|
||
}
|
||
break;
|
||
|
||
case Lamp_ShiDuan_Key5:
|
||
flag_LampTimeSetting=1; // 即将进行《灯的定时》设置
|
||
flag_ClockTimeSetting=0;
|
||
LampTimeSetup_Stepper++;
|
||
|
||
if(LampTimeSetup_Stepper%2==1)
|
||
{flag_Open_Time=1;flag_Close_Time=0;}
|
||
else
|
||
{flag_Open_Time=0;flag_Close_Time=1;}
|
||
|
||
if(LampTimeSetup_Stepper>12)
|
||
{
|
||
LampTimeSetup_Stepper=0;
|
||
flag_LampTimeSetting=0;
|
||
flag_LampTime_Change=1;
|
||
//MCUeeprom_write();
|
||
//MCUeeprom_read();
|
||
}
|
||
break;
|
||
|
||
case Clock_Setup_Key6:
|
||
flag_ClockTimeSetting=1; // 即将进行《时钟调时》设置
|
||
flag_LampTimeSetting=0;
|
||
ClockTimeSetup_Stepper++;
|
||
if(ClockTimeSetup_Stepper>10)
|
||
{
|
||
Write_Time();
|
||
//Disp_Year=Disp_Month=Disp_Day=Disp_Hour=Disp_Minute=Disp_Week=0;
|
||
//Read_Time();
|
||
ClockTimeSetup_Stepper=0;
|
||
flag_ClockTimeSetting=0;
|
||
flag_ClockTime_Change=1;
|
||
}
|
||
break;
|
||
|
||
case WIFI_Key6:
|
||
flag_auto_hand_change=1;
|
||
do
|
||
{
|
||
flag_have_key=1;
|
||
key_use=Read_Key_Num();
|
||
Lcd_Disp_KeyDynamic();
|
||
//Delay_ms(100);
|
||
Lcd_Display();
|
||
}while(flag_auto_hand_change==1&&key_use!=0xff);
|
||
|
||
if(flag_auto_hand_change==0)
|
||
{
|
||
System_Init();
|
||
ESP8266_RESTORE();
|
||
flag_RESTORE=1;
|
||
}
|
||
|
||
if(key_use==0xff) // 防止半途松开按键
|
||
{
|
||
flag_auto_hand_change=0;
|
||
flag_have_key=0;
|
||
}
|
||
break;
|
||
|
||
default:break;
|
||
}
|
||
//if((flag_LampTimeSetting&&key_use==Adjust_Key4)||(flag_ClockTimeSetting&&key_use==Adjust_Key4)||key_use<4||key_use==5|key_use==6)
|
||
{
|
||
ht_writecmd(Command, toneon);
|
||
while(Read_Key_Num()!=0xff); // 等待键松开
|
||
ht_writecmd(Command, toneoff);
|
||
}
|
||
MCUeeprom_write();
|
||
}
|
||
}
|
||
}
|
||
else // 去键抖动 or 没有按键的情况下:
|
||
{
|
||
Key_Shake=0;
|
||
Key_Back=key_use;
|
||
flag_have_key=0;
|
||
}
|
||
}
|
||
|
||
/*********************自动还是手动处理*************************/
|
||
void Autohand_Control(void)
|
||
{
|
||
unsigned char i;
|
||
unsigned int Timer_open[10],Timer_close[10],Now_time;
|
||
/*
|
||
@near unsigned char Timers_Enable[11]; 1,2,3,4,5,6,7,8,9,10
|
||
@near unsigned char Set_Open_Hour[10]; 0,1,2,3,4,5,6,7,8,9
|
||
@near unsigned char Set_Open_Minute[10]; 0,1,2,3,4,5,6,7,8,9
|
||
@near unsigned char Set_Close_Hour[10]; 0,1,2,3,4,5,6,7,8,9
|
||
@near unsigned char Set_Close_Minute[10]; 0,1,2,3,4,5,6,7,8,9
|
||
*/
|
||
if(flag_auto_hand==1) //0=手动,1=自动
|
||
{
|
||
for(i=0;i<4;i++)
|
||
{
|
||
Timer_open[i] =Set_Open_Hour[i]*60+Set_Open_Minute[i];
|
||
Timer_close[i]=Set_Close_Hour[i]*60+Set_Close_Minute[i];
|
||
}
|
||
Now_time=Disp_Hour*60+Disp_Minute;
|
||
|
||
// Timer1 = 1时段(Lamp1):1开 1关
|
||
if(Timers_Enable[1]&&(Now_time>=Timer_open[0])&&(Now_time<Timer_close[0])&&(Timer_open[0]<Timer_close[0]))
|
||
flag_lamp1_onoff=1;
|
||
// Timer2 = 1时段(Lamp1):2开 2关
|
||
else if(Timers_Enable[2]&&(Now_time>=Timer_open[1])&&(Now_time<Timer_close[1])&&(Timer_open[1]<Timer_close[1]))
|
||
flag_lamp1_onoff=1;
|
||
else
|
||
flag_lamp1_onoff=0;
|
||
|
||
|
||
// Timer3 = 2时段(Lamp2):1开 1关
|
||
if(Timers_Enable[3]&&(Now_time>=Timer_open[2])&&(Now_time<Timer_close[2])&&(Timer_open[2]<Timer_close[2]))
|
||
flag_Pump_onoff=1;//flag_lamp2_onoff=1;
|
||
// Timer4 = 2时段(Lamp2):2开 2关
|
||
else if(Timers_Enable[4]&&(Now_time>=Timer_open[3])&&(Now_time<Timer_close[3])&&(Timer_open[3]<Timer_close[3]))
|
||
flag_Pump_onoff=1; //flag_lamp2_onoff=1;
|
||
else
|
||
flag_Pump_onoff=0;//flag_lamp2_onoff=0;
|
||
|
||
/*
|
||
// Timer5 = 3时段(Pump_pump):1开 1关
|
||
if(Timers_Enable[5]&&(Now_time>=Timer_open[4])&&(Now_time<Timer_close[4])&&(Timer_open[4]<Timer_close[4]))
|
||
flag_Pump_onoff=1;
|
||
// Timer6 = 3时段(Pump_pump):2开 2关
|
||
else if(Timers_Enable[6]&&(Now_time>=Timer_open[5])&&(Now_time<Timer_close[5])&&(Timer_open[5]<Timer_close[5]))
|
||
flag_Pump_onoff=1;
|
||
else
|
||
flag_Pump_onoff=0;
|
||
*/
|
||
// Timer7 = 4时段(...):1开 1关 Timers_Enable[7]
|
||
// Timer8 = 4时段(...):2开 2关 Timers_Enable[8]
|
||
|
||
// Timer9 = 5时段(...):1开 1关 Timers_Enable[9]
|
||
// Timer10 = 5时段(...):2开 2关 Timers_Enable[10]
|
||
}
|
||
|
||
if(flag_lamp1_onoff)
|
||
Lamp1_PB2=1;
|
||
else
|
||
Lamp1_PB2=0;
|
||
|
||
//if(flag_lamp2_onoff){lamp2_PC5=1;}
|
||
//else{lamp2_PC5=0;}
|
||
|
||
if(flag_Pump_onoff)
|
||
Pump_PB3=1;
|
||
else
|
||
Pump_PB3=0;
|
||
}
|
||
|
||
|
||
/*********************形成整个帧数据链,发送*************************/
|
||
void CIPSendData_Process(void) // +IPD,0,32:http://www.cmsoft.cn QQ:10865600
|
||
{
|
||
unsigned char i;
|
||
unsigned int CRC16 = 0xffff;
|
||
|
||
// 上电若ready设置flag_ready_Monitoring5s=1,若5s无入网信息, 则重新启动智能入网,设置flag_ready5s_STARTSMART=1
|
||
if((flag_ready5s_STARTSMART&&flag_WiFi_ready)||(flag_RESTORE&&flag_WiFi_ready))
|
||
{
|
||
flag_ready5s_STARTSMART=0;
|
||
flag_ready_Monitoring5s=0;
|
||
|
||
ESP8266_STARTSMART();
|
||
flag_RESTORE=0;
|
||
}
|
||
// 连接服务器失败,约10s重连
|
||
else if(flag_Enable_Connect_TCP)
|
||
{
|
||
flag_Enable_Connect_TCP=0;
|
||
ESP8266_CIPSTART_TCP('0');// 开启TCP1连接
|
||
}
|
||
else if(flag_LoginTCP_SendOnce) // 登录TCP服务器 24
|
||
{
|
||
flag_LoginTCP_SendOnce=0;
|
||
flag_NoLoginBack_Monitoring150s=1;
|
||
|
||
make_AT_CIPSEND(24,0,255); // 命令头:AT+CIPSEND=0,len 【0=id,len=数据长度】;
|
||
Function_Code=1;
|
||
Load_Header_15data(0,'S');
|
||
Send_Buffer[15]=factory_data;
|
||
Send_Buffer[16]=pcb_data;
|
||
Send_Buffer[17]=mcu_data;
|
||
for(i=18;i<22;i++)
|
||
Send_Buffer[i]=LOC_IP_buf[i-18];
|
||
CRC16=GetRevCrc_16(Send_Buffer,22);
|
||
Send_Buffer[22]=CRC16>>8;
|
||
Send_Buffer[23]=CRC16;
|
||
Send_Num=24;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,SEND_OK))==NULL&&flag_RS232_TimeoutStart);// 此循环完成 SEND OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
System_Status=161;
|
||
// 打印了 "SEND OK"
|
||
flag_SEND_FAIL=0;
|
||
}
|
||
else
|
||
{
|
||
System_Status=160;
|
||
// 打印了 "SEND FAIL"
|
||
flag_SEND_FAIL=1;
|
||
}
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
// 等待回复,接收网络时间;
|
||
|
||
}
|
||
else if(flag_TCP_Logined)
|
||
{
|
||
if(flag_Tempture_Abnormal&&TemptureAlam_NormalLowHigh!='N')// 温度异常报警(包括:高温和低温) 22
|
||
{
|
||
if(TemptureAlam_Close_Open_Setup==1) // 报警状态开启的情况下
|
||
{
|
||
if((Real_Tempture>(Set_High_Tempture+6))||(Real_Tempture<(Set_Low_Tempture-6)))
|
||
{
|
||
flag_Tempture_Abnormal=0;
|
||
make_AT_CIPSEND(22,0,255); // 命令头:AT+CIPSEND=0,len 【0=id,len=数据长度】;
|
||
Function_Code=9;
|
||
Load_Header_15data(0,'S');
|
||
|
||
Send_Buffer[16]=Real_Tempture/0x100;
|
||
Send_Buffer[17]=Real_Tempture%0x100;//温度
|
||
if('H'==TemptureAlam_NormalLowHigh)
|
||
{
|
||
Send_Buffer[15]=1;
|
||
Send_Buffer[18]=Set_High_Tempture/0x100;
|
||
Send_Buffer[19]=Set_High_Tempture%0x100;//报警温度 High
|
||
}
|
||
else if('L'==TemptureAlam_NormalLowHigh)
|
||
{
|
||
Send_Buffer[15]=0;
|
||
Send_Buffer[18]=Set_Low_Tempture/0x100;
|
||
Send_Buffer[19]=Set_Low_Tempture%0x100;//报警温度 Low
|
||
}
|
||
CRC16=GetRevCrc_16(Send_Buffer,20);
|
||
Send_Buffer[20]=CRC16>>8;
|
||
Send_Buffer[21]=CRC16;
|
||
Send_Num=22;
|
||
UART2_Send_Buffer_Check(Send_Num);
|
||
while((pStr1=strstr(Receive_Buffer1,SEND_OK))==NULL);// 此循环完成 SEND OK
|
||
flag_RS232_TimeoutStart=0;
|
||
InBuffer_ID=0;Receive_Count0=0;
|
||
|
||
if(pStr1!=NULL)
|
||
{
|
||
System_Status=201;
|
||
// 打印了 "SEND OK"
|
||
flag_SEND_FAIL=0;
|
||
}
|
||
else
|
||
{
|
||
System_Status=200;
|
||
// 打印了 "SEND FAIL"
|
||
flag_SEND_FAIL=1;
|
||
}
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
// 等待回复
|
||
}
|
||
}
|
||
}
|
||
|
||
else if(flag_HeartBeat10s)//&&flag_NoLoginBack_Monitoring150s==0) // 心跳包
|
||
{
|
||
flag_HeartBeat10s=0;
|
||
HeartBeat10s_TimeoutCounter=0;
|
||
make_AT_CIPSEND(57,0,'0'); // 命令头:AT+CIPSEND=0,len 【0=id,len=数据长度】;
|
||
Function_Code=8;
|
||
Heart_and_State_Return('S');
|
||
// 不回复
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/*********************形成整个帧数据链,接收*************************/
|
||
// \r\n +IPD,0,xx:0Fdd...
|
||
// LOCMAC,"18:fe:34:db:0d:33"
|
||
// RMTMAC,"5c:cf:7f:07:65:21"
|
||
//const unsigned char maohao[]={":"};
|
||
const unsigned char test_IPD[]={'\r','\n','+','I','P','D',',','0',',','1','9',
|
||
'1','9','2','.','1','9','2','.','1','9','2','.','1','9','2',',','9','9','9','9',':',
|
||
0, // 发送方0
|
||
7, // 功能码
|
||
0x18,0xfe,0x34,0xdb,0x0d,0x33, // LOC_MAC
|
||
0x5c,0xcf,0x7f,0x07,0x65,0x21, // RMT_MAC
|
||
19, // 数据长度
|
||
11,22,33,44,55,66,77,88, // data
|
||
'C','R' // CRC16
|
||
};
|
||
void ReceiveData_Process(void) // +IPD,0,32:http://www.cmsoft.cn QQ:10865600
|
||
{
|
||
unsigned char i,j,temp,CRC16_L,CRC16_H,CRC16_Check_OK;
|
||
unsigned int CRC16 = 0xffff;
|
||
/*
|
||
flag_Receive_NewFrame_Buffer0=1;
|
||
for(i=0;i<50;i++)
|
||
Receive_Buffer0[i]=test_IPD[i];
|
||
|
||
temp=strloc(Receive_Buffer0,plusIPD);
|
||
temp=0;
|
||
temp=strloc(Receive_Buffer0,"+IPD,");
|
||
temp=0;
|
||
temp=strloc(Receive_Buffer0,plusIPD);
|
||
temp=0;
|
||
*/
|
||
if(flag_Receive_NewFrame_Buffer0)
|
||
{
|
||
flag_Receive_NewFrame_Buffer0=0;
|
||
|
||
HeartBeat10s_TimeoutCounter=0;
|
||
HeartBeat_0_TimeoutCounter=0;
|
||
HeartBeat_1_TimeoutCounter=0;
|
||
|
||
//for(i=0;i<Receive_Num;i++)
|
||
// Receive_Buffer0[i]=Receive_Buffer1[i];
|
||
|
||
Receive_NewFrame_Length=0;
|
||
temp=CRC16_Check_OK=0;
|
||
if((pStr0=strstr(Receive_Buffer0,plusIPD))!=NULL)// "+IPD,"【相当于处于接收状态下】
|
||
{
|
||
temp=strloc(Receive_Buffer0,plusIPD);
|
||
//\r\n +IPD,0,xx:0Fdd... 多路连接时(+CIPMUX=1)+IPD,<id>,<len> :<data>
|
||
// +IPD,<id>,<len>[,<remote IP>,<remote port>]:<data>
|
||
// 0 1 23456789abcdef
|
||
//例如:\r\n+IPD,0,32:http://www.cmsoft.cn QQ:10865600
|
||
|
||
if(Receive_Buffer0[temp+5]=='0') // id号
|
||
{Link_id='0';}
|
||
else // if(Receive_Buffer0[temp+7]=='1')
|
||
{Link_id='1';} // udp_adder=Receive_Buffer0[temp+7];
|
||
|
||
temp=temp+7; // =9
|
||
|
||
if((Receive_Buffer0[temp]>='0')&&(Receive_Buffer0[temp]<='9'))//9 maxlen=2048
|
||
{
|
||
Receive_NewFrame_Length=Receive_Buffer0[temp]-'0';
|
||
temp++;
|
||
if((Receive_Buffer0[temp]>='0')&&(Receive_Buffer0[temp]<='9'))//10
|
||
{
|
||
Receive_NewFrame_Length=(Receive_Buffer0[temp-1]-'0')*10+(Receive_Buffer0[temp]-'0');
|
||
temp++;
|
||
if((Receive_Buffer0[temp]>='0')&&(Receive_Buffer0[temp]<='9')) //*11
|
||
{
|
||
Receive_NewFrame_Length=(Receive_Buffer0[temp-2]-'0')*100+(Receive_Buffer0[temp-1]-'0')*10+(Receive_Buffer0[temp]-'0');
|
||
temp++;
|
||
if((Receive_Buffer0[temp]>='0')&&(Receive_Buffer0[temp]<='9')) //*12
|
||
{
|
||
Receive_NewFrame_Length=(Receive_Buffer0[temp-3]-'0')*1000+(Receive_Buffer0[temp-2]-'0')*100\
|
||
+(Receive_Buffer0[temp-1]-'0')*10+(Receive_Buffer0[temp]-'0');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 获取远端IP和对端端口
|
||
if(Receive_Buffer0[temp]==','); // 11=","
|
||
temp++;
|
||
//if(Receive_Buffer0[temp]=='"'); // 12="""
|
||
//temp++;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer0[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
RMT_IP_buf[0]=(Receive_Buffer0[temp]-'0');
|
||
else if(i==2)
|
||
RMT_IP_buf[0]=(Receive_Buffer0[temp]-'0')*10 +(Receive_Buffer0[temp+1]-'0');
|
||
else if(i==3)
|
||
RMT_IP_buf[0]=(Receive_Buffer0[temp]-'0')*100+(Receive_Buffer0[temp+1]-'0')*10+(Receive_Buffer0[temp+2]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer0[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
RMT_IP_buf[1]=(Receive_Buffer0[temp]-'0');
|
||
else if(i==2)
|
||
RMT_IP_buf[1]=(Receive_Buffer0[temp]-'0')*10+(Receive_Buffer0[temp+1]-'0');
|
||
else if(i==3)
|
||
RMT_IP_buf[1]=(Receive_Buffer0[temp]-'0')*100+(Receive_Buffer0[temp+1]-'0')*10+(Receive_Buffer0[temp+2]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer0[temp+i]=='.')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
RMT_IP_buf[2]=(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==2)
|
||
RMT_IP_buf[2]=(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==3)
|
||
RMT_IP_buf[2]=(Receive_Buffer0[temp+i-3]-'0')*100+(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer0[temp+i]==',')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
RMT_IP_buf[3]=(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==2)
|
||
RMT_IP_buf[3]=(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==3)
|
||
RMT_IP_buf[3]=(Receive_Buffer0[temp+i-3]-'0')*100+(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
temp=temp+i+1;
|
||
|
||
for(i=0;i<10;i++)
|
||
{
|
||
if(Receive_Buffer0[temp+i]==':')
|
||
break;
|
||
}
|
||
if(i==1)
|
||
RMT_IP_PORT=(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==2)
|
||
RMT_IP_PORT=(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==3)
|
||
RMT_IP_PORT=(Receive_Buffer0[temp+i-3]-'0')*100+(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
else if(i==4)
|
||
RMT_IP_PORT=(Receive_Buffer0[temp+i-4]-'0')*1000+(Receive_Buffer0[temp+i-3]-'0')*100+(Receive_Buffer0[temp+i-2]-'0')*10+(Receive_Buffer0[temp+i-1]-'0');
|
||
temp=temp+i+1;
|
||
|
||
|
||
|
||
|
||
|
||
//
|
||
temp=strloc(Receive_Buffer0,":");
|
||
if(Receive_Buffer0[temp]==':'); // 11=":"
|
||
temp++;
|
||
if(Receive_Buffer0[temp]==1); // 12,对方发=1,我方回复=0
|
||
Function_Code=Receive_Buffer0[temp+1]; // 13,功能码
|
||
|
||
//1.服务器回复设备登录指令(25字节) Function_Code==1, 主动发送的 这里是返回
|
||
if((25==Receive_NewFrame_Length)&&(1==Function_Code))
|
||
{
|
||
flag_HeartBeat10s=1; // 立马启动一次心跳
|
||
|
||
flag_TCP_Logined=1;
|
||
//flag_NoLoginBack_Monitoring150s=0;
|
||
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
CRC16=Receive_Buffer0[temp++]*0x100; // 0x07
|
||
CRC16+=Receive_Buffer0[temp++]; // 0xdf
|
||
Disp_Year=CRC16%100; // 0x07df=2015
|
||
Disp_Month=Receive_Buffer0[temp++];
|
||
Disp_Day=Receive_Buffer0[temp++];
|
||
Disp_Hour=Receive_Buffer0[temp++];
|
||
Disp_Minute=Receive_Buffer0[temp++];
|
||
Disp_Second=Receive_Buffer0[temp++];
|
||
Disp_Week=Receive_Buffer0[temp];
|
||
Write_Time();
|
||
CRC16_L=Receive_Buffer0[temp+1];
|
||
CRC16_H=Receive_Buffer0[temp+2];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+1);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//2.切换工作模式指令(18字节)Function_Code==2
|
||
else if((18==Receive_NewFrame_Length)&&(2==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
if(Receive_Buffer0[temp]==0x0)
|
||
flag_auto_hand=0;
|
||
else
|
||
flag_auto_hand=1;
|
||
|
||
CRC16_L=Receive_Buffer0[temp+1];
|
||
CRC16_H=Receive_Buffer0[temp+2];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+1);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//3.手动模式下开关指令(19字节)Function_Code==3
|
||
else if((19==Receive_NewFrame_Length)&&(3==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
if(flag_auto_hand==0)
|
||
{
|
||
if(Receive_Buffer0[temp]==1)//灯编号1=lamp1
|
||
{
|
||
if(Receive_Buffer0[temp+1]==0)flag_lamp1_onoff=0;
|
||
else if(Receive_Buffer0[temp+1]==1)flag_lamp1_onoff=1;
|
||
}
|
||
else if(Receive_Buffer0[temp]==2)//灯编号2=lamp2
|
||
{
|
||
if(Receive_Buffer0[temp+1]==0)flag_Pump_onoff=0;//flag_lamp2_onoff=0;
|
||
else if(Receive_Buffer0[temp+1]==1)flag_Pump_onoff=1;//flag_lamp2_onoff=1;
|
||
}
|
||
/*
|
||
else if(Receive_Buffer0[temp]==3)//灯编号3=Pump_pump
|
||
{
|
||
if(Receive_Buffer0[temp+1]==0)flag_Pump_onoff=0;
|
||
else if(Receive_Buffer0[temp+1]==1)flag_Pump_onoff=1;
|
||
}
|
||
else if(Receive_Buffer0[temp]==4)//灯编号4=..
|
||
{
|
||
if(Receive_Buffer0[temp+1]==0)flag_lamp4_onoff=0;
|
||
else flag_lamp4_onoff=1;
|
||
}
|
||
else if(Receive_Buffer0[temp]==5)//灯编号5=..
|
||
{
|
||
if(Receive_Buffer0[temp+1]==0)flag_lamp5_onoff=0;
|
||
else flag_lamp5_onoff=1;
|
||
}
|
||
*/
|
||
CRC16_L=Receive_Buffer0[temp+2];
|
||
CRC16_H=Receive_Buffer0[temp+3];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+2);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
}
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//4.设置定时器时间指令(22字节)Function_Code==4
|
||
else if((22==Receive_NewFrame_Length)&&(4==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
//Timers_Enable[Receive_Buffer0[temp]]=1; // 只是设定定时器定时时间
|
||
i=Receive_Buffer0[temp]-1; // 1~10
|
||
Set_Open_Hour[i]=Receive_Buffer0[temp+1];
|
||
Set_Open_Minute[i]=Receive_Buffer0[temp+2];
|
||
Set_Close_Hour[i]=Receive_Buffer0[temp+3];
|
||
Set_Close_Minute[i]=Receive_Buffer0[temp+4];
|
||
|
||
CRC16_L=Receive_Buffer0[temp+5];
|
||
CRC16_H=Receive_Buffer0[temp+6];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+5);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//5.设置报警温度指令(22字节)Function_Code==5
|
||
else if((22==Receive_NewFrame_Length)&&(5==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
if(Receive_Buffer0[temp]<2)
|
||
TemptureAlam_Close_Open_Setup=Receive_Buffer0[temp];
|
||
// TemptureAlam_Close_Open_Setup=0,关报警;
|
||
// TemptureAlam_Close_Open_Setup=1,开报警;
|
||
// TemptureAlam_Close_Open_Setup=2,只是设置预警温度(不管是否开关报警)
|
||
else if(2==Receive_Buffer0[temp])
|
||
{
|
||
Set_Low_Tempture=Receive_Buffer0[temp+1]*0x100+Receive_Buffer0[temp+2];
|
||
Set_High_Tempture=Receive_Buffer0[temp+3]*0x100+Receive_Buffer0[temp+4];
|
||
}
|
||
|
||
CRC16_L=Receive_Buffer0[temp+5];
|
||
CRC16_H=Receive_Buffer0[temp+6];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+5);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//6.查询设备所有状态指令(17字节)Function_Code==6
|
||
else if((17==Receive_NewFrame_Length)&&(6==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
CRC16_L=Receive_Buffer0[temp];
|
||
CRC16_H=Receive_Buffer0[temp+1];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
}
|
||
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
//7.配置设备入网指令(37字节)Function_Code==7 zhang
|
||
else if((37==Receive_NewFrame_Length)&&(7==Function_Code))
|
||
{
|
||
//\r\n +IPD,0,xx:0Fdd... 多路连接时(+CIPMUX=1)+IPD,<id>,<len>:<data>
|
||
// 0 1 23456789abcdef
|
||
//例如:\r\n+IPD,0,32:http://www.cmsoft.cn QQ:10865600
|
||
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
for(i=0;i<20;i++)
|
||
URL_ADDR[i]=Receive_Buffer0[temp+i];
|
||
|
||
CRC16_L=Receive_Buffer0[temp+i];
|
||
CRC16_H=Receive_Buffer0[temp+i+1];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+i);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
Have_New_URL=0xea;
|
||
make_AT_CIPSEND(20,0,255);
|
||
UDP1_Return(7);
|
||
if(flag_TCP0_Connected)
|
||
ESP8266_CIPCLOSE('0');
|
||
ESP8266_CIPSTART_TCP('0');
|
||
flag_TCP_Logined=0;
|
||
|
||
// 验证下新域名是否正确(是否能连接上'id=2'?)
|
||
/*
|
||
if(Link_id=='1')
|
||
ESP8266_CIPSTART_NewTCP_Check('2');
|
||
else if(Link_id=='2')
|
||
ESP8266_CIPSTART_NewTCP_Check('1');
|
||
|
||
// 这里是回复UDP命令
|
||
make_AT_CIPSEND(20,0,255); // AT+CIPSEND=1,20,255.255.255.255,9954 全网群发
|
||
if(Have_New_URL==0xea)
|
||
UDP1_Return(7);
|
||
else
|
||
UDP1_Return(0xff);
|
||
*/
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
//8.Function_Code==8,心跳 主动发送 不设返回
|
||
//9.Function_Code==9,报温 主动发送 不设返回
|
||
//10.开关定时器指令(19字节)Function_Code==10
|
||
else if((19==Receive_NewFrame_Length)&&(10==Function_Code))
|
||
{
|
||
if(Check_Header_15data(temp))
|
||
{
|
||
temp=temp+15;
|
||
i=Receive_Buffer0[temp];
|
||
Timers_Enable[i]=Receive_Buffer0[temp+1];
|
||
|
||
CRC16_L=Receive_Buffer0[temp+2];
|
||
CRC16_H=Receive_Buffer0[temp+3];
|
||
CRC16=GetRevCrc_16(Receive_Buffer0,temp+2);
|
||
if(CRC16==(CRC16_H*0x100+CRC16_L)){CRC16_Check_OK=1;} // 数据校验
|
||
CRC16_Check_OK=1;
|
||
////
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ht_writecmd(Command, toneon);
|
||
//flag_Buzzer=1;
|
||
BEEP_ms(10);
|
||
}
|
||
}
|
||
|
||
// 进行回复,Function_Code=,2,3,4,5,6,7,,,10
|
||
if(CRC16_Check_OK&&Function_Code!=1&&Function_Code!=7&&Function_Code!=8&&Function_Code!=9)
|
||
{
|
||
make_AT_CIPSEND(57,0,255); // 命令头:AT+CIPSEND=0,len 【0=id,len=数据长度】;
|
||
Heart_and_State_Return('R');
|
||
|
||
}
|
||
else
|
||
{
|
||
//Function_Code=0xff; // 要求重发上条命令
|
||
}
|
||
MCUeeprom_write(); // 保存xin数据到MCUeeprom;60bytes;
|
||
}
|
||
|
||
// 一、密码正确的情况下:第一次"SmartLink"后显示1~7, 第二次上电自动联网显示5和6,5~6相隔3秒
|
||
// 1. smartconfig type:ESPTOUCH
|
||
// 2. Smart get wifi info
|
||
// 3. ssid:TP-LINK_0202
|
||
// 4. password:1234567890
|
||
// 5. WIFI CONNECTED
|
||
// 6. WIFI GOT IP
|
||
// 7. smartconfig connected wifi
|
||
|
||
// 二、密码错误的情况下:
|
||
//smartconfig type:ESPTOUCH
|
||
//Smart get wifi info
|
||
//ssid:TP-LINK_0202
|
||
//password:15800
|
||
//WIFI DISCONNECT
|
||
else if((pStr0=strstr(Receive_Buffer0,ready))!=NULL)// "ready"
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
flag_WiFi_ready=1;
|
||
ESP8266_CWMODE('1');
|
||
//ESP8266_CIPMODE('0'); // 默认'0'
|
||
ESP8266_CIPMUX('1');
|
||
ESP8266_CIPDINFO('1');
|
||
|
||
NoWiFi5s_TimeoutCounter=0;
|
||
flag_ready_Monitoring5s=1; // 5S ago 启动flag_ready5s_STARTSMART=1;
|
||
|
||
System_Status=31;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
|
||
else if((pStr0=strstr(Receive_Buffer0,WIFI_DISCONNECT))!=NULL)// "WIFI DISCONNECT"
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
flag_WiFi_Disconnect=1;
|
||
flag_WiFi_Connected=0;
|
||
flag_TCP0_Connected=0;
|
||
|
||
flag_WiFi_Connect_Enable=1;
|
||
NoWiFi5s_TimeoutCounter=0;
|
||
flag_ready_Monitoring5s=0; // 5S ago 启动flag_ready5s_STARTSMART=1;
|
||
|
||
System_Status=220;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
//ESP8266_RST();
|
||
}
|
||
else if((pStr0=strstr(Receive_Buffer0,WIFI_CONNECTED))!=NULL)// "WIFI CONNECTED"
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
flag_ready_Monitoring5s=0;
|
||
flag_ready5s_STARTSMART=0;
|
||
flag_WiFi_Connect_Enable=1;
|
||
flag_WiFi_Disconnect=0;
|
||
}
|
||
else if((pStr0=strstr(Receive_Buffer0,WIFI_GOT_IP))!=NULL)// "WIFI GOT IP"
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
|
||
//flag_DisConnect_Monitoring180s=0;
|
||
flag_WiFi_Disconnect=0;
|
||
flag_WiFi_Connected=1;
|
||
flag_WiFi_Smarting=0;
|
||
|
||
ESP8266_CIFSR();
|
||
//ESP8266_CIPDINFO('1');
|
||
InBuffer_ID=0;
|
||
|
||
ESP8266_CIPSTART_UDP('1'); // 开启UDP0连接
|
||
|
||
ESP8266_CIPSTART_TCP('0'); // 开启TCP1连接
|
||
System_Status=151;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
// "0,CONNECT",TCP0连接成功
|
||
else if(((pStr0=strstr(Receive_Buffer0,TCP_0_CONNECT))!=NULL))
|
||
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
flag_TCP0_Connected=1;
|
||
flag_LoginTCP_SendOnce=1;
|
||
//flag_NoLoginBack_Monitoring150s=0;
|
||
|
||
BEEP_ms(200);
|
||
System_Status=161;
|
||
flag_Restart_Connect_TCP=0;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
}
|
||
// "1,CONNECT",UDP连接成功
|
||
else if((pStr0=strstr(Receive_Buffer0,UDP_1_CONNECT))!=NULL)
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
flag_UDP1_Connected=1;
|
||
}
|
||
|
||
else if((pStr0=strstr(Receive_Buffer0,SEND_OK))!=NULL)// "SEND OK" CIPSEND发送数据成功
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//flag_NoLoginBack_Monitoring150s=0;
|
||
flag_TCP0_Connected=1;
|
||
}
|
||
|
||
else if(((pStr0=strstr(Receive_Buffer0,TCP0_CLOSED))!=NULL)||((pStr0=strstr(Receive_Buffer0,DNS_Fail))!=NULL))// "CLOSED",TCP连接失败DNS Fail
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
|
||
flag_TCP0_Connected=0;
|
||
//flag_TCP0_Connecting=1;
|
||
flag_SEND_FAIL=0;
|
||
flag_TCP_Logined=0;
|
||
BEEP_ms(200);
|
||
//Delay_ms(10000);
|
||
//ESP8266_RST();
|
||
//ESP8266_CIPCLOSE(Link_id);
|
||
|
||
//ESP8266_CIPSTART_TCP('0');// 开启TCP0连接
|
||
|
||
//flag_NoLoginBack_Monitoring150s=1;
|
||
|
||
System_Status=160;
|
||
//Lcd_Disp_Tempture(System_Status);
|
||
flag_Restart_Connect_TCP=1;
|
||
|
||
}
|
||
|
||
|
||
else if((pStr0=strstr(Receive_Buffer0,ERROR))!=NULL)
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
//flag_Restart_Connect_TCP=1;
|
||
}
|
||
else if((pStr0=strstr(Receive_Buffer0,link_is_not_valid))!=NULL)
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
else if((pStr0=strstr(Receive_Buffer0,FAIL))!=NULL)
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
else if(flag_SEND_FAIL)
|
||
{
|
||
for(i=0;i<120;i++)
|
||
Receive_Buffer0[i]=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
|
||
/*
|
||
|
||
else if((pStr0=strstr(Receive_Buffer0,Smart_get_wifi_info))!=NULL)// "Smart_get_wifi_info"
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,smarting_connected_wifi))!=NULL)// "smartconfig connected wifi"
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,SEND_OK))!=NULL)// "SEND OK" CIPSEND发送数据成功
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,send_logo))!=NULL)// "> "
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,ALREADY_CONNECT))!=NULL)// "ALREADY CONNECT",TCP连接已经存在;
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,FAIL))!=NULL)// "FAIL"
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,ERROR))!=NULL)// "ERROR"
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
else if((pStr0=strstr(Receive_Buffer0,OK))!=NULL)// "OK"
|
||
{for(i=0;i<120;i++)Receive_Buffer0[i]=0;}
|
||
*/
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
启朱唇,发皓齿,丁香小舌,吹气如兰。
|
||
不急不慢似吟似唱,莺啼婉转情意绵绵。
|
||
|
||
心旷神怡,如听高山流水;意乱情迷,如闻艳曲狂弦。
|
||
先惹起满腔心火,又送上一缕清泉。
|
||
|
||
制服诱惑巧裁剪,勾出一身玲珑线。
|
||
婀娜体态,遮得庄严。
|
||
|
||
稍不慎露出半截手腕,怎不能叫人浮想联翩。
|
||
领口又开三分低,贴身小衣竟可见。
|
||
|
||
拿捏得恰到好处,总不给看个完全。
|
||
望眼欲穿,捶胸空叹。
|
||
遥不可及,枉自垂涎。
|
||
只可远观,不可亵玩。
|
||
|
||
惟从这深深沟渠,梦想那壮美山川。
|
||
今朝把发辫松挽,明日将青丝束偏。
|
||
百变妆容,千般娇艳。
|
||
亭亭玉立姿,盈盈秋波转。
|
||
天生本是风流骨,偏要板起桃花面。
|
||
撩动春风吸人魄,潜入春梦惹人怜。
|
||
这一番销魂蚀骨,端的是难以言传。
|
||
*/
|
||
|
||
/**********************************************/
|
||
void main(void)
|
||
{
|
||
unsigned char i,j;
|
||
int USE;
|
||
|
||
//**********************初始化UART2**********************
|
||
UART2_CR1 = 0x00;
|
||
UART2_CR2 = 0x00;
|
||
UART2_CR3 = 0x00;
|
||
UART2_BRR2 = 0x00;
|
||
UART2_BRR1 = 0x06;
|
||
// UART_DIV[15:0]=fMASTER/波特率;
|
||
// UART_BRR1=UART_DIV[11:4]
|
||
// UART_BRR1=UART_DIV[15:12]+UART_DIV[3:0]
|
||
|
||
// fMASTER=11059200(11.0592MHz)
|
||
// 例如对于波特率115200时,分频系数=11059200/115200=96
|
||
// 对应的十六进制数为0060,BBR1=0x06,BBR2=00
|
||
|
||
// 例如对于波特率 9600时,分频系数=11059200/9600=1152
|
||
// 对应的十六进制数为0480,BBR1=0x48,BBR2=00
|
||
|
||
// UART2_SR = 0x0;
|
||
UART2_CR2 = 0x2C; //00101100
|
||
//位7:TIEN 发送中断使能;
|
||
//位6:TCIEN 发送完成中断使能;
|
||
//位5:RIEN *接收中断使能;
|
||
//位4:ILIEN IDLE中断使能;
|
||
//位3:TEN *发送使能;
|
||
//位2:REN *接收使能;
|
||
//位1:RWU 接收唤醒;
|
||
//位0:SBK 发送断开帧;
|
||
//*******************************************************
|
||
|
||
//*********************初始化MCU端口*********************
|
||
//可选择的输入模式:浮动输入和带上拉输入
|
||
//可选择的输出模式:推挽式输出和开漏输出
|
||
//复位之后,所有的引脚都是悬浮输入模式。
|
||
//没有使用的I/O引脚必须连接到一个固定的电平值。或者是上拉或者是下拉。
|
||
//pb口 pb0悬浮输入 AD_HEAT
|
||
// pb1开漏输出 PB1_LED
|
||
// pb2开漏输出 PB2_LAMP
|
||
// pb3开漏输出 PB3_PUMP
|
||
// pb4上拉输入 *
|
||
// pb5上拉输入 *
|
||
|
||
//pc口 pc1开漏输出 DS1302_DATA
|
||
// pc2开漏输出 DS1302_RST
|
||
// pc3上拉输入 *
|
||
// pc4上拉输入 QT1696_B0
|
||
// pc5上拉输入 QT1696_B1
|
||
// pc6上拉输入 QT1696_B2
|
||
// pc7上拉输入 QT1696_B3
|
||
|
||
//pd口 pd0上拉输入 LCD_IRQ
|
||
// pd1 SWIM=0
|
||
// pd2开漏输出 LCD_Data
|
||
// pd3开漏输出 LCD_WR
|
||
// pd4开漏输出 LCD_RD
|
||
// pd5 TX =1
|
||
// pd6 RX =0
|
||
// pd7开漏输出 LCD_CS
|
||
|
||
//pe口 pe5开漏输出 DS1302_CLK
|
||
//pf口 pf4上拉输入 *
|
||
|
||
PB_DDR=0x0e;PB_CR1=0x3e;PB_CR2=0x00;PB_ODR=0x0e;
|
||
PC_DDR=0x06;PC_CR1=0xf0;PC_CR2=0x00;PC_ODR=0x06;
|
||
|
||
PD_DDR=0xbc;PD_CR1=0x44;PD_CR2|=0x00;PD_ODR|=0x4;
|
||
|
||
PE_DDR=0x20;PE_CR1=0x00;PE_CR2=0x00;PE_ODR=0x00;
|
||
|
||
//*******************************************************
|
||
//*********************初始化MCU端口*********************
|
||
//pb口 pb0悬浮输入 ad
|
||
// pb1上拉输入 *PB1-ESP_EN
|
||
// pb4上拉输入 b0
|
||
// pb5上拉输入 b1
|
||
//pc口 pc1开漏输出 DS1302_DATA_IN
|
||
// pc2开漏输出 DS1302_RST
|
||
// pc3开漏输出 LCD_LED
|
||
// pc4开漏输出 heating_PC4
|
||
// pc5开漏输出 Pump_PB3
|
||
// pc6开漏输出 Lamp1_PB2
|
||
// pc7开漏输出 lamp2_PC5
|
||
//pd口 pd0开漏输出 *PD6-RSTESP
|
||
// pd2上拉输入 b3
|
||
// pd3开漏输出 lcd_data
|
||
// pd4开漏输出 lcd_wr
|
||
// pd5 TX
|
||
// pd6 RX
|
||
// pd7开漏输出 lcd_cs
|
||
//pe口 pe5开漏输出 DS1302_CLK
|
||
//pf口 pf4上拉输入 b2
|
||
// PB_DDR|=0x00;PB_CR1|=0x30;PB_CR2|=0x00;PB_ODR|=0x30;
|
||
// PC_DDR|=0xfe;PC_CR1|=0x00;PC_CR2|=0x00;PC_ODR=0x08;
|
||
// PD_DDR|=0xb8;PD_CR1|=0x44;PD_CR2|=0x00;PD_ODR|=0x4;
|
||
// PE_DDR|=0x20;PE_CR1|=0x00;PE_CR2|=0x00;PE_ODR=0x00;
|
||
// PF_DDR|=0x00;PF_CR1|=0x10;PF_CR2|=0x00;PF_ODR|=0x10;
|
||
//*******************************************************
|
||
|
||
//************************时钟控制***********************
|
||
// 8.9.1 内部时钟寄存器(CLK_ICKR)
|
||
// CLK_ICKR=0x01;
|
||
// 8.9.2 外部时钟寄存器(CLK_ECKR)
|
||
// CLK_ECKR=0x00;
|
||
// 8.9.3 主时钟状态寄存器(CLK_CMSR)
|
||
// CLK_CMSR=0xE1; // CLK_CMSR=CKM[7:0]:主时钟状态位
|
||
//0xE1:HSI为主时钟源(复位值)
|
||
//0xD2:LSI为主时钟源(仅当LSI_EN选项位为1时)
|
||
//0xB4:HSE为主时钟源
|
||
|
||
// 8.9.4 主时钟切换寄存器(CLK_SWR)
|
||
// 8.9.5 切换控制寄存器(CLK_SWCR)
|
||
CLK_SWCR|=0x02; // 向第二位SWEN写1将切换主时钟至寄存器CLK_SWR指定的时钟源。
|
||
CLK_SWR = 0xb4; // 0xB4:HSE为主时钟源
|
||
// 0xE1:HSI为主时钟源(复位值)16MHz
|
||
|
||
// 8.9.6 时钟分频寄存器(CLK_CKDIVR[4:0]),复位值:0x18
|
||
// 位 4:3(HSIDIV[1:0]:高速内部时钟预分频器) 11:fHSI = fHSI RC输出/8
|
||
// 位 2:0(CPUDIV[2:0]:CPU时钟预分频器) 000:fCPU = fMASTER
|
||
// CLK_CKDIVR = 0x18; // 主时钟 = 16MHZ / 8
|
||
// fCPU时钟 = fMASTER主时钟 = 2MHZ
|
||
|
||
// 8.9.7 外设时钟门控寄存器(CLK_PCKENR1)
|
||
// 8.9.8 外设时钟门控寄存器(CLK_PCKENR2)
|
||
// 8.9.9 时钟安全系统寄存器(CLK_CSSR)
|
||
// 8.9.10 可配置时钟输出寄存器
|
||
// 8.9.11 CAN 外部时钟控制寄存器(CLK_CANCCR)
|
||
// 8.9.12 HSI 时钟修正寄存器(CLK_HSITRIMR)
|
||
// 8.9.13 SWIM 时钟控制寄存器(CLK_SWIMCCR)
|
||
//*******************************************************
|
||
|
||
//**********************初始化A/D模块*********************
|
||
// ----------初始化A/D模块;
|
||
ADC_CR2 = 0x00; // A/D结果数据左对齐
|
||
ADC_CR1 = 0x00; // ADC时钟=主时钟/2=1MHZ
|
||
// ADC转换模式=单次
|
||
// 禁止ADC转换
|
||
ADC_CSR = 0x00; // 选择通道0
|
||
ADC_TDRL = 0x1;
|
||
|
||
ADC_CR1 = 0x01; // CR1寄存器的最低位置1,使能ADC转换 并且连续转换
|
||
Delay(100); // 延时一段时间,至少7uS,保证ADC模块的上电完成
|
||
ADC_CR1 = ADC_CR1 | 0x01; // 再次将CR1寄存器的最低位置1
|
||
// 使能ADC转换
|
||
//*******************************************************
|
||
|
||
//********************初始化定时器模块*******************
|
||
TIM4_IER = 0x00; // 禁止中断
|
||
TIM4_EGR = 0x01; // 允许产生更新事件
|
||
TIM4_PSCR = 0x07; // 计数器时钟=主时钟/128=2MHZ/128=64us微秒
|
||
TIM4_ARR =255;// 156; // 设定重装载时的寄存器值,255是最大值*64=16.320ms毫秒
|
||
TIM4_CNTR=255;//156; // 设定计数器的初值 //2MHZ/128/255/
|
||
// 定时周期=(ARR+1)*64=16320uS
|
||
TIM4_CR1 = 0x01; // b0 = 1,允许计数器工作
|
||
// b1 = 0,允许更新
|
||
// 设置控制器,启动定时器
|
||
TIM4_IER = 0x01; // 允许更新中断
|
||
//*******************************************************
|
||
|
||
_asm("rim"); // _asm("sim"); // 这是关中断
|
||
// _asm("rim"); // 这是开中断
|
||
//ht_writecmd(Command, toneon);
|
||
|
||
System_Init(); // 开机接收缓存区清零;
|
||
ht1621_cmd_init(); // 开机LCD初始化
|
||
|
||
//Disp_Second=readds1302(0)&0x7f;
|
||
//writeds1302(0x0,7); // 可以写
|
||
//writeds1302(Disp_Second,0);
|
||
//writeds1302(0xa5,8);
|
||
//writeds1302(0x80,7); // 写保护WP
|
||
|
||
//state0=readds1302(0x20);
|
||
//MCUeeprom_read();
|
||
//Read_Time();
|
||
//Delay_ms(200);
|
||
//ht_writecmd(Command, toneoff);
|
||
|
||
while (0) // for test
|
||
{
|
||
|
||
Delay_ms(1000);
|
||
//lamp2_PC5=~lamp2_PC5;
|
||
//Lamp1_PB2=~Lamp1_PB2;
|
||
//Pump_PB3=~Pump_PB3;
|
||
LCD_LED=~LCD_LED;
|
||
//ReceiveData_Process();
|
||
}
|
||
//_asm("rim");
|
||
|
||
Disp_Year=0;
|
||
Disp_Month=0;
|
||
Disp_Day=0;
|
||
Disp_Hour=0;
|
||
Disp_Minute=0;
|
||
Disp_Week=0;
|
||
Real_Tempture=0;
|
||
|
||
while(0)
|
||
{
|
||
Disp_Year++;
|
||
Disp_Month++;
|
||
Disp_Day++;
|
||
Disp_Hour++;
|
||
Disp_Minute++;
|
||
Disp_Week++;
|
||
Real_Tempture+=111;
|
||
|
||
Write_Time();
|
||
Delay_ms(1000);
|
||
Read_Time();
|
||
Delay_ms(1000);
|
||
}
|
||
|
||
while(0)
|
||
{
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0xff,4);
|
||
Delay_ms(1000);
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0x00,4);
|
||
Delay_ms(1000);
|
||
|
||
Disp_Year++;
|
||
Disp_Month++;
|
||
Disp_Day++;
|
||
Disp_Hour++;
|
||
Disp_Minute++;
|
||
Disp_Week++;
|
||
Real_Tempture+=111;
|
||
|
||
Lcd_Display();
|
||
Delay_ms(1000);
|
||
}
|
||
|
||
|
||
while (0) // for test
|
||
{
|
||
//ht_writecmd(Command,lcdon);
|
||
Delay_ms(100);
|
||
//ht_writecmd(Command,lcdoff);
|
||
Delay_ms(100);
|
||
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0xff,4);
|
||
Delay_ms(1000);
|
||
for(i=0;i<32;i++)
|
||
ht_writedata(i,0x00,4);
|
||
Delay_ms(1000);
|
||
|
||
for(i=0;i<32;i++)
|
||
{
|
||
Delay(5000);
|
||
Delay(5000);
|
||
for(j=0;j<16;j++)
|
||
{
|
||
ht_writedata_zdh(31-i,j,4);
|
||
Delay(5000);
|
||
Delay(5000);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
while(0)
|
||
{
|
||
_asm("sim");
|
||
state0=0xaa;
|
||
Have_New_URL=0xea;
|
||
MCUeeprom_write();
|
||
Delay(50000);
|
||
for(i=55;i<75;i++)
|
||
URL_ADDR[i-55]=0;
|
||
state0=0;
|
||
Have_New_URL=0;
|
||
MCUeeprom_read();
|
||
Delay(50000);
|
||
|
||
flag_lamp2_onoff=1;
|
||
flag_lamp1_onoff=0;
|
||
flag_Pump_onoff=1;
|
||
flag_auto_hand=1;
|
||
|
||
|
||
MCUeeprom_write();
|
||
state0=0;
|
||
Delay(50000);
|
||
MCUeeprom_read();
|
||
Delay(50000);
|
||
}
|
||
while (0) // for test
|
||
{
|
||
flag_ScreenLock_Status=0;
|
||
while (0)
|
||
{
|
||
|
||
Key_Scanning_OK();
|
||
Lcd_Display();
|
||
Delay(50000);
|
||
//Delay(50000);
|
||
}
|
||
}
|
||
|
||
while(0) // for test
|
||
{
|
||
//Read_STAIP_STAMAC();
|
||
Delay(10);
|
||
ReceiveData_Process();
|
||
Delay(10);
|
||
Check_Header_15data(0);
|
||
Delay(10);
|
||
}
|
||
|
||
|
||
//flag_lamp2_onoff=0;
|
||
|
||
while(0)
|
||
{
|
||
Key_Scanning_OK(); // 按键扫描;
|
||
//_asm("sim");
|
||
//Read_Tempture();
|
||
//make_AT_CIPSEND(20,255,255);
|
||
//ESP8266_CIPSTART_UDP1_BK(1);
|
||
Delay_ms(1000);
|
||
Heart_and_State_Return('S');
|
||
}
|
||
|
||
//MCUeeprom_write_URL();
|
||
//MCUeeprom_write();
|
||
MCUeeprom_read();
|
||
ESP8266_RST();
|
||
Link_id='0';
|
||
flag_ScreenLock_Status=1; // 开机设定面板是锁定的?
|
||
//ESP8266_RESTORE();
|
||
|
||
while (1)
|
||
{
|
||
InBuffer_ID=0;
|
||
ReceiveData_Process(); // 被动:对接收的新数据.进行分析(回复、赋值、处理)
|
||
Key_Scanning_OK(); // ok 按键扫描;
|
||
Read_Time(); // ok 读DS1302的时间;
|
||
Read_Tempture(); // ok 采集温度and高温判断处理;
|
||
Lcd_Display(); // ok 屏幕刷新
|
||
Autohand_Control(); // ok 状态控制flag_auto_hand;若0手动模式(根据按键处理)...,若1自动模式(根据定时器处理)...;
|
||
CIPSendData_Process(); // 主动:根据状态变化主动发送数据;
|
||
|
||
// 温度显示或者通讯故障代码打印;
|
||
if(0)//if(flag_ScreenLock_Status==1&&Key_Back==Adjust_Key4)
|
||
{
|
||
Lcd_Disp_Tempture(System_Status);
|
||
ht_writecmd(Command, toneon);
|
||
while(Read_Key_Num()!=0xff);
|
||
ht_writecmd(Command, toneoff);
|
||
//MCUeeprom_write();
|
||
}
|
||
}
|
||
}
|
||
/*
|
||
"步骤" "返回" "说明"
|
||
1、AT+RST ready 重启;
|
||
1、AT+RESTORE ready 恢复出厂设置;
|
||
1、ATE0/1 OK 取消/设置回显功能;
|
||
|
||
2、AT+CWMODE=1 OK/ERROR 设置成STA;
|
||
2、AT+CIPMODE=0 OK/ERROR 设置非透传模式;
|
||
2、AT+CIPMUX=1 OK/ERROR 启动多路连接;
|
||
|
||
3、AT+CWSTARTSMART OK 智能连接路由器;
|
||
3、AT+CWSTOPSMART OK 关闭连接路由器;
|
||
3、AT+CIFSR OK 查询模块自身IP;
|
||
AT+CIFSR
|
||
+CIFSR:STAIP,"192.168.0.108"
|
||
+CIFSR:STAMAC,"18:fe:34:db:0d:33"
|
||
|
||
OK
|
||
|
||
4、AT+CIPSTART=0,"TCP","192.168.1.2",9955 OK/ERROR/ALREADY CONNECT 连接TCP服务器
|
||
4、AT+CIPCLOSE=5 OK/ERROR 关闭所有连接
|
||
|
||
5、AT+CIPSEND=x,len:ddddd OK+"> " 发送数据: x=<link ID> 网络连接ID号(0~4)用于多连接的情况
|
||
5、+IPD,0,len:www.ifish7.com 接收数据;len是数据长度(MAX=2048)
|
||
*/
|
||
|
||
/**********************************************/
|
||
// 函数功能:UART2的接收中断服务程序 1byte
|
||
// 输入参数:无
|
||
// 输出参数:无
|
||
// 返 回 值:无
|
||
/**********************************************/
|
||
@far @interrupt void UART2_Recv_IRQHandler (void)
|
||
{
|
||
unsigned char i;
|
||
// flag_Receive_NewFrame_Buffer0=1;
|
||
if(Receive_Count0>119)
|
||
Receive_Count0=0;
|
||
if(Receive_Count1>119)
|
||
Receive_Count1=0;
|
||
|
||
if(1==flag_WiFi_Data_Sending||0==InBuffer_ID)
|
||
{
|
||
Receive_Buffer0[Receive_Count0++]=UART2_DR;// 读入接收到的字符0 针对系统
|
||
Receive_NewFrame_TimeoutCounter=0;
|
||
flag_Receive_NewOneByte=1;
|
||
}
|
||
else
|
||
Receive_Buffer1[Receive_Count1++]=UART2_DR;// 读入接收到的字符1 针对单命令
|
||
/*
|
||
if(1==InBuffer_ID)
|
||
{
|
||
Receive_Buffer1[Receive_Count1++]=UART2_DR;// 读入接收到的字符1 针对单命令
|
||
}
|
||
else
|
||
{
|
||
Receive_Buffer0[Receive_Count0++]=UART2_DR;// 读入接收到的字符0 针对系统
|
||
Receive_NewFrame_TimeoutCounter=0;
|
||
flag_Receive_NewOneByte=1;
|
||
}
|
||
*/
|
||
return;
|
||
}
|
||
|
||
/**********************************************/
|
||
// 函数功能:UART2的发送中断服务程序
|
||
// 输入参数:无
|
||
// 输出参数:无
|
||
// 返 回 值:无
|
||
/**********************************************/
|
||
@far @interrupt void UART2_Send_IRQHandler (void)
|
||
{
|
||
if(flag_WiFi_Data_Sending==1)
|
||
{
|
||
if(Send_Count<=Send_Num)
|
||
UART2_DR = Send_Buffer[++Send_Count];
|
||
else
|
||
{
|
||
flag_WiFi_Data_Sending=0;
|
||
UART2_CR2&= 0x7f; //TIEN=0:发送中断使能被禁止;
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
/**********************************************/
|
||
// 函数功能:定时器4的更新中断服务程序
|
||
// 输入参数:无
|
||
// 输出参数:无
|
||
// 返 回 值:无 16.32ms【3MS】进一次TIM4中断,
|
||
/**********************************************/
|
||
@far @interrupt void TIM4_UPD_OVF_IRQHandler (void)//2MHZ/128/255/
|
||
{
|
||
TIM4_SR = 0x00; // 清除更新标志
|
||
//PD_ODR = PD_ODR ^ 0x08; // LED驱动信号取反
|
||
// //LED闪烁频率=2MHZ/128/255/2=30.63
|
||
|
||
// 1. 基本时间片= 50*3=150ms
|
||
if(++ThreeMS_Counter>=50)
|
||
{
|
||
ThreeMS_Counter=0;
|
||
// 1.0 TCP服务器60S没有连接,60S超时重启。
|
||
if(flag_TCP0_Connected==0&&flag_WiFi_Connected)
|
||
{
|
||
if(++TCP0_TimeoutCounter>=400) //150ms*400=60s
|
||
{
|
||
TCP0_TimeoutCounter=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
}
|
||
if(flag_TCP0_Connected)TCP0_TimeoutCounter=0;
|
||
|
||
// 1.1 跳闪设置 // 50*3*4=600ms
|
||
flag_TimeSetup_Jump=~flag_TimeSetup_Jump;
|
||
if(++Lcd_Colon_TimeoutCounter>=5)
|
||
{
|
||
Lcd_Colon_TimeoutCounter=0; // 灯光跳闪三部曲
|
||
flag_Colon_Jump=~flag_Colon_Jump; // ClockTime秒跳,":","(((WiFi)))"
|
||
//Display_T();
|
||
}
|
||
|
||
// 1.2 串口RS232连接超时 //50*3*40=6000ms
|
||
if(++RS232_TimeoutCounter>=40&&flag_RS232_TimeoutStart)
|
||
{
|
||
RS232_TimeoutCounter=0;
|
||
flag_RS232_TimeoutStart=0;
|
||
flag_RS232_Timeout=1;
|
||
}
|
||
if(flag_RS232_TimeoutStart==0)RS232_TimeoutCounter=0;
|
||
|
||
// 1.3 按键解屏 //50*3*15=2250ms
|
||
if(flag_ScreenLock_Status&&flag_have_key)
|
||
{
|
||
if(++UnLockScreen_TimeoutCounter>=15)
|
||
{
|
||
if(flag_ScreenLock_Status)
|
||
flag_ScreenLock_Status=0;
|
||
UnLockScreen_TimeoutCounter=0;
|
||
}
|
||
}
|
||
if(flag_ScreenLock_Status==0)UnLockScreen_TimeoutCounter=0;
|
||
|
||
// 1.4 手动自动切换 //50*3*10=1500ms
|
||
if(flag_auto_hand_change&&flag_have_key)
|
||
{
|
||
if(++auto_hand_TimeoutCounter>=10)
|
||
{
|
||
if(flag_auto_hand_change)
|
||
flag_auto_hand_change=0;
|
||
auto_hand_TimeoutCounter=0;
|
||
}
|
||
}
|
||
if(flag_auto_hand_change==0)auto_hand_TimeoutCounter=0;
|
||
|
||
// 1.5 超时锁屏 //50*3*50=7500ms
|
||
if(flag_ScreenLock_Status==0)//&&flag_auto_hand_change==0)
|
||
{
|
||
if(++LockScreen_TimeoutCounter>=50)
|
||
{
|
||
flag_ScreenLock_Status=1;
|
||
LockScreen_TimeoutCounter=0;
|
||
if(flag_ClockTimeSetting)
|
||
{
|
||
flag_ClockTimeSetting=0;
|
||
ClockTimeSetup_Stepper=0;
|
||
}
|
||
if(flag_LampTimeSetting)
|
||
{
|
||
flag_LampTimeSetting=0;
|
||
LampTimeSetup_Stepper=0;
|
||
flag_Open_Time=0;
|
||
flag_Close_Time=0;
|
||
}
|
||
}
|
||
}
|
||
if(flag_ScreenLock_Status)LockScreen_TimeoutCounter=0;
|
||
|
||
// 1.6 约10s心跳包 //50*3*68=10200ms Connect_TCP_Counter=0;
|
||
if(flag_TCP0_Connected&&flag_WiFi_Connected&&flag_TCP_Logined)
|
||
{
|
||
if(++HeartBeat10s_TimeoutCounter>68)
|
||
{
|
||
HeartBeat10s_TimeoutCounter=0;
|
||
flag_HeartBeat10s=1;
|
||
}
|
||
}
|
||
if(flag_TCP_Logined==0)HeartBeat10s_TimeoutCounter=0;
|
||
|
||
// 1.7 长时间60s没有心跳、服务器、路由器,看门狗复位 //50*3*400=60000ms
|
||
if(flag_HeartBeat10s&&flag_TCP0_Connected&&flag_WiFi_Connected)
|
||
{
|
||
HeartBeat_0_TimeoutCounter=0;
|
||
if(++HeartBeat_1_TimeoutCounter>400)
|
||
{
|
||
HeartBeat_1_TimeoutCounter=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
}
|
||
else if(flag_HeartBeat10s==0&&flag_TCP0_Connected&&flag_WiFi_Connected)
|
||
{
|
||
HeartBeat_1_TimeoutCounter=0;
|
||
if(++HeartBeat_0_TimeoutCounter>400)
|
||
{
|
||
HeartBeat_0_TimeoutCounter=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
}
|
||
|
||
// 1.8 连接服务器失败,一直约10s重连
|
||
if(flag_Restart_Connect_TCP)
|
||
{
|
||
if(++Restart_Connect_TCP_TimeoutCounter>90)
|
||
{
|
||
Connect_TCP_Counter++;
|
||
Restart_Connect_TCP_TimeoutCounter=0;
|
||
flag_Enable_Connect_TCP=1;
|
||
}
|
||
}
|
||
else {Restart_Connect_TCP_TimeoutCounter=0;Connect_TCP_Counter=0;}
|
||
|
||
// 1.9连接路由失败,10s后路由复位连接
|
||
if(flag_WiFi_Disconnect)
|
||
{
|
||
if(++WiFi_Disconnect_TimeoutCounter>90)
|
||
{
|
||
WiFi_Disconnect_TimeoutCounter=0;
|
||
//ESP8266_RST();
|
||
IWDG_Enable();
|
||
}
|
||
}
|
||
if(flag_have_key) WiFi_Disconnect_TimeoutCounter=0;
|
||
|
||
// 1.a 上电若ready设置flag_ready_Monitoring5s=1,若5s无入网信息, 则重新启动智能入网,设置flag_ready5s_STARTSMART=1
|
||
if(flag_ready_Monitoring5s&&flag_WiFi_ready)
|
||
{
|
||
if(++NoWiFi5s_TimeoutCounter>34)
|
||
{
|
||
NoWiFi5s_TimeoutCounter=0;
|
||
flag_ready5s_STARTSMART=1;
|
||
}
|
||
}
|
||
if(flag_ready_Monitoring5s==0)NoWiFi5s_TimeoutCounter=0;
|
||
|
||
// 1.b 发出登陆指令设置flag_NoLoginBack_Monitoring150s=1,若150s没有返回网络时间,则重新启动连接服务器,设置flag_NoLoginBack150s_CIPSTART=1
|
||
//if((flag_NoLoginBack_Monitoring150s&&flag_TCP0_Connected&&flag_WiFi_Connected))
|
||
// if(flag_NoLoginBack_Monitoring150s)//||(flag_TCP0_Connected==0&&flag_WiFi_Connected))
|
||
// {
|
||
// if(++NoLoginBack150s_TimeoutCounter>1000)
|
||
// {
|
||
// NoLoginBack150s_TimeoutCounter=0;
|
||
// flag_NoLoginBack150s_CIPSTART=1;
|
||
// //ESP8266_RST();
|
||
// IWDG_Enable();
|
||
// }
|
||
// }
|
||
//if(flag_NoLoginBack_Monitoring150s==0)NoLoginBack150s_TimeoutCounter=0;
|
||
|
||
}
|
||
|
||
// 2.串口接收时间片 // 3*3=9ms没有再收到新的字符,认为前面一帧结束
|
||
if(flag_Receive_NewOneByte)
|
||
{
|
||
if(++Receive_NewFrame_TimeoutCounter>10) // 超时处理,一帧数据收集完毕
|
||
{
|
||
Receive_NewFrame_TimeoutCounter=0;
|
||
flag_Receive_NewOneByte=0; // =1UART接收1个新的字符;?
|
||
flag_Receive_NewFrame_Buffer0=1; // =1表明接收完了一帧新字符
|
||
Receive_Num0=Receive_Count0;
|
||
Receive_Count0=0;
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|