浏览代码

docs:移除部分无关变量调整代码格式

1.移除按键 IR扫描代码
2.移除LED代码
3.移除Flash相关代码
Comment.Vivre 1 年之前
父节点
当前提交
232549cdb2

+ 16 - 64
KeilC51/Fortior.uvopt

@@ -358,30 +358,6 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\User\Source\KeyScan.c</PathWithFileName>
-      <FilenameWithoutPath>KeyScan.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>2</GroupNumber>
-      <FileNumber>13</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\User\Source\LED.c</PathWithFileName>
-      <FilenameWithoutPath>LED.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>2</GroupNumber>
-      <FileNumber>14</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
       <PathWithFileName>..\User\Source\mcFiledWeaken.c</PathWithFileName>
       <FilenameWithoutPath>mcFiledWeaken.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
@@ -389,7 +365,7 @@
     </File>
     <File>
       <GroupNumber>2</GroupNumber>
-      <FileNumber>15</FileNumber>
+      <FileNumber>13</FileNumber>
       <FileType>4</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -409,7 +385,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>16</FileNumber>
+      <FileNumber>14</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -421,7 +397,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>17</FileNumber>
+      <FileNumber>15</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -433,7 +409,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>18</FileNumber>
+      <FileNumber>16</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -445,7 +421,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>19</FileNumber>
+      <FileNumber>17</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -457,7 +433,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>20</FileNumber>
+      <FileNumber>18</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -469,7 +445,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>21</FileNumber>
+      <FileNumber>19</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -481,7 +457,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>22</FileNumber>
+      <FileNumber>20</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -493,7 +469,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>23</FileNumber>
+      <FileNumber>21</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -505,7 +481,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>24</FileNumber>
+      <FileNumber>22</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -517,7 +493,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>25</FileNumber>
+      <FileNumber>23</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -529,7 +505,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>26</FileNumber>
+      <FileNumber>24</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -541,7 +517,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>27</FileNumber>
+      <FileNumber>25</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -553,7 +529,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>28</FileNumber>
+      <FileNumber>26</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -565,7 +541,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>29</FileNumber>
+      <FileNumber>27</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -575,30 +551,6 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
-    <File>
-      <GroupNumber>3</GroupNumber>
-      <FileNumber>30</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\User\Source\FU68xx_5_Flash.c</PathWithFileName>
-      <FilenameWithoutPath>FU68xx_5_Flash.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>3</GroupNumber>
-      <FileNumber>31</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\User\Source\EXTI.c</PathWithFileName>
-      <FilenameWithoutPath>EXTI.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
   </Group>
 
   <Group>
@@ -609,7 +561,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>32</FileNumber>
+      <FileNumber>28</FileNumber>
       <FileType>2</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>

+ 0 - 20
KeilC51/Fortior.uvproj

@@ -436,16 +436,6 @@
               <FileType>1</FileType>
               <FilePath>..\User\Source\RSDDetect.c</FilePath>
             </File>
-            <File>
-              <FileName>KeyScan.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\User\Source\KeyScan.c</FilePath>
-            </File>
-            <File>
-              <FileName>LED.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\User\Source\LED.c</FilePath>
-            </File>
             <File>
               <FileName>mcFiledWeaken.c</FileName>
               <FileType>1</FileType>
@@ -531,16 +521,6 @@
               <FileType>1</FileType>
               <FilePath>..\User\Source\TSD.c</FilePath>
             </File>
-            <File>
-              <FileName>FU68xx_5_Flash.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\User\Source\FU68xx_5_Flash.c</FilePath>
-            </File>
-            <File>
-              <FileName>EXTI.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\User\Source\EXTI.c</FilePath>
-            </File>
           </Files>
         </Group>
         <Group>

+ 0 - 1
User/Include/Customer.h

@@ -214,7 +214,6 @@
  * @param (PWMMODE)       PWM调速
  * @param (SREFMODE)      模拟调速
  * @param (NONEMODE)      直接给定值,不调速
- * @param (KEYSCANMODE)   按键控制模式
  * @param (ONOFFTEST)     启停测试工具
  */
 #define SPEED_MODE						(NONEMODE)				// 闭环方式选择  

+ 0 - 80
User/Include/Customer_Debug.h

@@ -1,80 +0,0 @@
-/**
- * @copyright (C) COPYRIGHT 2022 Fortiortech Shenzhen
- * @file      Customer_Debug.h
- * @author    Marcel He
- * @since     Create:2022-07-14
- * @date      Last modify:2022-07-14
- * @note      Last modify author is Marcel He
- * @brief     使用说明
- * @brief     1.本模块通过SPI接口与"SPI_Monitor"硬件模块相连,"SPI_Monitor"将会把数据转换成模拟信号。
- * @brief     2.本模块有两种工作模式:硬件DBG模式和软件DBG模式。
- * @brief     3.硬件DBG模式:填写要发送的数据的首地址,单片机将会发送地址连续的8个字节数据。
- *            在本模式下,客户仅需要修改的以下宏定义的参数(必须是地址值):HARD_SPIDATA
- * @brief     4.软件方式:一般选择在载波中断中填写数据                   
- */
-
-
-#ifndef __CUSTOMER_DEBUG_H__
-#define __CUSTOMER_DEBUG_H__
-
-/**************************************************************************************************///Including Header Files
-#include "FU68xx_5.h"
-
-
-/* 调试模式选择 */
-#define DBG_DISABLE                     (0x10)             // 关闭调试模式
-#define DBG_SPI_SW                      (0x11)             // SPI软件写模式
-#define DBG_SPI_HW                      (0x12)             // SPI硬件传输模式
-#define DBG_UART                        (0x13)             //UART监控模式
-#define DBG_MODE                        (DBG_DISABLE)
-
-/* FU6864仅支持单线模式,P00口 */
-///* 使用SPI调试时,SPI模式选择 */
-//#define DBG_SPI_3                       (0)    // 三线模式,MCU的 SCLK NSS MOSI 接SPI小板的 SCLK NSS MOSI,    SPI拨码开关:SW2 = 0;SW3 = 0;    
-//#define DBG_SPI_2                       (1)    // 双线模式,MCU的 SCLK MOSI     接SPI小板的 SCLK  MOSI,       SPI拨码开关:SW2 = 1;SW3 = 0;   
-//#define DBG_SPI_1                       (2)    // 单线模式,MCU的 SCLK          接SPI小板的 MOSI,             SPI拨码开关:SW2 = 1;SW3 = 1;   
-
-//#define SPI_DBG_MODE                    (DBG_SPI_2)
-
-
- // 硬件DBG的参数首地址
-#define HARD_SPIDATA                   FOC__ETHETA
-extern uint16 xdata spidebug[4];
-/*GPIO DBG模块配置--------------------------------------------------------------*/
-
- // GP01 DBG信号配置
-#define GP01_DISABLE                   0x00                                    ///< 禁能GP01的DBG信号
-#define GP01_BEMFZero                  DBGSEL0                                 ///< GP01输出方波屏蔽续流结束和检测到过零点信号
-#define GP01_ADCTrigger                DBGSEL1                                 ///< GP01ADC trigger信号
-#define GP01_CMPSample                 DBGSEL1 | DBGSEL0                       ///< GP01比较器采样区间信号
-
-#define GP01_DBG_Conf                  (GP01_DISABLE)                          ///< GP01信号选择
-
- // GP07 DBG信号配置
-#define GP07_DISABLE                   0x00                                    ///< 禁能GP07的比较器信号输出
-#define GP07_CMP0                      CMPSEL0                                 ///< 输出CMP0
-#define GP07_CMP1                      CMPSEL1                                 ///< 输出CMP1
-#define GP07_CMP2                      CMPSEL1 | CMPSEL0                       ///< 输出CMP2
-#define GP07_CMP3                      CMPSEL2                                 ////</ 输出CMP3
-#define GP07_CMP4                      CMPSEL2 | CMPSEL0                       ///< 输出CMP4
-// #define GP07_CMP5                    	CMPSEL2 | CMPSEL1                       ///< 输出CMP5
-#define GP07_CMPOX                     CMPSEL2 | CMPSEL1 | CMPSEL0             ///< 输出ADC结果比较信号(BLDC)Omega启动状态(FOC)
-
-#define GP07_DBG_Conf                  (GP07_DISABLE)                            ///< GP07信号选择
-
-
-
-/*DBG模块检查--------------------------------------------------------------*/
- #if (defined (SPI_DBG_HW) && defined (SPI_DBG_SW)) || (defined (UART_DBG) && (defined (SPI_DBG_SW) || defined (SPI_DBG_HW)))
-     #error Only one DBG mode can be selected
- #else
-     #if defined (SPI_DBG_SW)
-         #pragma message("Software mode using the SPI DEBUG module")
-     #elif defined (SPI_DBG_HW)
-         #pragma message("Hardware mode using the SPI DEBUG module")
-     #elif defined (UART_DBG)
-         #pragma message("Using the UART DEBUG (ANTO protocol)")
-     #endif
- #endif
-
-#endif

+ 4 - 73
User/Include/Declaration.h

@@ -42,12 +42,6 @@ void   FGOutput(void);
 void   Fault_GetCurrentOffset(void);
 uint32 Abs_F32(int32 value);
 
-void SinCal(int16 Ref, int16 Theta, int16 * Sin, int16 * Cos);
-uint16 SqrtUDQ(int16 sqrtUd, int16 sqrtUq);
-
-void LedDisplay(uint8 uLedMask);
-void zeroLoss(void);
-
 // 保护相关
 void Fault_Detection(void);
 void Fault_OverCurrent(void);
@@ -74,10 +68,13 @@ void GPIO_Init(void);
 void GPIO_Default_Init(void);
 void SPI_Init(void);
 
-
+/**
+	@brief 芯片温度检测
+*/
 void TSD_Init(void);
 void TEMP_Check(void);
 
+
 void PI_Init(void);
 void PI2_Init(void);
 void PI3_Init(void);
@@ -137,21 +134,13 @@ void SetDbgMod_DMA(void);
 void SetDbgData_DMA(unsigned short ulAddr);
 void Set_DBG_DMA(uint16 DMAAddr);
 
-/**
-	@brief 过零点检测
-*/
-void ZeroCrossing_Init(void);
-
 /**
 	@brief 定时器
 */
 #define TIM3_Fre                       (750000.0)                                // TIM0计数频率750KHz
 #define TIM4_Fre                       (6000.0)                                  // TIM0计数频率6KHz
-void Timer1_Init(void);
 void Timer2_Init(void);
 void Timer3_Init(void);
-void Timer4_Init(void);
-void TIM4_Init_RF(void);
 
 
 /* ------------------------------------------- 功能 ------------------------------------------------------------- */
@@ -190,64 +179,6 @@ MotStateType Bemf_Start_Process(void);
 void VoltageCompensation(uint8 VCCtrlMode, uint16 VCmcDcbusFlt);
 void BusAverageVoltage(void);
 
-typedef struct
-{
-    uint8  CheckCount;                 //
-    uint8 TSD_Enable_Flag;             //    温度检测使能标志位	
-	uint8 TSD_Trigger_Flag;            //    温度检测触发标志位
-
-    uint8 ActualTemper;               // 
-    uint16 Trigger_Value;              // 
-    uint16 TSD_Dec_Time;               //    温度检测时间计数
-	
-}MCUTemperature;
-
-extern MCUTemperature xdata TSDTemperature;
-
-typedef struct
-{
-    uint8 ScrOnAngleTimeDatum;         //期望给定 导通延迟时间  单位为  1/载波频率
-    uint8 ScrOnAngleTime;              //实际给定 导通延迟时间  单位为  1/载波频率
-    uint8 ScrOnPeriod;                 //控制周期
-    uint16 Temperature;                //温度值
-    uint16 TemperatureDatum[3];        //温度期望值
-	uint16 TPCtrlDealy;                // 发热丝导通延时计数
-	uint8 ScrOnZeroFlag;                 //控制周期
-	uint16 ScrOnZeroCnt;
-} USER_TYPEDEF;
-
-extern USER_TYPEDEF  User;
-
-typedef struct
-{
-	uint16 LEDCnt;
-	uint8 FlagLED;
-//	uint8 FlagStepTime;
-//	uint16 LEDTimeCnt;	
-} LEDCtl_TypeDef;
-
-extern LEDCtl_TypeDef LEDCtl;
-
-#define LED1_MASK	((uint8)(1 << 0))
-#define LED2_MASK	((uint8)(1 << 1))
-#define LED3_MASK	((uint8)(1 << 2))
-#define LED4_MASK	((uint8)(1 << 3))
-#define LED5_MASK	((uint8)(1 << 4))
-#define LED6_MASK	((uint8)(1 << 5))
-
-void LedDisplay(uint8 uLedMask);
-
-/**
-	@brief 按键函数声明
-*/
-
-#define SW3 GP33
-#define SW1 GP33
-#define SW2 GP26
-void KeyInit(void);
-int KeyValue(void);
-int KeyValue1(void);
-void KeyScan(void);
 
 #endif
 

+ 0 - 81
User/Include/FU68xx_5_Flash.h

@@ -1,81 +0,0 @@
-/* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
-    File Name      : FLASH.h
-    Author         : Fortiortech  Appliction Team
-    Version        : V1.0
-    Date           : 2021-07-24
-    Description    : This file contains flash变量和函数的定义 parameter used for Motor Control.
-----------------------------------------------------------------------------------------------------
-                                       All Rights Reserved
-------------------------------------------------------------------------------------------------- */
-
-/* Define to prevent recursive inclusion -------------------------------------------------------- */
-///******************************************************************************///Including Header Files
-#include <FU68xx_5.h>
-
-
-//#ifndef __FLASH_H__
-//#define __FLASH_H__
-//#define USERCODEADDRESS 0X3F00
-
-////typedef struct
-////{	
-////	uint8   FlashRead; 
-////	uint8   FlashWrite;
-////	uint16  FlashRead2Byte;
-////	uint16  FlashWrite2Byte;
-////    
-////} MCUFlash;
-
-//extern MCUFlash xdata FlashTest;                                                        //flash数据测试
-//extern uint16 Get2ByteFromFlash(uint8 xdata *BlockStartAddr);                          //2字节的flash读取函数   
-//extern uint8 Write2Byte2Flash(uint8 xdata *BlockStartAddr,uint16 NewData2Flash);      //2字节的flash写入函数
-//extern void WriteOrReadFlashTest(uint8 xdata *BlockStartAddr,uint16 NewData2Flash);  //读写函数定义
-
-//extern  void Flash_Sector_Erase(uint8 xdata *FlashAddress);                         //自擦除函数定义  
-//extern  void Flash_Sector_Write(uint8 xdata *FlashAddress, uint8 FlashData);        //自写入函数定义
-
-//#endif
-
-
-/************************ (C) COPYRIGHT 2015 FT *******************************
-* File Name          : 
-* Author             : Application Team  Tom.wang 
-* Version            : V2.0.0
-* Date               : 06/15/2015
-* Description        : 
-********************************************************************************
-/*******************************************************************************
-* All Rights Reserved
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __FLASH_H
-#define __FLASH_H
-#define     __I     volatile const    /*!< defines 'read only' permissions      */
-#define     __O     volatile          /*!< defines 'write only' permissions     */
-#define     __IO    volatile          /*!< defines 'read / write' permissions   */
-
-#define   START_WriteADDRESS  0x6800             //写入首地址
-#define   Write_Lenght        4                  //写入字节长度
-#define   Verify_Bit          Write_Lenght -1    //Data数值最后位为校验位
-#define   Verify_Ture         0xFF               //校验正确数值
-#define   Verify_Error        0x55               //校验错误数值
-
-typedef struct
-{
-	uint16 WriteAddress;     // 写入地址 
-	uint8  WriteValue[8];    // Flash 写入数组
-	uint16 ReadAddress;      // 读取地址
-	uint8  ReadValue[8];     // ROM 读出值
-	uint8  FlagFlashWrite;   // 写标志位
-	uint8  Flag_FlashErase;  // Flash擦除标志位
-}ROM_TypeDef;
-
-extern ROM_TypeDef xdata  FlashData;  
-extern uint8  ReadFlashValue(uint16 ReadAddress);
-extern uint8  Flash_WriteValue(uint16 WriteAddress ,uint8 Length,uint8 * str);
-extern uint16 GetWrite_Black_Addr(unsigned short FlashAddress, uint8 Write_Length);
-extern void   ReadFromFlash(unsigned short BlockStartAddr, uint8 Length, uint8 * str);
-extern void Flash_Erase(void);
-extern void   Save_KeyValue(void);
-#endif

+ 0 - 3
User/Include/MyProject.h

@@ -15,14 +15,11 @@
 #include <Customer.h>
 #include <Parameter.h>
 #include <Protect.h>
-#include <Customer_Debug.h>
 
 
 #include <Declaration.h>
 #include <VaribleDef.h>
 
-
-#include "FU68xx_5_Flash.h"
 #include <SMDU.h>
 
 #endif

+ 0 - 1
User/Include/SystemDefinition.h

@@ -98,7 +98,6 @@
 #define NONEMODE                        (0xA0)          ///< 直接给定值,不调速
 #define PWMMODE                         (0xB0)          ///< PWM调速
 #define SREFMODE                        (0xC0)          ///< 模拟调速
-#define KEYSCANMODE                     (0xD0)          ///< 按键调速  
 #define ONOFFTEST                       (0xE0)          ///< 启停测试工具   
 #define OTHERS                          (0xF0)          ///< 其他调速方式   
 

+ 24 - 55
User/Include/VaribleDef.h

@@ -108,9 +108,9 @@ extern MotorRSDTypeDef   mcRsd;
 /**
     @brief BMEF顺逆风
 */
-#define BEMF_FR_CCW                           (0xA0) // 
-#define BEMF_FR_CW                            (0xB0) // 
-#define BEMF_FR_ERR                           (0xC0) // 
+#define BEMF_FR_CCW                           (0xA0)
+#define BEMF_FR_CW                            (0xB0)
+#define BEMF_FR_ERR                           (0xC0)
 
 #define  BEMF_FORWARD                           (1)
 #define  BEMF_REVERSE                           (2)
@@ -178,35 +178,6 @@ typedef struct
 } FieldWeakeningTypeDef;
 extern  FieldWeakeningTypeDef xdata mcFiledWeaken;
 
-/**
-    @brief 按键定义
-*/
-typedef struct
-{
-    uint8 Key1Value;
-    uint8 Key2Value;
-    uint8 Key3Value;
-    
-    uint16 Key1PressCnt;
-    uint16 Key2PressCnt;
-    uint16 Key2PressCnt2;
-    uint16 Key3PressCnt;
-    uint16 Key3releaseCnt;
-    
-    uint16 KeyADCValue;
-    
-    uint8 KeyValuetotal;
-    uint8 OldKeyValuetotal;
-    uint8 ChangeKeyFlg;
-    uint8 TwoCarrierCnt;
-    
-    uint8 ColdHotFlag;
-    uint16 ONOFFCNT;
-    uint8 ONOFFFlag;
-    
-} KeyScanParam_TypeDef;
-extern KeyScanParam_TypeDef xdata KS;
-
 /**
     @brief 电压补偿
 */
@@ -223,8 +194,8 @@ typedef struct
     s32tos16 mcDcbusFlt2Sum;
     s32tos16 UQVALUESum;
     s32tos16 UDVALUESum;
-    int16    UQVALUEAVERAGE;
-    int16    UDVALUEAVERAGE;
+    int16	 UQVALUEAVERAGE;
+    int16	 UDVALUEAVERAGE;
     uint16 mcDcbusFlt2cnt;
     uint16 cpscnt;
     uint16 Uqcps;
@@ -323,9 +294,9 @@ typedef struct
     uint16 VoltRecoverCnt;
     uint16 BusVoltDetecCnt;
     uint16 DectDealyCnt;
-    uint16      VoltDetecBraketCount;
-    uint8       FlagBrakeInit;
-    uint16      VoltDetecBraketDuty;
+    uint16 VoltDetecBraketCount;
+    uint8  FlagBrakeInit;
+    uint16 VoltDetecBraketDuty;
 } FaultVoltageVarible;
 typedef struct
 {
@@ -376,6 +347,21 @@ typedef struct
     FaultOverPower              Power;
 } FaultVarible;
 
+typedef struct
+{
+    uint8  CheckCount;                 //
+    uint8 TSD_Enable_Flag;             //    温度检测使能标志位	
+	uint8 TSD_Trigger_Flag;            //    温度检测触发标志位
+
+    uint8 ActualTemper;               // 
+    uint16 Trigger_Value;              // 
+    uint16 TSD_Dec_Time;               //    温度检测时间计数
+	
+}MCUTemperature;
+
+extern MCUTemperature xdata TSDTemperature;
+
+
 extern uint8                        xdata   mcPOSTErrSource;
 extern FaultVarible                 xdata   fault;
 extern FaultCurrentVarible          idata   mcCurVarible;
@@ -416,33 +402,16 @@ typedef struct
     uint16 PowerLimitValue; // 功率限制的值
     
     uint8  Mode0HoldCnt;    // MODE0切MODE1延迟时间计数
-    
     uint16  EMFsquare;      // 当前FOC_ESQU滤波后的值
-    
     uint16 RunStateCnt;     // 运行状态计数
-    
     uint8 LoopTime;         // 外环控制周期计数
-    
     uint16 State_Count;     // 电机各个状态的时间计数
-    
     int16  mcPosCheckAngle;// 位置检测的角度
     uint8  MCU_TEMP;        //MCU超过70°后,读取当前温度值
-    
     int16  Angle;            //弱磁角度
-    uint16 sqrtUdq;
-    
-    uint16  Refcnt;
-    
-    uint8 ZeroFlag;
-    uint8 ZeroLossFlag;
-    uint16 ZeroCnt;
-    uint16 ZeroLossCnt;
-    
     
     int16 NTCValue;
     int16 NTCValueFlt;
-    uint8 NTCValueGatherFlag;
-    uint16 NTCValueGatherCnt;
 } FOCCTRL;
 extern FOCCTRL xdata mcFocCtrl;
 
@@ -456,7 +425,7 @@ typedef struct
     float  IncValue;
     float  DecValue;
 } MCRAMP;
-extern MCRAMP               data mcRefRamp;
+extern MCRAMP data mcRefRamp;
 
 /**
     @brief 脉宽计算定义

+ 1 - 28
User/Source/AddFunction.c

@@ -227,12 +227,6 @@ void TargetRef_Process(void)
         isCtrlPowOn = 1; // 开机
         mcFocCtrl.Ref = S_Value(1500);
     }
-    #elif (SPEED_MODE == KEYSCANMODE)
-    {
-        mcFocCtrl.PowerLimitValue = POWERLPFLIMIT;
-        isCtrlPowOn = 1; // 开机
-        KeyScan();          // 获取按键值
-    }
     #elif (SPEED_MODE == ONOFFTEST)
     {
         ONOFF_Test();
@@ -495,7 +489,7 @@ void TickCycle_1ms(void)
     mcFocCtrl.NTCValueFlt = LPFFunction(mcFocCtrl.NTCValue, mcFocCtrl.NTCValueFlt, 60);
     mcFocCtrl.UqFlt = LPFFunction(FOC__UQ, mcFocCtrl.UqFlt, 50);
     mcFocCtrl.UdFlt = LPFFunction(FOC__UD, mcFocCtrl.UdFlt, 50);
-    // 获取调速信号,不同调速模式(PWMMODE,NONEMODE,SREFMODE,KEYSCANMODE)的目标值修改
+    // 获取调速信号,不同调速模式(PWMMODE,NONEMODE,SREFMODE)的目标值修改
     TargetRef_Process();
     // 启动ATO控制,环路响应,如速度环、转矩环、功率环等
     Speed_response();
@@ -507,25 +501,4 @@ void TickCycle_1ms(void)
     // 电机状态机的时序处理
     if (mcFocCtrl.State_Count > 0)
     { mcFocCtrl.State_Count--; }
-    
-    if ((mcState == mcRun) && (User.TPCtrlDealy > 0))
-    { User.TPCtrlDealy--; }
-}
-
-uint16 SqrtUDQ(int16 sqrtUd, int16 sqrtUq)
-{
-    SCAT2_COS = sqrtUd;
-    SCAT2_SIN = sqrtUq;
-    SMDU_RunBlock(2, ATAN);
-    return SCAT2_RES1;
-}
-
-void SinCal(int16 Ref, int16 Theta, int16 * Sin, int16 * Cos)
-{
-    SCAT3_COS = Ref;
-    SCAT3_SIN = 0;
-    SCAT3_THE = Theta;
-    SMDU_RunBlock(3, SIN_COS);
-    *Cos = SCAT3_RES1;
-    *Sin = SCAT3_RES2;
 }

+ 0 - 93
User/Source/BuzzerScan.c

@@ -1,93 +0,0 @@
-/* *************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
-    File Name          : BuzzerScan.c
-    Author             : Billy Long Fortiortech  Market Dept
-    Version            : V1.0
-    Date               : 01/07/2015
-    Description        : This file contains Buzzer Scan function used for Motor Control.
-***************************************************************************************************
-    All Rights Reserved
-**************************************************************************************************/
-
-
-/* Includes -------------------------------------------------------------------------------------*/
-
-#include <FU68xx_4.h>
-#include <MyProject.h>
-
-/* Private variables ----------------------------------------------------------------------------*/
-BZScan_TypeDef xdata BZScan;
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void BuzzerInit(void)
-    Description   : 按键参数初始化
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void BuzzerInit(void)
-{
-    BZScan.FlagBZ = 0;
-    BZScan.BZRunTime = 0;
-    BZScan.BZCnt = 0;
-    BZScan.BZMultitimes = 0;
-    BZScan.BZMultitimesCount = 0;
-}
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void SetBuzzer(uint8 Length)
-    Description   : 置位蜂鸣器鸣叫标志
-    Input         : Length:响铃长度  单位:100ms
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void SetBuzzer(uint8 BZRunTime, uint8 BZMultitimes)
-{
-    BZScan.FlagBZ = 1;
-    BZScan.BZRunTime = BZRunTime;
-    BZScan.BZMultitimes = BZMultitimes;
-}
-
-
-/*  ----------------------------------------------------------------------------------------------*/
-/*  Function Name  : BuzzerScan
-    /*  Description    : 蜂鸣器,BZScan.BZRunTime控制时间长度
-    /*  Date           : 2020-03-25
-    /*  Parameter      : None
-    /*  ----------------------------------------------------------------------------------------------*/
-void BuzzerScan(void)
-{
-    if (BZScan.BZMultitimes > 0)
-    {
-        BZScan.BZMultitimesCount++;
-        
-        if (BZScan.BZMultitimesCount % 200 == 0)
-        {
-            BZScan.BZMultitimesCount = 0;
-            BZScan.FlagBZ = 1;
-        }
-    }
-    else
-    {
-        BZScan.FlagBZ = 0;
-        BZScan.BZMultitimesCount = 0;
-    }
-    
-    if (BZScan.FlagBZ && BZScan.BZMultitimes)
-    {
-        SetBit(TIM3_CR1, T3EN);
-        //        SetBit(TIM4_CR1, T4EN);
-        //        SetBit(PH_SEL, T4SEL);
-        BZScan.BZCnt ++;
-        
-        if (BZScan.BZCnt >= (100 * BZScan.BZRunTime))
-        {
-            BZScan.BZCnt = 0;
-            BZScan.FlagBZ = 0;
-            ClrBit(TIM3_CR1, T3EN);
-            ResetBUZZERPin;
-            //            ClrBit(TIM4_CR1, T4EN);
-            //            ClrBit(PH_SEL, T4SEL);
-            //            ResetBUZZERPin;
-            //            BZScan.BZMultitimes = 0;
-            BZScan.BZMultitimes--;
-        }
-    }
-}

+ 0 - 23
User/Source/EXTI.c

@@ -1,23 +0,0 @@
-#include <FU68xx_5.h>
-#include <Myproject.h>
-
-USER_TYPEDEF        User;
-
-/**
- * @brief       过零点检测
- * @data        2022/08/12
- */
-void ZeroCrossing_Init(void)
-{
-//    ClrBit(P1_OE, P15);  // config P20 as input
-//    ClrBit(P1_PU, P15);  // diasable P20 Pull Up
-//    ClrBit(P1_AN, P15);  // diasable P20 analog function
-//    ClrBit(P1_IF, P15);         // clear P11 interrupt flag
-//    SetBit(P1_IE, P15);   // config P11 as the source of EXTI1
-//    IT11 = 0;
-//    IT10 = 0;                               // 00: posedge mode interrupt,01: negedge mode interrupt,1x: edge-change mode interrupt
-//    PX11 = 0;
-//    PX10 = 1;                               // 中断优先级别0,中断优先级最高
-//    EX1 = 1;                                // 使能外部中断1, P20位外部中断输入硬件
-//    EA = 1;                                 // 使能全局中断
-}

+ 0 - 175
User/Source/FLASH.c

@@ -1,175 +0,0 @@
-/* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
-    File Name      : FLASH.c
-    Author         : Fortiortech  Appliction Team
-    Version        : V1.0
-    Date           : 2021-07-24
-    Description    : This file contains FLASH function used for Motor Control.
-----------------------------------------------------------------------------------------------------  
-                                       All Rights Reserved
-------------------------------------------------------------------------------------------------- */
-/******************************************************************************///Including Header Files
-
-
-#include <Flash.h>
-
-/* -------------------------------------------------------------------------------------------------
-    Function Name  : Flash_Sector_Erase
-    Description    : 扇区自擦除: 指定将要擦除的Flash扇区,每个扇区128Byte,共128个扇区,扇区0~127对应Flash地址0x0000~0x3fff,
-                     通过指定Flash地址来指定要擦除的Flash地址所在扇区。
-                     一次只能擦除一个扇区,自擦除数据为任意值,一定要在解锁后才给DPTR赋值。
-    Date           : 2021-07-23
-    Parameter      : FlashAddress: [输入/出] 
-------------------------------------------------------------------------------------------------- */
-void Flash_Sector_Erase(uint8 xdata *FlashAddress)
-{
-    
-        EA = 0;                        //Flash自擦除前先关总中断
-        FLA_CR = 0x03;                 //使能自擦除
-        FLA_KEY = 0x5a;
-        FLA_KEY = 0x1f;                //flash预编程解锁
-        
-        *FlashAddress = 0xff;          //写任意数据
-        FLA_CR = 0x08;                 //开始预编程,完成后Flash再次上锁
-   
-}
-
-
-/* -------------------------------------------------------------------------------------------------
-    Function Name  : Flash_Sector_Write
-    Description    : Flash自烧写: 对扇区预编程和自擦除后,可以对扇区内的地址进行Flash烧写,
-                    一次烧写一个byte,一定要在解锁后才给DPTR赋值
-    Date           : 2021-07-23
-    Parameter      : FlashAddress: [输入/出] 
-------------------------------------------------------------------------------------------------- */
-void Flash_Sector_Write(uint8 xdata *FlashAddress, uint8 FlashData)
-{
-        
-            EA = 0;                   //Flash自烧写前先关总中断
-       
-        FLA_CR = 0x01;                // 使能Flash编程
-        FLA_KEY = 0x5a;
-        FLA_KEY = 0x1f;               // flash预编程解锁
-        *FlashAddress =FlashData;     // 写编程数据
-        FLA_CR = 0x08;                // 开始预编程,完成后Flash再次上锁
-    
- 
-
-
-
-}
-
-MCUFlash xdata FlashTest;            //flash测试
-/* -------------------------------------------------------------------------------------------------
-    Function Name  : void WriteData2Flash(uint8 xdata *BlockStartAddr,uint16 NewData2Flash)
-    Description    : 从目标FLASH扇区读取2字节最新写入的数据。Input:	uint8 xdata *BlockStartAddr:目标FLASH扇区
-	Output:	读出的数据
-                    
-    Date           : 2021-07-23
-    Parameter      : None
-------------------------------------------------------------------------------------------------- */
-uint16 Get2ByteFromFlash(uint8 xdata *BlockStartAddr)
-{
-	uint8 xdata *FlashStartAddr = BlockStartAddr;
-	uint8 i;
-	uint16 tempofFlashData;
-	
-	for(i=0;i<64;i++)
-	{
-		tempofFlashData = *(uint16 code *)(FlashStartAddr+2*i);   
-		if(tempofFlashData==0)
-		{
-			if(i!=0)
-			{
-				tempofFlashData = *(uint16 code *)(FlashStartAddr+2*(i-1));
-				return tempofFlashData;
-			}
-			else
-			{
-				return 0;
-			}
-		}
-		else
-		{
-			if(i==63)
-			{
-				return tempofFlashData;
-			}
-		}	
-	}
-	return 1;
-}
-/* -------------------------------------------------------------------------------------------------
-    Function Name  : void WriteData2Flash(uint8 xdata *BlockStartAddr,uint16 NewData2Flash)
-    Description    : 写入2个字节到FLASH。其中Input:uint8 xdata *BlockStartAddr:目标FLASH地址  NewData2Flash:被写入数据
-    Output:1:扇区未满,写入完成  0:扇区已满,写入失败
-                    
-    Date           : 2021-07-23
-    Parameter      : None
-------------------------------------------------------------------------------------------------- */
-uint8 Write2Byte2Flash(uint8 xdata *BlockStartAddr,uint16 NewData2Flash)
-{
-	uint8 xdata *FlashStartAddr = BlockStartAddr;
-	uint16 tempofFlashData=0;
-	uint16 tempofNewFlashData=0;
-	uint8 i;
-	
-	tempofNewFlashData = NewData2Flash;
-	
-	for(i=0;i<64;i++)
-	{
-		tempofFlashData = *(uint16 code *)(FlashStartAddr+2*i);
-		if(tempofFlashData==0)
-		{
-			tempofFlashData = tempofNewFlashData>>8;                            //待写入数据首字节
-			Flash_Sector_Write((FlashStartAddr+2*i),(uint8)tempofFlashData);
-		
-			tempofFlashData = tempofNewFlashData&0x00ff;                       //待写入数据末字节   
-			Flash_Sector_Write((FlashStartAddr+2*i+1),(uint8)tempofFlashData);
-		 return 1;
-		}
-		else
-		{
-			if(i==63)
-			{
-				return 0;
-			}
-		}
-	}
-	return 0;
-}
-/* -------------------------------------------------------------------------------------------------
-    Function Name  : void WriteOrReadFlashTest(uint8 xdata *BlockStartAddr,uint16 NewData2Flash)
-    Description    :FLASH读写数据测试,先把NewData2Flash写入到目标FLASH地址BlockStartAddr后,再将其FLASH值读出来。
-	uint8 xdata *BlockStartAddr:目标FLASH地址  NewData2Flash:被写入数据
-                    
-    Date           : 2021-07-23
-    Parameter      : None
-------------------------------------------------------------------------------------------------- */
-uint8 FlashWriteStatus=0;
-void WriteOrReadFlashTest(uint8 xdata *BlockStartAddr,uint16 NewData2Flash)
-{
-  
-        
-//	if(FlashTest.FlashWrite)
-//	{
-//        FlashWriteStatus = Write2Byte2Flash(BlockStartAddr,NewData2Flash);
-//        
-//        if(!FlashWriteStatus)
-//        {
-//            Flash_Sector_Erase(BlockStartAddr);	
-//            FlashWriteStatus = Write2Byte2Flash(BlockStartAddr,NewData2Flash);				
-//        }			
-//		
-//        FlashTest.FlashWrite = 0;
-        FlashTest.FlashRead  = 1;
-//	}
-    
-   if(FlashTest.FlashRead)
-	{	
-		FlashTest.FlashRead2Byte = Get2ByteFromFlash(BlockStartAddr);
-		
-        FlashTest.FlashRead = 0;
-	}
-
-
-}

+ 0 - 270
User/Source/FU68xx_5_Flash.c

@@ -1,270 +0,0 @@
-/*  -------------------------- (C) COPYRIGHT 2022 Fortiortech ShenZhen ---------------------------*/
-/**
- * @copyright (C) COPYRIGHT 2022 Fortiortech Shenzhen
- * @file
- * @author    Fortiortech  Appliction Team
- * @since     Create:2022-07-14
- * @date      Last modify:2022-07-14
- * @note      Last modify author is Leo.li
- * @brief
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include <FU68xx_5.h>
-#include <Myproject.h>
-
-ROM_TypeDef xdata  FlashData;
-
-uint8 Flash_GetAddress(void);
-
-
-/**
- * @brief        读取固定地址值
- * @date         2022-07-14
- */
-uint8 ReadFlashValue(uint16 ReadAddress)
-{
-    uint16 TempAddress0 = ReadAddress;
-    __IO uint8 tevalue = 0;        //临时变量
-    tevalue = *(uint8 code *)TempAddress0;   //读取回地址的值
-    return tevalue;
-}
-
-/**
- * @brief        擦除指定扇区
- * @brief        FlashAddress--Flash自擦除扇区内任意地址
- * @return       0--Flash自擦除成功,1--Flash自擦除失败
- * @date         2022-07-14
- */
-uint8 Flash_Sector_Erase(uint8 xdata * FlashAddress)
-{
-    bool TempEA;
-    uint16 TempFlashAddress;
-    TempEA = EA;
-    EA = 0;
-    TempFlashAddress = (uint16)FlashAddress;
-    
-    if ((TempFlashAddress) < (0x7f00))        // 不擦除最后一个扇区
-    {
-        FLA_CR = 0x03;                        //使能自擦除
-        FLA_KEY = 0x5a;
-        FLA_KEY = 0x1f;                       //flash预编程解锁
-        _nop_();
-        *FlashAddress = 0xff;                 //写任意数据
-        FLA_CR = 0x08;                        //开始预编程,完成后Flash再次上锁
-    }
-    
-    EA = TempEA;
-    
-    if (ReadBit(FLA_CR, FLAERR))
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-/**
- * @brief        擦除指定扇区
- * @brief        FlashAddress--指定写入地址
- * @brief        FlashData--写入数值
- * @return       0--Flash自擦除成功,1--Flash自擦除失败
- * @date         2022-07-14
- */
-void Flash_Sector_Write(uint8 xdata * FlashAddress, uint8 Flash_Data)
-{
-    bool TempEA = 0;
-    uint16 TempFlashAddress;
-    uint8 idata Flash_Data_t = Flash_Data;
-    TempEA = EA;
-    EA = 0;
-    TempFlashAddress = (uint16)FlashAddress;
-    
-    if ((TempFlashAddress) < 0x7f00)        // 不编程最后一个扇区
-    {
-        FLA_CR = 0x01;              // 使能Flash编程
-        FLA_KEY = 0x5a;
-        FLA_KEY = 0x1f;             // flash预编程解锁
-        _nop_();
-        *(uint8 xdata *)FlashAddress = Flash_Data_t;  // 写编程数据
-        FLA_CR = 0x08;              // 开始预编程,完成后Flash再次上锁
-    }
-    
-    EA = TempEA;
-}
-
-/**
- * @brief        WriteAddress--指定写入地址  
- * @brief        Length:写入数组长度
- * @brief        value--写入数组
- * @date         2022-11-14
- */
-uint8 Flash_WriteValue(uint16 WriteAddress, uint8 Length, uint8 * str)
-{
-    uint8 i;
-    uint8 TempReadRomValue;
-    uint16 FlashWriteAddr = WriteAddress;
-    
-    //读出有效数据
-    for (i = 0; i < Length; i++)
-    {
-        Flash_Sector_Write(FlashWriteAddr + i, str[i]);
-        TempReadRomValue = *(uint8 code *)(FlashWriteAddr + i);
-        
-        if (TempReadRomValue != str[i])
-        {
-            return 0;
-        }
-    }
-    
-    return 1;
-}
-
-
-/**
-* @brief        获取最后写入的地址,确认最新能写入的地址
-* @brief        unsigned short FlashAddress:目标FLASH首地址
-* @brief        uint8 Write_Length:写入数值长度
-*/
-uint16 GetWrite_Black_Addr(unsigned short FlashAddress, uint8 Write_Length)
-{
-    uint16 TempFlashAddress = 0;
-    uint16 TempFirstAddress = 0;             //用来保存保存首地址
-    uint8  tempFlashData = 0xFF;
-    uint8  Length = 0;
-    TempFlashAddress = FlashAddress;
-    TempFirstAddress = FlashAddress;
-    
-    while ((Length != Write_Length) && (TempFlashAddress < (TempFirstAddress + Write_Length))) //限定读取地址为当前页
-    {
-        tempFlashData = *(uint8 code *)(TempFlashAddress);  //读取目标地址中数值是否为0
-        
-        if (tempFlashData == 0)
-        {
-            Length ++;
-            TempFlashAddress  += 1;
-        }
-        else
-        {
-            TempFirstAddress  += Write_Length;        //首地址跳转Write_Length字节
-            
-            if (TempFirstAddress > 0x7f00)
-            {
-                TempFirstAddress  = 0x7f00;
-            }
-            
-            TempFlashAddress  = TempFirstAddress;
-            Length = 0;
-        }
-    }
-    
-    return TempFirstAddress;
-}
-
-
-/**
- * @brief        读取Length字节数据,
- * @Input        unsigned short BlockStartAddr:目标FLASH首地址
- * @Input        uint8 Length:数值长度
- * @Input        uint8 * str :读回数值写入数组
- * @ruturn       Flash数据
- */
-void ReadFromFlash(unsigned short BlockStartAddr, uint8 Length, uint8 * str)
-{
-    uint8 i = 0;
-    
-    for (i = 0; i < Length; i++)
-    {
-        str[i] = *(uint8 code *)(BlockStartAddr + i);
-    }
-}
-
-/**
- * @brief        扇区擦除
- * @Input
- * @ruturn
- */
-void Flash_Erase(void)
-{
-    uint8 FlashEraseStatus = 0;
-    FlashEraseStatus = Flash_Sector_Erase(START_WriteADDRESS);
-    
-    if (!FlashEraseStatus)
-    {
-        /*----- 获取写入首地址 -----*/
-        FlashData.WriteAddress = GetWrite_Black_Addr(START_WriteADDRESS, Write_Lenght);
-    }
-    else
-    {
-        FlashEraseStatus = Flash_Sector_Erase(START_WriteADDRESS);
-        FlashData.WriteAddress = START_WriteADDRESS;                     //第一次擦写失败后第二次擦写,强行给地址
-        
-        /*----- 第二次擦写再失败,默认为Flash损坏,不进行处理 -----*/
-        if (FlashEraseStatus)
-        {
-            ;
-        }
-    }
-    
-    FlashData.Flag_FlashErase = 0;
-}
-
-
-/**
- * @brief        保存按键
- * @date         2022-11-14
- */
-void  Save_KeyValue(void)
-{
-    uint8 FlashWriteStatus = 0;        //返回值
-    uint8 TempReadValue = 0;
-    FlashData.WriteValue[0] = KS.KeyValuetotal;
-    
-    if (FlashData.ReadValue[0] != FlashData.WriteValue[0]) //确认写入前后数据不一致
-    {
-        EA = 0;
-        
-        while (!FlashWriteStatus)   //写入异常,换到下个地址写入
-        {
-            FlashWriteStatus = Flash_WriteValue(FlashData.WriteAddress, Write_Lenght, FlashData.WriteValue);
-            
-            if (FlashWriteStatus)
-            {
-                Flash_Sector_Write(FlashData.WriteAddress + Verify_Bit, Verify_Ture);
-                TempReadValue = *(uint8 code *)(FlashData.WriteAddress + Verify_Bit);
-                /*----- 更新读取Flash首地址 -----*/
-                FlashData.ReadAddress = FlashData.WriteAddress - Write_Lenght;
-                /*----- 读取数值到FlashData.ReadValue -----*/
-                ReadFromFlash(FlashData.ReadAddress, Write_Lenght, FlashData.ReadValue);
-                
-                if (TempReadValue == Verify_Ture)
-                {
-                    goto exit;
-                }
-                else
-                {
-                    FlashWriteStatus = 0;
-                }
-            }
-            else
-            {
-                Flash_Sector_Write(FlashData.WriteAddress + Verify_Bit, Verify_Error);
-                FlashData.WriteAddress = FlashData.WriteAddress + Write_Lenght;
-                
-                if (FlashData.WriteAddress > START_WriteADDRESS + 0x70)
-                {
-                    FlashData.Flag_FlashErase = 1;      //写到扇区最后字节,依然失败,直接进行数值清楚
-                    goto exit;
-                }
-            }
-        }
-        
-    exit:
-        EA = 1;
-    }
-}
-
-
-

+ 1 - 2
User/Source/GPIO.c

@@ -31,6 +31,5 @@ void GPIO_Default_Init(void)
  */
 void GPIO_Init(void)
 {
-    SetBit(P3_OE, P37); // V_Control延时掉电
-    GP37 = 1;
+	
 }

+ 0 - 768
User/Source/IRScan.c

@@ -1,768 +0,0 @@
-/**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
-    File Name          : IRScan.c
-    Author             : Billy Long Fortiortech  Market Dept
-    Version            : V1.0
-    Date               : 01/07/2015
-    Description        : This file contains main function used for Motor Control.
-***************************************************************************************************
-    All Rights Reserved
-**************************************************************************************************/
-
-
-/* Includes -------------------------------------------------------------------------------------*/
-#include <MyProject.h>
-#include <FU68xx_4_MCU.h>
-
-
-/* Private typedef ------------------------------------------------------------------------------*/
-/* Private define -------------------------------------------------------------------------------*/
-/* Private macro --------------------------------------------------------------------------------*/
-/* Private variables ----------------------------------------------------------------------------*/
-IRScan_TypeDef xdata IRScan;
-IRControl_TypeDef xdata IRControl;
-IRControl_AutoPowerDef AutoPowerState;
-LineControlSpeedDEF xdata LineSpeedState;
-
-uint8   NatureWinFlag = 0;
-
-/* Private function prototypes ------------------------------------------------------------------*/
-/* Private functions ----------------------------------------------------------------------------*/
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void IRInit(void)
-    Description   :
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void IRInit(void)
-{
-    IRControl.LEDONOFFStatus = 1;
-    IRScan.BitValue = 0;
-    IRScan.BitCnt = 0;
-    IRScan.Bit0Cnt = 0;
-    IRScan.ByteValue = 0;
-    IRScan.UserCode = 0;
-    IRScan.DataCode = 0;
-    IRScan.IRReceiveFlag = 0;
-    IRScan.CurrentUserCode = 0;
-    IRScan.OldDataCodeMixTimes1 = 0;
-    IRScan.OldDataCodeMixTimes0 = 0;
-    IRScan.CurrentDataCode = 0;
-    IRScan.DataCodeLengthCover = 1;
-    IRScan.UserCodeLengthCover = 1;
-    IRScan.DataCodeLengthCover = (IRScan.DataCodeLengthCover << (DataCodeLength)) - 1;
-    IRScan.UserCodeLengthCover = (IRScan.UserCodeLengthCover << (UserCodeLength)) - 1;
-    IRControl.FlagONOFF = 0;
-    IRControl.FlagFR = 0;
-    IRControl.FlagSpeed = 0;
-    IRControl.TargetSpeed = 0;
-    IRControl.ONOFFStatus = 0;
-    IRControl.FlagNatureWind = 0;
-    IRControl.FlagLED = 0;
-    IRControl.FlagAutoPower = 0;
-    IRControl.FlagUserCodeSave = 0;
-    IRControl.FlagUserCodeSaveOFF = 0;
-    IRControl.FlagUserCodeRead = 1;                                     //上电读出一次UserCode
-    IRControl.FlagLED1Protect = 0;                                      //LED欠压过压保护标记
-    IRControl.FlagLED2Protect = 0;
-    IRScan.TempDataCode[0] = 0;
-    IRScan.TempDataCode[1] = 0;
-    IRScan.TempDataCode[2] = 0;
-    IRScan.TempDataCode[3] = 0;
-    IRScan.DataCodeNum = 0;
-    IRScan.BYTE0 = 0;
-    IRScan.BYTE1 = 0;
-    IRScan.BYTE2 = 0;
-    IRScan.BYTE3 = 0;
-    IRScan.PID = 0;
-    IRScan.B = 0;
-    IRControl.NatureFlage = 0;
-    IRScan.OverFlowStatus = 0;
-    mcFRState.OldTargetSpeed = 1;
-    mcFRState.FR = CCW;
-    mcFRState.FlagFR = 0;
-    mcFRState.FRStatus = 0;
-    //      Time.ReciveDelayFlage=0;
-    //      Time.ReciveDelayCount=0;
-    //      Time.PowerUpTimeCount=0;
-    AutoPowerState.FlagAutoPower = 0;
-    AutoPowerState.Timer10sec = 0;
-    AutoPowerState.ShutDowntime = 0;
-    AutoPowerState.CurrentTime = 0;
-    #if (Motor_Speed_Control_Mode == SPEED_LOOP_CONTROL)
-    {
-        IRControl.SpeedLevel[0] = MOTOR_SPEED_LEVEL_0;
-        IRControl.SpeedLevel[1] = MOTOR_SPEED_LEVEL_1;
-        IRControl.SpeedLevel[2] = MOTOR_SPEED_LEVEL_2;
-        IRControl.SpeedLevel[3] = MOTOR_SPEED_LEVEL_3;
-        IRControl.SpeedLevel[4] = MOTOR_SPEED_LEVEL_4;
-        IRControl.SpeedLevel[5] = MOTOR_SPEED_LEVEL_5;
-        IRControl.SpeedLevel[6] = MOTOR_SPEED_LEVEL_6;
-    }
-    #elif (Motor_Speed_Control_Mode == POWER_LOOP_CONTROL)
-    {
-        IRControl.SpeedLevel[0] = MOTOR_POWER_LEVEL_0;
-        IRControl.SpeedLevel[1] = MOTOR_POWER_LEVEL_1;
-        IRControl.SpeedLevel[2] = MOTOR_POWER_LEVEL_2;
-        IRControl.SpeedLevel[3] = MOTOR_POWER_LEVEL_3;
-        IRControl.SpeedLevel[4] = MOTOR_POWER_LEVEL_4;
-        IRControl.SpeedLevel[5] = MOTOR_POWER_LEVEL_5;
-        IRControl.SpeedLevel[6] = MOTOR_POWER_LEVEL_6;
-    }
-    #endif
-    LineSpeedState.TargetSpeed = 0;
-    LineSpeedState.PreTargetSpeed = 0;
-}
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void IRValue(void)
-    Description   : 红外接收头解码
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-//void IRValue(void)
-//{
-//    uint8 tempof1 = 0;
-//    uint8 tempof2 = 0;
-//
-//    if (IRScan.BitCnt == 0)
-//    {
-//        IRScan.Bit0Cnt = TIM3__DR;
-//
-//        if ((IRScan.Bit0Cnt <= TempLeadCodeMax) && (IRScan.Bit0Cnt >= TempLeadCodeMin))
-//        {
-//            IRScan.BitCnt++;
-//        }
-//    }
-//    else
-//    {
-//        IRScan.Bit0Cnt = TIM3__ARR - TIM3__DR;
-//
-//        if ((IRScan.Bit0Cnt >= TempBitValue1Min) && (IRScan.Bit0Cnt <= TempBitValue1Max))
-//        {
-//            IRScan.BitValue = 1;
-//            tempof1 = 0x00;
-//        }
-//        else if ((IRScan.Bit0Cnt >= TempBitValue0Min) && (IRScan.Bit0Cnt <= TempBitValue0Max))
-//        {
-//            IRScan.BitValue = 0;
-//            tempof1 = 0x00;
-//        }
-//        else
-//        {
-//            tempof1 = 0xFF;
-//        }
-//
-//        if (tempof1 != 0xff)
-//        {
-//            if (IRScan.BitCnt <= UserCodeLength)
-//            {
-//                IRScan.ByteValue += (IRScan.BitValue << (UserCodeLength - IRScan.BitCnt));
-//
-//                if (IRScan.BitCnt == UserCodeLength)
-//                {
-//                    IRScan.UserCode = IRScan.ByteValue;
-//                    IRScan.ByteValue = 0;
-//                }
-//
-//                IRScan.BitCnt ++;
-//            }
-//            else
-//            {
-//                IRScan.ByteValue += (IRScan.BitValue << (DataCodeLength - (IRScan.BitCnt - UserCodeLength)));
-//
-//                if (IRScan.BitCnt == AllCodeLength)
-//                {
-//                    IRScan.DataCode = IRScan.ByteValue;
-//                    IRScan.ByteValue = 0;
-//                    IRScan.BitCnt = 0;
-//
-//                    //              tempof2 = (uint8)IRScan.DataCode;
-//                    //              tempof1 = IRScan.DataCode>>8;
-//                    //              tempof1 = 0xff -tempof1-1;
-//                    //              tempof1 = 0xff -tempof1;
-//
-//                    if (IRScan.UserCode == UserCodeDef)
-//                    {
-//                        IRScan.IRReceiveFlag = 1;
-//                    }
-//                }
-//                else
-//                { IRScan.BitCnt ++; }
-//            }
-//        }
-//        else
-//        {
-//            IRScan.ByteValue = 0;
-//            IRScan.BitCnt = 0;
-//        }
-//    }
-//}
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void SetSpeed(uint8 SpeedLevel)
-    Description   : 速度设置
-    Input         : SpeedLevel:速度挡位
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void SetSpeed(uint8 SpeedLevel)
-{
-    IRControl.TargetSpeed = SpeedLevel;
-    
-    if (!mcSpeedRamp.FlagONOFF)
-    {
-        mcSpeedRamp.FlagONOFF = 1;
-    }
-    
-    IRControl.ONOFFStatus = 1;
-    IRControl.FlagSpeed = 1;
-    mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
-    NatureWinFlag = 0;          //正反转切换后根据遥控档位启动
-    IRControl.NatureFlage = 0;
-    // SetBuzzer(1,1);
-}
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void SetAutoPower(uint16 Time)
-    Description   : 定时设置
-    Input         : Time:定时时长
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void SetAutoPower(uint16 Time)
-{
-    IRControl.FlagAutoPower = 1;
-    AutoPowerState.ShutDowntime = Time;
-}
-
-uint32 idata TempByteValue;
-uint16 buf1[32] = {0};
-uint8 k = 0;
-uint16 TIM4_DR_Temp = 0;
-uint16 TIM4_ARR_Temp = 0;
-
-///*-------------------------------------------------------------------------------------------------
-//  Function Name : void RFValue(void)
-//  Description   : RF接收头解码
-//  Input         : 无
-//  Output              :   无
-//-------------------------------------------------------------------------------------------------*/
-void IRValue(void)
-{
-    static uint8 UserSavedStatus = 0;
-    static uint8 UserSavedOffStatus = 0;
-    static idata uint32 TempByteValueEff;
-    static idata uint32 TempBitValue;
-    static idata uint8  effect_value = 0;
-    uint8 tempof1 = 0;
-    TIM4_ARR_Temp = TIM4__ARR;
-    TIM4_DR_Temp = TIM4__DR;
-    IRScan.Bit0Cnt = TIM4_ARR_Temp - TIM4_DR_Temp;
-    
-    //读出高电平
-    //两组遥控信号之间的低电平信号认为是第二组信号的起始信号,低电平长度6ms
-    //  if((TIM4_DR_Temp <= 15000)&&(TIM4_DR_Temp >= 12000)&&(IRScan.Bit0Cnt <= 2100)&&(IRScan.Bit0Cnt >= 1500))
-    if ((TIM4_DR_Temp <= TempLeadCodeMax) && (TIM4_DR_Temp >= TempLeadCodeMin) && (IRScan.Bit0Cnt <= TempLeadCode0Max) && (IRScan.Bit0Cnt >= TempLeadCode0Min))
-    {
-        IRScan.BitCnt = 1;
-        effect_value = 0;
-    }
-    
-    if (IRScan.BitCnt == 1)
-    {
-        IRScan.BitCnt = 2;
-        TempByteValue = 0;
-        TempByteValueEff = 0;
-    }
-    else if (IRScan.BitCnt >= 2)
-    {
-        IRScan.Bit0Cnt = TIM4__DR;
-        
-        //        buf1[k] = IRScan.Bit0Cnt;
-        //        if(++k == 32)
-        //        {
-        //            k = 0;
-        //        }
-        if ((IRScan.Bit0Cnt >= TempBitValue1Min) && (IRScan.Bit0Cnt <= TempBitValue1Max))
-        {
-            //当前数据为1
-            TempBitValue = 1;
-            tempof1 = 0x00;
-        }
-        else if ((IRScan.Bit0Cnt >= TempBitValue0Min) && (IRScan.Bit0Cnt <= TempBitValue0Max))
-        {
-            //当前数据为0
-            TempBitValue = 0;
-            tempof1 = 0x00;
-        }
-        else
-        {
-            tempof1 = 0xff;              //当前数据电平长度不符合要求
-        }
-        
-        if (tempof1 != 0xff)
-        {
-            /****************************遥控解码部分**************/
-            //存储有效数据至对应位
-            TempByteValue += (TempBitValue << ((AllCodeLength - 1) - (IRScan.BitCnt - 2)));
-            IRScan.BitCnt ++;
-            
-            //接收满24位数据时进行处理(数据长度实际为25位,最后一位在起始信号时读取)
-            if ((IRScan.BitCnt - 2) == AllCodeLength)
-            {
-                IRScan.DataCode = (TempByteValue) & 0XFFFF;
-                //存储当前遥控地址吗
-                IRScan.UserCode = (TempByteValue >> 16) & 0XFFFF;
-                TempByteValue = 0;
-                
-                if (IRScan.UserCode == 0x00ff)
-                {
-                    if (IRScan.DataCode == 0x8877)
-                    {
-                        if (KeySpeed == 0) //处于关机状态按下该按键则以一档速度运行并短“滴”一声
-                        {
-                            KeySpeed = 1;
-                            SetBuzzer(1, 1);
-                            SetSpeed_LEDPin;
-                        }
-                        else //处于开机状态按下该按键则关机并长“滴”一声
-                        {
-                            KeySpeed = 0;
-                            SetBuzzer(5, 1);
-                            ResetSpeed_LEDPin;
-                            YaoTou_Flag = 0;
-                            ResetYaoTou_LEDPin;
-                        }
-                    }
-                    else if (IRScan.DataCode == 0x6897)//摇头
-                    {
-                        if (KeySpeed) //只有在主控电机运行时才开摇头
-                        {
-                            YaoTou_Flag ^= 1;
-                            
-                            if (YaoTou_Flag) //
-                            {
-                                SetBuzzer(1, 1);
-                                SetYaoTou_LEDPin;
-                            }
-                            else
-                            {
-                                SetBuzzer(1, 2);
-                                ResetYaoTou_LEDPin;
-                            }
-                        }
-                    }
-                    else if (IRScan.DataCode == 0x48b7)//加大风量并短“滴”一声
-                    {
-                        if (KeySpeed != 0)
-                        {
-                            if (KeySpeed < 3)
-                            { KeySpeed++; }
-                            
-                            SetBuzzer(1, 1);
-                            SetSpeed_LEDPin;
-                        }
-                    }
-                    else if (IRScan.DataCode == 0xa857)//减小风量并短“滴”一声
-                    {
-                        if (KeySpeed != 0)
-                        {
-                            if (KeySpeed > 1)
-                            { KeySpeed--; }
-                            
-                            SetSpeed_LEDPin;
-                            SetBuzzer(1, 1);
-                        }
-                    }
-                }
-            }
-        }
-        else
-        {
-            TempByteValue = 0;
-            IRScan.BitCnt = 0;
-        }
-    }
-}
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void IRScanControl(void)
-    Description   : 遥控信号处理
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void IRScanControl(void)
-{
-    if (IRScan.IRReceiveFlag)
-    {
-        //Time.ReciveDelayFlage=1;
-        if (IRScan.DataCode == IRFRCCW)
-        { SetBuzzer(2, 2); }
-        else
-        { SetBuzzer(2, 1); }
-        
-        switch (IRScan.DataCode)
-        {
-            case IRALLOFF:
-            {
-                IRControl.ONOFFStatus = 0;
-                IRControl.TargetSpeed = 0;
-                IRControl.FlagSpeed = 1;
-                mcSpeedRamp.FlagONOFF = 0;
-                IRControl.NatureFlage = 0;
-                //在反转过程中关机时退出反转状态
-                mcFRState.FlagFR = 0;
-                mcFRState.FRStatus = 0;
-                NatureWinFlag = 0;
-                
-                if (IRControl.LEDONOFFStatus)
-                {
-                    ResetLEDPin;
-                    IRControl.LEDONOFFStatus = 0;
-                }
-                
-                break;
-            }
-            
-            case IRONOFF:
-            {
-                if (mcSpeedRamp.FlagONOFF == 1)
-                {
-                    IRControl.ONOFFStatus = 0;
-                    IRControl.TargetSpeed = 0;
-                    mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
-                    mcSpeedRamp.FlagONOFF = 0;
-                    IRControl.NatureFlage = 0;
-                    //在反转过程中关机时退出反转状态
-                    mcFRState.FlagFR = 0;
-                    mcFRState.FRStatus = 0;
-                    IRControl.FlagSpeed = 1;
-                    NatureWinFlag = 0;
-                }
-                
-                break;
-            }
-            
-            case IRFRCCW:
-            {
-                if (mcFRState.FR == CCW)
-                {
-                    if ((mcState == mcRun) || (mcState == mcStart))
-                    { IRControl.FlagFR = 1; }
-                    else if ((mcState == mcReady) || (mcState == mcFault))
-                    {
-                        mcFRState.FR = CW;
-                        
-                        if (IRControl.TargetSpeed == 0)
-                        { SetSpeed(3); }
-                        else
-                        { SetSpeed(IRControl.TargetSpeed); }
-                    }
-                }
-                else
-                {
-                    IRControl.FlagFR = 0;
-                    
-                    if (!NatureWinFlag)
-                    {
-                        if (IRControl.TargetSpeed == 0)
-                        { SetSpeed(3); }
-                        else
-                        { SetSpeed(IRControl.TargetSpeed); }
-                    }
-                    else
-                    {
-                    }
-                }
-                
-                break;
-            }
-            
-            case IRFRCW:
-            {
-                if (mcFRState.FR == CW)
-                {
-                    if ((mcState == mcRun) || (mcState == mcStart))
-                    { IRControl.FlagFR = 1; }
-                    else if ((mcState == mcReady) || (mcState == mcFault))
-                    {
-                        mcFRState.FR = CCW;
-                        
-                        if (IRControl.TargetSpeed == 0)
-                        { SetSpeed(3); }
-                        else
-                        { SetSpeed(IRControl.TargetSpeed); }
-                    }
-                }
-                else
-                {
-                    IRControl.FlagFR = 0;
-                    
-                    if (!NatureWinFlag)
-                    {
-                        if (IRControl.TargetSpeed == 0)
-                        { SetSpeed(3); }
-                        else
-                        { SetSpeed(IRControl.TargetSpeed); }
-                    }
-                    else
-                    {
-                    }
-                }
-                
-                break;
-            }
-            
-            case IRLED:
-            {
-                IRControl.FlagLED = 1;
-                break;
-            }
-            
-            case IRSpeed1:
-            {
-                SetSpeed(1);
-                break;
-            }
-            
-            case IRSpeed2:
-            {
-                SetSpeed(2);
-                break;
-            }
-            
-            case IRSpeed3:
-            {
-                SetSpeed(3);
-                break;
-            }
-            
-            case IRSpeed4:
-            {
-                SetSpeed(4);
-                break;
-            }
-            
-            case IRSpeed5:
-            {
-                SetSpeed(5);
-                break;
-            }
-            
-            case IRSpeed6:
-            {
-                SetSpeed(6);
-                break;
-            }
-            
-            case IRAUTOPOWER1H:
-            {
-                SetAutoPower(360);                                      //360*10s =3600s =1h
-                break;
-            }
-            
-            case IRAUTOPOWER2H:
-            {
-                SetAutoPower(720);
-                break;
-            }
-            
-            case IRAUTOPOWER4H:
-            {
-                SetAutoPower(1400);
-                break;
-            }
-            
-            case IRNatureWind:
-            {
-                if (!IRControl.ONOFFStatus)
-                {
-                    IRControl.ONOFFStatus = 1;
-                    mcSpeedRamp.FlagONOFF = 1;
-                }
-                
-                if (!NatureWinFlag)
-                {
-                    //                          mcFRState.OldTargetSpeed = 1;
-                    //                          IRControl.TargetSpeed = mcFRState.OldTargetSpeed;
-                    IRControl.TargetSpeed = NatureWinCode[0];
-                    mcFRState.OldTargetSpeed = IRControl.TargetSpeed;
-                    IRControl.FlagSpeed = 1;
-                    IRControl.NatureFlage = 1;
-                    //IRControl.FlagSpeed = 1;
-                    NatureWinFlag = 1;
-                }
-                
-                break;
-            }
-            
-            default:
-                break;
-        }
-        
-        IRScan.IRReceiveFlag = 0;
-    }
-}
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void AutoPowerControl(void)
-    Description   : 自动控制开关机
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void AutoPowerControl(void)
-{
-    if (IRControl.FlagAutoPower)
-    {
-        //        if (AutoPowerState.FlagAutoPower)
-        //        {
-        //            AutoPowerState.FlagAutoPower = 0;
-        //        }
-        //        else
-        //        {
-        AutoPowerState.FlagAutoPower = 1;
-        //        }
-        AutoPowerState.Timer10sec = 0;                                  //每次按遥控重新计时
-        AutoPowerState.CurrentTime = 0;
-        IRControl.FlagAutoPower = 0;
-    }
-    
-    //自动关机
-    if ((AutoPowerState.FlagAutoPower && IRControl.ONOFFStatus) || ( AutoPowerState.FlagAutoPower && IRControl.LEDONOFFStatus))
-    {
-        AutoPowerState.Timer10sec++;
-        
-        if (AutoPowerState.Timer10sec > 10000)
-        {
-            AutoPowerState.Timer10sec = 0;
-            AutoPowerState.CurrentTime++;
-            
-            if (AutoPowerState.CurrentTime >= AutoPowerState.ShutDowntime)
-            {
-                //              if(IRControl.ONOFFStatus)
-                //              {
-                IRControl.ONOFFStatus = 0;
-                mcFRState.OldTargetSpeed = 0;
-                IRControl.TargetSpeed = 0;
-                mcSpeedRamp.FlagONOFF = 0;
-                //              }
-                //              else
-                //              {
-                //                  IRControl.ONOFFStatus =1;
-                //                  PIControlTime = SPEED_LOOP_TIME;
-                //                  IRControl.TargetSpeed = MOTOR_POWER_LEVEL_1;
-                //              }
-                // IRControl.FlagONOFF = 1;
-                //               BZScan.FlagBZ = 1;
-                IRControl.FlagSpeed = 1;
-                
-                if (IRControl.LEDONOFFStatus)
-                {
-                    ResetLEDPin;
-                    IRControl.LEDONOFFStatus = 0;
-                }
-                
-                AutoPowerState.CurrentTime = 0;
-                AutoPowerState.FlagAutoPower = 0;
-            }
-        }
-    }
-    else
-    {
-        AutoPowerState.FlagAutoPower = 0;
-        AutoPowerState.Timer10sec = 0;
-        AutoPowerState.ShutDowntime = 0;
-        AutoPowerState.CurrentTime = 0;
-    }
-}
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : uint8 GetUserCode(void)
-    Description   : LED显示,IO口电平变化实现
-    Input         : 无
-    Output        : 无
-    -------------------------------------------------------------------------------------------------*/
-void LEDDisplay(void)
-{
-    // static uint8 LEDDiaplayStatus = 0;
-    if (IRControl.FlagLED)
-    {
-        if (IRControl.LEDONOFFStatus == 0)
-        {
-            SetLEDPin;
-            // IRControl.ONOFFStatus=1;
-            IRControl.LEDONOFFStatus = 1;
-        }
-        else
-        {
-            // IRControl.ONOFFStatus=0;
-            ResetLEDPin;
-            IRControl.LEDONOFFStatus = 0;
-        }
-        
-        IRControl.FlagLED = 0;
-    }
-}
-
-void IRONOFF_Control(void)
-{
-    if ((mcSpeedRamp.TargetValue == 0) && (mcState != mcRun) && (mcState != mcStop))
-    {
-        //关机后堵转保护次数和缺相保护次数清零
-        mcProtectTime.SecondStartTimes      = 0;
-        mcProtectTime.StallTimes            = 0;
-        mcProtectTime.LossPHTimes           = 0;
-        mcProtectTime.CurrentPretectTimes   = 0;
-    }
-}
-
-void NatureWind(void)
-{
-    static uint16 NatureWindCnt = 0;
-    static uint8  NatureWindStep = 0;
-    static uint8  FlageAddorDelace = 0;
-    //    if ((!NatureWinFlag) || (IRControl.FlagFR) || (!IRControl.ONOFFStatus) || (mcState != mcRun))
-    //    {
-    //        NatureWindCnt = 0;
-    //        NatureWindStep = 0;
-    //        return;
-    //    }
-    //    else
-    //    {
-    NatureWindCnt++;
-    //    }
-    //    IRControl.ONOFFStatus =1;
-    //      mcSpeedRamp.FlagONOFF = 1;
-    
-    if (NatureWindCnt > 5000)
-    {
-        NatureWindCnt = 0;
-        
-        if (FlageAddorDelace == 0)
-        {
-            if (NatureWindStep < 5)
-            { NatureWindStep++; }
-            else
-            {
-                NatureWindStep = 5;
-                FlageAddorDelace = 1;
-            }
-            
-            IRControl.TargetSpeed = NatureWinCode[NatureWindStep];
-            IRControl.FlagSpeed = 1;
-        }
-        else if (FlageAddorDelace)
-        {
-            if (NatureWindStep > 0)
-            { NatureWindStep--; }
-            else
-            {
-                NatureWindStep = 0;
-                FlageAddorDelace = 0;
-            }
-            
-            IRControl.TargetSpeed = NatureWinCode[NatureWindStep];
-            IRControl.FlagSpeed = 1;
-        }
-    }
-}

+ 2 - 11
User/Source/Interrupt.c

@@ -9,8 +9,6 @@
 
 extern uint8 data g_1mTick; ///< 1ms滴答信号,每隔1ms在SYSTICK定时器被置1,需在大循环使用处清零
 
-uint16 xdata spidebug[4] = {0}; ///< SPI debug 输出通道缓存,SPI调试器会将该变量值进行输出
-
 /**
 	@brief        低于预警中断与过温中断
 	@brief        开启低压检测中断后,MCU会对输入电压进行监测,当输入电压低于设定值,则会触发中断
@@ -51,7 +49,7 @@ void EXTERN0_INT(void) interrupt 1 //  外部中断0
 {
 	if (IF0)
 	{
-		IF0 = 0; // clear P00 interrupt flag
+		IF0 = 0;
 	}
 }
 /**
@@ -65,20 +63,13 @@ void DRV_ISR(void) interrupt 3
 
 	if (ReadBit(DRV_SR, DCIF)) // 比较中断
 	{
-#if (DBG_MODE == DBG_SPI_SW)   // 软件调试模式
-		spidebug[0] = mcFocCtrl.SPIVar3; // mcFocCtrl.mcDcbusFlt;
-		spidebug[1] = FOC__UQ;
-//		spidebug[2] = FOC__THETA; // mcBemf.BEMFSpeed;
-//		spidebug[3] = FOC__THETA;
-#endif
-
 #if (VoltageCompensationEn == 1)
 		{
 			if (VoltageComp.cpscnt > VoltageCompensationDelayCnt)
 			{
 				SetBit(ADC_CR, ADCBSY);
 				while (ReadBit(ADC_CR, ADCBSY));
-//				mcFocCtrl.mcDcbusFlt = ADC2_DR;
+				// mcFocCtrl.mcDcbusFlt = ADC2_DR;
 			}			
 			VoltageCompensation(mcFocCtrl.CtrlMode,mcFocCtrl.mcDcbusFlt);
 		}

+ 0 - 420
User/Source/KeyScan.c

@@ -1,420 +0,0 @@
-/**
- * @copyright None
- * @file      KeyScan.c
- * @author    Comment Vivre
- * @date      2024-08-26
- * @brief     None
- */
-#include <FU68xx_5.h>
-#include <Myproject.h>
-
-uint8 SW1_Flag = 0;
-uint8 SW2_Flag = 0;
-uint8 SW2_Flag2 = 0;
-uint8 SW3_Flag = 0;
-
-uint8 Flag_Key1Value = 0;      //档位变换顺序
-uint8 Flag_Key2Value = 0;
-
-/* Private variables ----------------------------------------------------------------------------*/
-KeyScanParam_TypeDef xdata KS;
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void KeyInit(void)
-    Description   : 按键参数初始化
-    Input         : 无
-    Output                :   无
-    -------------------------------------------------------------------------------------------------*/
-void KeyInit(void)
-{
-    uint8 i = 0;
-    uint8 Check_code = 0;           //写入数值为Write_Lenght,最后一位为校验位0xFF
-    uint16 ReadInfor_Addr = 0;      //读取信息地址
-    KS.Key1Value = 0x01;
-    KS.Key2Value = 0x40;
-    KS.Key3Value = 0x00;
-    KS.KeyValuetotal     = KS.Key1Value ^ KS.Key2Value ^ KS.Key3Value;
-    /*----- 获取写入首地址 -----*/
-    //    FlashData.WriteAddress = GetWrite_Black_Addr(START_WriteADDRESS, Write_Lenght);
-    
-    if (FlashData.WriteAddress > START_WriteADDRESS)
-    {
-        /*----- 获取读取数值首地址 -----*/
-        FlashData.ReadAddress  = FlashData.WriteAddress - Write_Lenght;
-        
-        while ((FlashData.WriteAddress > START_WriteADDRESS) && (Check_code != Verify_Ture))
-        {
-            ReadInfor_Addr = FlashData.ReadAddress + Verify_Bit;
-            Check_code = *(uint8 code *)(ReadInfor_Addr);
-            
-            if (Check_code == Verify_Ture)
-            {
-                /*----- 读取数值到FlashData.ReadValue -----*/
-                ReadFromFlash(FlashData.ReadAddress, Write_Lenght, FlashData.ReadValue);
-                KS.KeyValuetotal = FlashData.ReadValue[0];    //有数值直接读回上次保存的数值
-            }
-            else
-            {
-                FlashData.ReadAddress  = FlashData.ReadAddress - Write_Lenght;
-            }
-        }
-    }
-    else
-    {
-        /*----- 获取读取数值首地址 -----*/
-        FlashData.ReadAddress  = FlashData.WriteAddress;
-    }
-    
-    /*Flash写一个扇区 2/3 区域后开始尝试擦写*/
-    if (FlashData.WriteAddress >= START_WriteADDRESS + 0x060)                //
-    {
-        for (i = 0; i < Write_Lenght; i++)
-        {
-            FlashData.WriteValue[i] = FlashData.ReadValue[i];
-        }
-        
-        FlashData.Flag_FlashErase = 1;
-    }
-    
-    KS.Key1Value = KS.KeyValuetotal & 0x0F;
-    KS.Key2Value = KS.KeyValuetotal & 0x70;
-    KS.Key3Value = 0x00;
-    KS.OldKeyValuetotal  = 0;
-    KS.ChangeKeyFlg      = 0;
-    KS.Key1PressCnt = 0;
-    KS.TwoCarrierCnt = 0;
-    User.ScrOnZeroFlag = 0;
-    User.ScrOnZeroCnt = 0;
-}
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : uint8 KeyValue(void)
-    Description   : 功能函数,获取按键值,选择返回键位值还是管脚电平KeyValue
-    Input         : 无
-    Output                :   键位值或者管脚电平KeyValue
-    -------------------------------------------------------------------------------------------------*/
-int KeyValue(void)
-{
-    /* SW1 Scan */
-    if ((KS.KeyADCValue > 10922) && (KS.KeyADCValue < 19000))
-    {
-        if (SW1_Flag == 0)
-        {
-            KS.Key1PressCnt ++;
-            
-            if (KS.Key1PressCnt >= KeyFilterTime)
-            {
-                KS.Key1PressCnt = KeyFilterTime;
-                SW1_Flag = 1;
-                SW2_Flag = 0;
-                SW3_Flag = 0;
-                
-                if ((KS.Key1Value < 0x08) && (Flag_Key1Value == 0))
-                {
-                    KS.Key1Value = KS.Key1Value << 1;
-                }
-                else if ((KS.Key1Value > 0x01) && (Flag_Key1Value == 1))
-                {
-                    KS.Key1Value = KS.Key1Value >> 1;
-                }
-                else if (KS.Key1Value == 0x08)
-                {
-                    Flag_Key1Value = 1;
-                    KS.Key1Value = KS.Key1Value >> 1;
-                }
-                else if (KS.Key1Value == 0x01)
-                {
-                    Flag_Key1Value = 0;
-                    KS.Key1Value = KS.Key1Value << 1;
-                }
-                else
-                {
-                    Flag_Key1Value = 0;
-                    KS.Key1Value = 0x01;
-                }
-            }
-        }
-        else if (SW1_Flag == 1)
-        {
-            KS.Key1Value = KS.Key1Value ;
-        }
-        else
-        { SW1_Flag = 0; }
-    }
-    /* SW2 Scan */
-    else if ((KS.KeyADCValue >= 0) && (KS.KeyADCValue < 10922))
-    {
-        if (SW2_Flag == 0)
-        {
-            KS.Key2PressCnt ++;
-            
-            if (KS.Key2PressCnt >= KeyFilterTime)
-            {
-                KS.Key2PressCnt = KeyFilterTime;
-                SW2_Flag = 1;
-                SW1_Flag = 0;
-                SW3_Flag = 0;
-                
-                if ((KS.Key2Value < 0x40) && (Flag_Key2Value == 0))
-                {
-                    KS.Key2Value = KS.Key2Value << 1;
-                }
-                else if ((KS.Key2Value > 0x10) && (Flag_Key2Value == 1))
-                {
-                    KS.Key2Value = KS.Key2Value >> 1;
-                }
-                else if (KS.Key2Value == 0x40)
-                {
-                    Flag_Key2Value = 1;
-                    KS.Key2Value = KS.Key2Value >> 1;
-                }
-                else if (KS.Key2Value == 0x10)
-                {
-                    Flag_Key2Value = 0;
-                    KS.Key2Value = KS.Key2Value << 1;
-                }
-                else
-                {
-                    Flag_Key2Value = 0;
-                    KS.Key2Value = 0x20;
-                }
-            }
-        }
-        else if (SW2_Flag == 1)
-        {
-            KS.Key2Value = KS.Key2Value ;
-        }
-        else
-        { SW2_Flag = 0; }
-    }
-    /* SW3 Scan */
-    else if ((KS.KeyADCValue > 19000) && (KS.KeyADCValue < 25000))
-    {
-        KS.Key3releaseCnt = 0;
-        
-        if (KS.Key3PressCnt < KeyFilterTime * 2 + 10)
-        {
-            KS.Key3PressCnt++;
-        }
-        
-        if (SW3_Flag == 0)
-        {
-            if (KS.Key3PressCnt >= KeyFilterTime * 2)
-            {
-                KS.Key3PressCnt = KeyFilterTime * 2;
-                SW3_Flag = 1;
-                SW1_Flag = 0;
-                SW2_Flag = 0;
-                KS.Key3Value = 0x80;
-            }
-        }
-        else if (SW3_Flag == 1)
-        {
-            KS.Key3Value = KS.Key3Value ;
-        }
-    }
-    else
-    {
-        KS.Key2PressCnt --;
-        KS.Key1PressCnt --;
-        KS.Key3PressCnt = 0;
-        
-        if (KS.Key3releaseCnt < 100)
-        { KS.Key3releaseCnt++; }
-        
-        if ((KS.Key2PressCnt <= 0) && (KS.Key1PressCnt <= 0) && (KS.Key3releaseCnt >= 80))
-        {
-            SW3_Flag = 0;
-            SW1_Flag = 0;
-            SW2_Flag = 0;
-        }
-        
-        if (KS.Key2PressCnt <= 0)
-        {
-            KS.Key2PressCnt = 1;
-        }
-        
-        if (KS.Key1PressCnt <= 0)
-        {
-            KS.Key1PressCnt = 1;
-        }
-        
-        if (KS.Key3releaseCnt >= 80)
-        {
-            KS.Key3Value = 0x00;
-        }
-    }
-    
-    return (KS.Key1Value ^ KS.Key2Value ^ KS.Key3Value);
-}
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : uint8 KeyValue(void)
-    Description   : 功能函数,获取按键值,选择返回键位值还是管脚电平KeyValue
-    Input         : 无
-    Output                :   键位值或者管脚电平KeyValue
-    -------------------------------------------------------------------------------------------------*/
-int KeyValue1(void)
-{
-    /* SW1 温度 */
-    if ((KS.KeyADCValue > 14000) && (KS.KeyADCValue < 18000))
-    {
-        if (SW1_Flag == 0)
-        {
-            KS.Key1PressCnt ++;
-            
-            if (KS.Key1PressCnt >= KeyFilterTime)
-            {
-                KS.Key1PressCnt = KeyFilterTime;
-                SW1_Flag = 1;
-                SW2_Flag = 0;
-                SW3_Flag = 0;
-                SW2_Flag2 = 0;
-                
-                if ((KS.Key1Value < 0x08) && (Flag_Key1Value == 0))
-                {
-                    KS.Key1Value = KS.Key1Value << 1;
-                }
-                else if ((KS.Key1Value > 0x01) && (Flag_Key1Value == 1))
-                {
-                    KS.Key1Value = KS.Key1Value >> 1;
-                }
-                else if (KS.Key1Value == 0x08)
-                {
-                    Flag_Key1Value = 1;
-                    KS.Key1Value = KS.Key1Value >> 1;
-                }
-                else if (KS.Key1Value == 0x01)
-                {
-                    Flag_Key1Value = 0;
-                    KS.Key1Value = KS.Key1Value << 1;
-                }
-                else
-                {
-                    Flag_Key1Value = 0;
-                    KS.Key1Value = 0x01;
-                }
-            }
-        }
-        else if (SW1_Flag == 1)
-        {
-            KS.Key1Value = KS.Key1Value ;
-        }
-        else
-        { SW1_Flag = 0; }
-    }
-    /* SW2 风速2 */
-    else if ((KS.KeyADCValue > 20000) && (KS.KeyADCValue < 26000))
-    {
-        if (SW2_Flag == 0)
-        {
-            KS.Key2PressCnt ++;
-            
-            if (KS.Key2PressCnt >= KeyFilterTime)
-            {
-                KS.Key2PressCnt = KeyFilterTime;
-                SW2_Flag = 1;
-                SW1_Flag = 0;
-                SW3_Flag = 0;
-                SW2_Flag2 = 0;
-                KS.Key2Value = 0x20;
-            }
-        }
-        else if (SW2_Flag == 1)
-        {
-            KS.Key2Value = KS.Key2Value ;
-        }
-        else
-        { SW2_Flag = 0; }
-    }
-    else
-    {
-        if (KS.Key2PressCnt > 0)
-        {
-            KS.Key2PressCnt --;
-        }
-        
-        if (KS.Key1PressCnt > 0)
-        {
-            KS.Key1PressCnt --;
-        }
-        
-        KS.Key3PressCnt = 0;
-        
-        if (KS.Key3releaseCnt < 100)
-        { KS.Key3releaseCnt++; }
-        
-        if ((KS.Key2PressCnt <= 0) && (KS.Key1PressCnt <= 0) && (KS.Key3releaseCnt >= 80))
-        {
-            SW3_Flag = 0;
-            SW1_Flag = 0;
-            SW2_Flag = 0;
-        }
-        
-        if (KS.Key3releaseCnt >= 80)
-        {
-            KS.Key3Value = 0x00;
-        }
-        
-        /* SW2 风速1 */
-        if (KS.KeyADCValue > 30000)
-        {
-            if (SW2_Flag2 == 0)
-            {
-                KS.Key2PressCnt2++;
-                
-                if (KS.Key2PressCnt2 >= KeyFilterTime)
-                {
-                    KS.Key2PressCnt2 = KeyFilterTime;
-                    SW2_Flag2 = 1;
-                    SW2_Flag = 0;
-                    SW1_Flag = 0;
-                    SW3_Flag = 0;
-                    KS.Key2Value = 0x10;
-                }
-            }
-            else if (SW2_Flag2 == 1)
-            {
-                KS.Key2Value = KS.Key2Value ;
-            }
-            else
-            { SW2_Flag2 = 0; }
-        }
-    }
-    
-    return (KS.Key1Value ^ KS.Key2Value ^ KS.Key3Value);
-}
-
-
-/*  -------------------------------------------------------------------------------------------------
-    Function Name : void KeyScan(void)
-    Description   : 功能函数,按键扫描,按键触发传递出按键命令
-    Input         : 无
-    Output                :   无
-    -------------------------------------------------------------------------------------------------*/
-void KeyScan(void)
-{
-    KS.OldKeyValuetotal = KS.KeyValuetotal;
-    #if (SwitchMode == HighVoltageSwitch)
-    {
-        KS.KeyValuetotal = KeyValue1();
-    }
-    #elif (SwitchMode == LowVoltageSwitch)
-    {
-        KS.KeyValuetotal = KeyValue();
-    }
-    #endif
-    
-    if (KS.OldKeyValuetotal != KS.KeyValuetotal)
-    {
-        if ((mcState == mcRun))
-        {
-            KS.ChangeKeyFlg = 1;
-        }
-    }
-}
-
-
-

+ 0 - 195
User/Source/LED.c

@@ -1,195 +0,0 @@
-/**
- * @copyright None
- * @file      LED.c
- * @author    Comment Vivre 
- * @date      2024-08-26
- * @brief     None
- */
-#include <FU68xx_5.h>
-#include <Myproject.h>
-
-LEDCtl_TypeDef LEDCtl;
-
-
-#define LED_Time  20
-void LedDisplay(uint8 uLedMask)
-{
-	    LEDCtl.LEDCnt++;
-		GP12 = 0;
-		GP16 = 0;
-		GP21 = 0;	
-	
-		if(LEDCtl.LEDCnt<=(LED_Time*1))
-		{
-			if(uLedMask & LED1_MASK) //if(LED1==1)  //D11
-			{
-				SetBit(P1_OE, P12); 
-				ClrBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 1;
-				GP16 = 0;
-				GP21 = 0;
-							
-			}	
-			else
-			{
-				SetBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;					
-				
-			}				
-		}
-		else if (LEDCtl.LEDCnt<=(LED_Time*2))
-		{
-			if (uLedMask & LED2_MASK) //if(LED2==1)   //D8
-			{
-				SetBit(P1_OE, P12); 
-				ClrBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 1;
-			}	
-			else
-			{
-				SetBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;				
-				
-			}					
-		}			
-		else if (LEDCtl.LEDCnt<=(LED_Time*3))
-		{
-			if (uLedMask & LED3_MASK) //if(LED3==1)   //D7
-			{
-				ClrBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 1;
-						
-			}	
-			else
-			{
-				SetBit(P1_OE, P12);  
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;				
-			}					
-		}	
-		else if (LEDCtl.LEDCnt<=(LED_Time*4))
-		{
-			if (uLedMask & LED4_MASK) //if(LED4==1)  //D10
-			{
-				ClrBit(P1_OE, P12);  
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 1;
-				GP21 = 0;
-							
-			}	
-			else
-			{
-				SetBit(P1_OE, P12);  
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;					
-				
-			}					
-		}			
-		else if (LEDCtl.LEDCnt<=(LED_Time*5))
-		{
-			if (uLedMask & LED5_MASK) //if(LED5==1) //D9
-			{
-				SetBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				ClrBit(P2_OE, P21);
-				GP12 = 1;
-				GP16 = 0;
-				GP21 = 0;
-			}	
-			else
-			{
-				SetBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;					
-				
-			}					
-		}	
-		else if (LEDCtl.LEDCnt<=(LED_Time*6))
-		{
-			if (uLedMask & LED6_MASK) //if(LED6==1) //D6
-			{
-				SetBit(P1_OE, P12);  
-				SetBit(P1_OE, P16); 	
-				ClrBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 1;
-				GP21 = 0;
-							
-			}	
-			else
-			{
-				SetBit(P1_OE, P12); 
-				SetBit(P1_OE, P16); 	
-				SetBit(P2_OE, P21);
-				GP12 = 0;
-				GP16 = 0;
-				GP21 = 0;				
-				
-			}					
-		}
-		else if ((LEDCtl.LEDCnt <= (LED_Time*6+1))&&(mcFocCtrl.NTCValueGatherFlag==1))
-		{
-			#if (NTCSignalENABLE==1)
-			{			
-				ClrBit(P1_OE, P12); 
-				ClrBit(P1_OE, P16);
-				ClrBit(P2_OE, P21);
-				
-				SetBit(ADC_MASK, CH8EN);   
-				SetBit(P2_AN, PIN1);
-			}	
-			#endif			
-		}
-		else if ((LEDCtl.LEDCnt <= (LED_Time*6+5))&&(mcFocCtrl.NTCValueGatherFlag==1))
-		{ 
-																											//延迟5个载波时间,待NTC信号稳定再采集NTC信号
-		}			
-		else if ((LEDCtl.LEDCnt <= (LED_Time*6+15))&&(mcFocCtrl.NTCValueGatherFlag==1))
-		{ 
-			#if (NTCSignalENABLE==1)
-			{			
-				mcFocCtrl.NTCValue = ADC8_DR;    /* -----采集NTC温度----- */
-			}	
-			#endif			
-		}  
-		else
-		{	
-			#if (NTCSignalENABLE==1)
-			{			
-				mcFocCtrl.NTCValueGatherFlag =0;
-				ClrBit(ADC_MASK, CH8EN);   
-				ClrBit(P2_AN, PIN1);
-			}	
-			#endif		
-			LEDCtl.LEDCnt = 0;
-		}		
-}
-
-

+ 1 - 5
User/Source/MotorControl.c

@@ -41,7 +41,6 @@ void MC_Control(void)
                 mcState = mcInit;
                 mcCurOffset.OffsetFlag = 0;
                 mcCurOffset.OffsetCount = 0; // 偏置电压采集计数
-                KS.ChangeKeyFlg = 1;
             }
             
             break;
@@ -138,10 +137,7 @@ void MC_Control(void)
             #else
                 
             if (mcFocCtrl.State_Count == 0)
-            {
-                mcState = mcStart;
-                User.TPCtrlDealy = 5000; // 延时启动发热
-            }
+            { mcState = mcStart; }
                 
             #endif
             break;

+ 0 - 3
User/Source/MotorControlFunction.c

@@ -435,9 +435,6 @@ void VariablesPreInit(void)
     mcRefRamp.OutValue_float = 0;
     mcFocCtrl.ChargeStep = 0;
     mcFocCtrl.Flg_ATORampEnd = 0;
-    /* -----电机功率参数初始化----- */
-    mcFocCtrl.sqrtUdq = 0;
-    mcFocCtrl.NTCValueGatherFlag = 1; // 上电即采集NTC信号
 }
 
 /**

+ 10 - 23
User/Source/MotorProtect.c

@@ -1,7 +1,7 @@
 /**
  * @copyright None
  * @file      MotorProtect.c
- * @author    Comment Vivre 
+ * @author    Comment Vivre
  * @date      2024-08-26
  * @brief     None
  */
@@ -54,7 +54,7 @@ void Fault_Voltage(void)
     {
         if (mcFaultSource == FaultNoSource)
         {
-            /* 过压检测 */
+            // 过压检测
             if (mcFocCtrl.mcDcbusFlt > OVER_VOLTAGE_PROTECT)
             {
                 fault.Voltage.OverVoltDetecCnt += 1;
@@ -65,22 +65,15 @@ void Fault_Voltage(void)
                     mcFaultSource = FaultOverVoltageDC;
                 }
             }
-            else
-            {
-                if (fault.Voltage.OverVoltDetecCnt > 0)
-                {
-                    fault.Voltage.OverVoltDetecCnt--;
-                }
-            }
+            else if (fault.Voltage.OverVoltDetecCnt > 0)
+            { fault.Voltage.OverVoltDetecCnt--; }
             
             if (mcFocCtrl.mcDcbusFlt < UNDER_VOLTAGE_PROTECT)
             {
                 fault.Voltage.UnderVoltDetecCnt += 1;
                 
                 if (fault.Voltage.UnderVoltDetecCnt >= 20)
-                {
-                    VoltageComp.Undervoltage_flag = 1;
-                }
+                { VoltageComp.Undervoltage_flag = 1; }
                 
                 if (fault.Voltage.UnderVoltDetecCnt >= 60)
                 {
@@ -91,13 +84,8 @@ void Fault_Voltage(void)
                     fault.Voltage.FlagBrakeInit = 1;
                 }
             }
-            else
-            {
-                if (fault.Voltage.UnderVoltDetecCnt > 0)
-                {
-                    fault.Voltage.UnderVoltDetecCnt--;
-                }
-            }
+            else if (fault.Voltage.UnderVoltDetecCnt)
+            { fault.Voltage.UnderVoltDetecCnt--; }
         }
     }
 }
@@ -105,7 +93,6 @@ void Fault_Voltage(void)
 /**
  * @brief     欠压处理
  * @brief     刹车处理
- * @brief     Flash保存
  * @date      2022-07-14
  */
 void UnderProcess(void)
@@ -121,9 +108,9 @@ void UnderProcess(void)
             {
                 fault.Voltage.FlagBrakeInit = 2;
                 // DRV_CMR &= 0xFFC0;
-                ClrBit(DRV_CR, OCS);			// OCS = 0, PWM来源DRV_COMR
-                DRV_CMR = 0x0015;				// UVW相下桥输出
-                SetBit(DRV_CR, DRVEN);			// DRV计数器使能,0-禁止,1-使能
+                ClrBit(DRV_CR, OCS);            // OCS = 0, PWM来源DRV_COMR
+                DRV_CMR = 0x0015;               // UVW相下桥输出
+                SetBit(DRV_CR, DRVEN);          // DRV计数器使能,0-禁止,1-使能
                 MOE = 1;
                 DRV_DR = 0.05 * DRV_ARR;
             }

+ 54 - 108
User/Source/TIMER.c

@@ -1,119 +1,65 @@
-/* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
-	File Name      : TIMER.c
-	Author         : Fortiortech  Appliction Team
-	Version        : V1.0
-	Date           : 2021-04-11
-	Description    : This file contains .C file function used for Motor Control.
-----------------------------------------------------------------------------------------------------
-									   All Rights Reserved
-------------------------------------------------------------------------------------------------- */
+/**
+ * @copyright None
+ * @file      TIMER.c
+ * @author    Comment Vivre
+ * @date      2024-08-27
+ * @brief     None
+ */
 #include <MyProject.h>
 
-#include <TIMER.h>
-
-void Timer1_Init(void)
-{
-}
-
 void Timer2_Init(void)
 {
-	ClrBit(TIM2_CR1, T2CEN); // TIM2使能	0-->Disable  1-->Enable
-
-	ClrBit(PH_SEL, T2SEL);	// P10复用作为 Timer2 的输入输出
-	ClrBit(PH_SEL, T2SSEL); // P07复用作为 Timer2 的输入输出
-
-	ClrBit(TIM2_CR0, T2PSC2); // 计数器时钟分频选择
-	SetBit(TIM2_CR0, T2PSC1); // 000-->24M		001-->12M		010-->6M	011-->3M
-	SetBit(TIM2_CR0, T2PSC0); // 100-->1.5M	101-->750K		110-->375K	111-->187.5K
-
-	ClrBit(TIM2_CR0, T2MOD1); // 00-->输入Timer模式  			01-->输出模式
-	SetBit(TIM2_CR0, T2MOD0); // 10-->输入Counter模式  		11-->QEP&ISD&步进模式
-
-	ClrBit(TIM2_CR0, T2OCM); // 0: TIM2__CNTR < TIM2__DR,输出 0;TIM2__CNTR ≥ TIM2__DR,输出 1
-	// 1: TIM2__CNTR < TIM2__DR,输出 1;TIM2__CNTR ≥ TIM2__DR,输出 0
-	ClrBit(TIM2_CR0, T2CES); // 清零脉冲计数器不使能
-	SetBit(TIM2_CR0, T2IRE); // 比较匹配中断/脉宽检测中断0-->Disable  1-->Enable
-	SetBit(TIM2_CR1, T2IFE); // 计数器上溢中断使能 0-->Disable  1-->Enable
-
-	ClrBit(TIM2_CR1, T2IR | T2IF | T2IP); // 清零中断标志位
-	ClrBit(TIM2_CR1, T2IPE);			  // 输入Timer PWM周期检测中断使能 0-->Disable  1-->Enable
-
-	ClrBit(TIM2_CR1, T2FE);	 // 输入噪声滤波使能,小于4个时钟周期脉宽滤除
-	ClrBit(TIM2_CR1, T2DIR); // QEP&ISD&步进模式专用:当前的方向 0-->正向	1-->反向
-
-	SetBit(IP1, PTIM21);
-	SetBit(IP1, PTIM20); // 中断优先级别为2
-
-	TIM2__ARR = 30000; // //3M分频,1/3us,30000对应延迟10ms
-	TIM2__DR = 0;
-	TIM2__CNTR = 0;
-
-	SetBit(TIM2_CR1, T2CEN); // TIM2使能	0-->Disable  1-->Enable
+    ClrBit(TIM2_CR1, T2CEN); // TIM2使能  0-->Disable  1-->Enable
+    ClrBit(PH_SEL, T2SEL);  // P10复用作为 Timer2 的输入输出
+    ClrBit(PH_SEL, T2SSEL); // P07复用作为 Timer2 的输入输出
+    ClrBit(TIM2_CR0, T2PSC2); // 计数器时钟分频选择
+    SetBit(TIM2_CR0, T2PSC1); // 000-->24M      001-->12M       010-->6M    011-->3M
+    SetBit(TIM2_CR0, T2PSC0); // 100-->1.5M 101-->750K      110-->375K  111-->187.5K
+    ClrBit(TIM2_CR0, T2MOD1); // 00-->输入Timer模式             01-->输出模式
+    SetBit(TIM2_CR0, T2MOD0); // 10-->输入Counter模式       11-->QEP&ISD&步进模式
+    ClrBit(TIM2_CR0, T2OCM); // 0: TIM2__CNTR < TIM2__DR,输出 0;TIM2__CNTR ≥ TIM2__DR,输出 1
+    // 1: TIM2__CNTR < TIM2__DR,输出 1;TIM2__CNTR ≥ TIM2__DR,输出 0
+    ClrBit(TIM2_CR0, T2CES); // 清零脉冲计数器不使能
+    SetBit(TIM2_CR0, T2IRE); // 比较匹配中断/脉宽检测中断0-->Disable  1-->Enable
+    SetBit(TIM2_CR1, T2IFE); // 计数器上溢中断使能 0-->Disable  1-->Enable
+    ClrBit(TIM2_CR1, T2IR | T2IF | T2IP); // 清零中断标志位
+    ClrBit(TIM2_CR1, T2IPE);              // 输入Timer PWM周期检测中断使能 0-->Disable  1-->Enable
+    ClrBit(TIM2_CR1, T2FE);  // 输入噪声滤波使能,小于4个时钟周期脉宽滤除
+    ClrBit(TIM2_CR1, T2DIR); // QEP&ISD&步进模式专用:当前的方向 0-->正向 1-->反向
+    SetBit(IP1, PTIM21);
+    SetBit(IP1, PTIM20); // 中断优先级别为2
+    TIM2__ARR = 30000; // //3M分频,1/3us,30000对应延迟10ms
+    TIM2__DR = 0;
+    TIM2__CNTR = 0;
+    SetBit(TIM2_CR1, T2CEN); // TIM2使能  0-->Disable  1-->Enable
 }
 
 /* -------------------------------------------------------------------------------------------------
-	Function Name  : Timer3_Init
-	Description    : 定时器3初始化
-	Date           : 2021-11-08
-	Parameter      : None
+    Function Name  : Timer3_Init
+    Description    : 定时器3初始化
+    Date           : 2021-11-08
+    Parameter      : None
 ------------------------------------------------------------------------------------------------- */
 void Timer3_Init(void)
 {
-	SetBit(PH_SEL, T3SEL); // Timer3端口使能
-
-	ClrBit(PH_SEL1, T3CT0);
-	SetBit(PH_SEL1, T3CT1); //  00:P11   X1:P01  10:P47
-
-	SetBit(TIM3_CR0, T3PSC2); // 计数器时钟分频选择
-	SetBit(TIM3_CR0, T3PSC1); // 000-->24M		001-->12M		010-->6M	011-->3M
-	ClrBit(TIM3_CR0, T3PSC0); // 100-->1.5M	101-->750K		110-->375K	111-->187.5K
-
-	ClrBit(TIM3_CR0, T3OCM);
-
-	ClrBit(TIM3_CR0, T3IRE); // 比较匹配中断/脉宽检测中断0-->Disable  1-->Enable
-	ClrBit(TIM3_CR0, T3OPM); // 0-->计数器不停止		1-->单次模式
-
-	SetBit(TIM3_CR1, T3IPE); // 输入Timer PWM周期检测中断使能 0-->Disable  1-->Enable
-	SetBit(TIM3_CR1, T3IFE); // 计数器上溢中断使能 0-->Disable  1-->Enable
-
-	ClrBit(TIM3_CR1, T3NM1); // 输入噪声脉宽选择
-	ClrBit(TIM3_CR1, T3NM0); // 00-->不滤波	01-->4cycles    10-->8cycles  11-->16cycles
-
-	//    /* 定时器配置  */
-	//  SetBit(IP2, PTIM31);    //1ms定时中断优先级别为1
-	//  SetBit(IP2, PTIM30);
-	//	TIM3__DR = 1200;
-	//	TIM3__ARR = 2400;
-	ClrBit(TIM3_CR0, T3MOD); // 0-->Timer模式       1-->输出模式
-	SetBit(TIM3_CR1, T3EN);	 // TIM3使能    0-->Disable  1-->Enable
-}
-// void Timer4_Init(void)
-//{
-//     ClrBit(PH_SEL , T4SEL);     //Timer4端口使能
-//     ClrBit(PH_SEL1 , T4CT);     //默认端口为P11,功能转移后为P01,需TIMER4转移到P00
-
-//    ClrBit(TIM4_CR0 , T4PSC2);	//计数器时钟分频选择
-//    ClrBit(TIM4_CR0 , T4PSC1);	//000-->24M		001-->12M		010-->6M	011-->3M
-//    ClrBit(TIM4_CR0 , T4PSC0);	//100-->1.5M	101-->750K		110-->375K	111-->187.5K
-
-//    ClrBit(TIM4_CR0 , T4OCM);
-//    ClrBit(TIM4_CR0 , T4IRE);	//比较匹配中断/脉宽检测中断0-->Disable  1-->Enable
-//    ClrBit(TIM4_CR0 , T4OPM);	//0-->计数器不停止		1-->单次模式
-
-//    ClrBit(TIM4_CR1 , T4IPE);	//输入Timer PWM周期检测中断使能 0-->Disable  1-->Enable
-//    ClrBit(TIM4_CR1 , T4IFE);	//计数器上溢中断使能 0-->Disable  1-->Enable
-//    ClrBit(TIM4_CR1 , T4NM1);	//输入噪声脉宽选择
-//    ClrBit(TIM4_CR1 , T4NM0);	//00-->不滤波	01-->4cycles    10-->8cycles  11-->16cycles
-
-//    TIM4__ARR = 4800;
-//    TIM4__DR = TIM4__ARR>>1 ;
-//    TIM4__CNTR = 1;
-
-//    PTIM41 = 1;
-//    PTIM40 = 1;
-//    SetBit(TIM4_CR0 , T4MOD);   //0-->Timer模式       1-->输出模式
-//    ClrBit(TIM4_CR1 , T4EN);    //TIM3使能    0-->Disable  1-->Enable
-//}
-void TIM4_Init_RF(void)
-{
+    SetBit(PH_SEL, T3SEL); // Timer3端口使能
+    ClrBit(PH_SEL1, T3CT0);
+    SetBit(PH_SEL1, T3CT1); //  00:P11   X1:P01  10:P47
+    SetBit(TIM3_CR0, T3PSC2); // 计数器时钟分频选择
+    SetBit(TIM3_CR0, T3PSC1); // 000-->24M      001-->12M       010-->6M    011-->3M
+    ClrBit(TIM3_CR0, T3PSC0); // 100-->1.5M 101-->750K      110-->375K  111-->187.5K
+    ClrBit(TIM3_CR0, T3OCM);
+    ClrBit(TIM3_CR0, T3IRE); // 比较匹配中断/脉宽检测中断0-->Disable  1-->Enable
+    ClrBit(TIM3_CR0, T3OPM); // 0-->计数器不停止      1-->单次模式
+    SetBit(TIM3_CR1, T3IPE); // 输入Timer PWM周期检测中断使能 0-->Disable  1-->Enable
+    SetBit(TIM3_CR1, T3IFE); // 计数器上溢中断使能 0-->Disable  1-->Enable
+    ClrBit(TIM3_CR1, T3NM1); // 输入噪声脉宽选择
+    ClrBit(TIM3_CR1, T3NM0); // 00-->不滤波  01-->4cycles    10-->8cycles  11-->16cycles
+    //    /* 定时器配置  */
+    //  SetBit(IP2, PTIM31);    //1ms定时中断优先级别为1
+    //  SetBit(IP2, PTIM30);
+    //  TIM3__DR = 1200;
+    //  TIM3__ARR = 2400;
+    ClrBit(TIM3_CR0, T3MOD); // 0-->Timer模式       1-->输出模式
+    SetBit(TIM3_CR1, T3EN);  // TIM3使能    0-->Disable  1-->Enable
 }

+ 0 - 9
User/Source/UART.c

@@ -1,12 +1,3 @@
-/* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
-    File Name      : UART.c
-    Author         : Fortiortech  Appliction Team
-    Version        : V1.0
-    Date           : 2021-04-11
-    Description    : This file contains .C file function used for Motor Control.
-----------------------------------------------------------------------------------------------------  
-                                       All Rights Reserved
-------------------------------------------------------------------------------------------------- */
 #include <Myproject.h>
 
 

+ 63 - 89
User/Source/main.c

@@ -11,87 +11,8 @@
 
 uint8 data g_1mTick = 0; ///< 1ms滴答信号,每隔1ms在SYSTICK定时器被置1,需在大循环使用处清零
 
-/**
-    @brief        Function Definition
-*/
-static void HardwareInit(void);
-static void SoftwareInit(void);
-void VREFConfigInit(void);
-static void DebugSet(void);
 
-/**
-    @brief        SPI Debug调试小工具
-    @date         2022-07-14
-*/
-static void DebugSet(void)
-{
-    #if (DBG_MODE == DBG_SPI_HW) // 硬件调试模式
-    SPI_Init();
-    Set_DBG_DMA(&HARD_SPIDATA);
-    #elif (DBG_MODE == DBG_SPI_SW) // 软件调试模式
-    SPI_Init();
-    Set_DBG_DMA((uint16)spidebug);
-    #elif (DBG_MODE == DBG_UART)
-    UART2_Init();
-    Conf_DMA(1, XDATA_UART1, (uint16)GetAddr_UARTDBG(), BUFFLEN);
-    #endif
-}
-
-/**
-    @brief     硬件初始化,初始化需要使用的硬件设备配置,FOC必须配置的是运放电压、运放初始化、ADC初始化、Driver初始化
-              其他的可根据实际需求加。
-    @date      2022-07-14
-*/
-static void HardwareInit(void)
-{
-    // 为提高芯片的抗干扰能力,降低芯片功耗,请在具体项目时,将不需要用的GPIO默认都配置为输入上拉。
-    // 具体配置可在GPIO_Default_Init设置。
-    //    GPIO_Default_Init();
-    /************************硬件外设初始化**************************/
-    /* ADC参考电压电压配置 */
-    VREFConfigInit();
-    /*  硬件过流,比较器初始化,用于硬件过流比较保护  */
-    CMP3_Init();
-    GPIO_Init();
-    ADC_Init(); /* 初始化需要在Driver之前 */
-    Driver_Init();
-    AMP_Init();
-    // Timer3_Init();
-    // Timer2_Init();
-    /******温度配置初始化**********/
-    TSD_Init();
-    /*  比较器中断配置,与CMP3硬件配置间隔一段时间等待硬件稳定  */
-    CMP3_Interrupt_Init();
-    /*  SYSTICK定时器配置  */
-    ClrBit(IP2, PTIM41); // 1ms定时中断优先级别为1
-    SetBit(IP2, PTIM40);
-    SetBit(DRV_SR, SYSTIE);
-    EA = 1;
-}
 
-/**
-    @brief        部分变量初始化,上电运行一次
-    @date         2022-07-14
-*/
-static void SoftwareInit(void)
-{
-	    // 电机状态机时序变量
-    McStaSet.SetMode = 0;
-		// 电机目标方向
-		#if (FR_MODE == CW)
-	mcFocCtrl.FR = CW;
-		#else
-	mcFocCtrl.FR = CCW;
-	#endif // end IRMODE
-    /* -----电流偏置校准变量初始化----- */
-    mcCurOffset.IuOffsetSum = 16383;
-    mcCurOffset.IvOffsetSum = 16383;
-    mcCurOffset.Iw_busOffsetSum = 16383;
-    mcPwmInput.TimerARR = 65535;
-	
-    mcState = mcReady;
-    mcFaultSource = FaultNoSource;
-}
 
 /**
     @brief        参考电压,偏置电压配置
@@ -156,6 +77,59 @@ void VREFConfigInit(void)
     SetBit(VREF_VHALF_CR, VREFEN);
 }
 
+/**
+    @brief     硬件初始化,初始化需要使用的硬件设备配置,FOC必须配置的是运放电压、运放初始化、ADC初始化、Driver初始化
+              其他的可根据实际需求加。
+    @date      2022-07-14
+*/
+static void HardwareInit(void)
+{
+    // ADC参考电压电压配置
+    VREFConfigInit();
+    //  硬件过流,比较器初始化,用于硬件过流比较保护
+    CMP3_Init();
+    GPIO_Init();
+    ADC_Init(); // 初始化需要在Driver之前
+    Driver_Init();
+    AMP_Init();
+    // 温度配置初始化
+    TSD_Init();
+    // 比较器中断配置,与CMP3硬件配置间隔一段时间等待硬件稳定
+    CMP3_Interrupt_Init();
+    // SYSTICK定时器配置
+    // 1ms定时中断优先级别为1
+    ClrBit(IP2, PTIM41);
+    SetBit(IP2, PTIM40);
+    // 使能系统定时器中断
+    SetBit(DRV_SR, SYSTIE);
+    // 开启全局中断
+    EA = 1;
+}
+
+/**
+    @brief        部分变量初始化,上电运行一次
+    @date         2022-07-14
+*/
+static void SoftwareInit(void)
+{
+    // 电机状态机时序变量
+    McStaSet.SetMode = 0;
+    // 电机目标方向
+    #if (FR_MODE == CW)
+    mcFocCtrl.FR = CW;
+    #else
+    mcFocCtrl.FR = CCW;
+    #endif // end IRMODE
+    // 电流偏置校准变量初始化
+    mcCurOffset.IuOffsetSum = 16383;
+    mcCurOffset.IvOffsetSum = 16383;
+    mcCurOffset.Iw_busOffsetSum = 16383;
+	// 输入捕获定时器初始化
+    mcPwmInput.TimerARR = 65535;
+    mcState = mcReady;
+    mcFaultSource = FaultNoSource;
+}
+
 /**
     @brief        主函数,大循环运行偏置电流采集函数,电机状态机控制函数,以及环路响应函数
     @date         2022-07-14
@@ -163,23 +137,23 @@ void VREFConfigInit(void)
 void main(void)
 {
     uint16 PowerUpCnt = 0;
-    
-    /* ----- 上电空指令延时 等待系统稳定 ----- */
+	
+    // 上电空指令延时 等待系统稳定
     for (PowerUpCnt = 0; PowerUpCnt < SystemPowerUpTime; PowerUpCnt++);
-    
-    SoftwareInit();                 // 部分变量初始化
-    HardwareInit();                 // 硬件初始化
+	
+    // 部分变量初始化
+    SoftwareInit();
+	// 硬件初始化
+    HardwareInit();
     
     while (1)
     {
-        /* -----获取电流采样偏置电压----- */
+        // 获取电流采样偏置电压
         if (!mcCurOffset.OffsetFlag)
-        {
-            GetCurrentOffset();
-        }
+        { GetCurrentOffset(); }
         else
         {
-            /* -----电机控制状态机----- */
+            // 电机控制状态机
             MC_Control();
             
             if (g_1mTick)