Browse Source

Signed-off-by: zhuhongbin <kptzhu@163.com>

zhuhongbin 2 years ago
parent
commit
32443cb5b3
18 changed files with 206 additions and 140 deletions
  1. 0 0
      .mxproject
  2. 1 0
      Inc/main.h
  3. 0 1
      Inc/stm32f1xx_it.h
  4. 1 1
      MDK-ARM/RTE/RTOS/rtconfig.h
  5. 1 1
      MDK-ARM/test.uvprojx
  6. 23 0
      Src/gpio.c
  7. 4 1
      Src/main.c
  8. 27 1
      Src/rtc.c
  9. 0 15
      Src/stm32f1xx_it.c
  10. 1 6
      Src/usart.c
  11. 2 1
      fal/fal_flash_stm32f1_port.c
  12. 64 37
      test.ioc
  13. 18 14
      tmr/Ad.c
  14. 7 7
      tmr/daScreen.c
  15. 42 42
      tmr/display.c
  16. 5 5
      tmr/flash.c
  17. 1 1
      tmr/plan.c
  18. 9 7
      tmr/weight.c

File diff suppressed because it is too large
+ 0 - 0
.mxproject


+ 1 - 0
Inc/main.h

@@ -58,6 +58,7 @@ void Error_Handler(void);
 /* USER CODE END EFP */
 
 /* Private defines -----------------------------------------------------------*/
+#define t 8
 #define AD_DIN_Pin GPIO_PIN_0
 #define AD_DIN_GPIO_Port GPIOC
 #define AD_CS_Pin GPIO_PIN_1

+ 0 - 1
Inc/stm32f1xx_it.h

@@ -63,7 +63,6 @@ void USART1_IRQHandler(void);
 void USART2_IRQHandler(void);
 void USART3_IRQHandler(void);
 void UART4_IRQHandler(void);
-void UART5_IRQHandler(void);
 void DMA2_Channel3_IRQHandler(void);
 void DMA2_Channel4_5_IRQHandler(void);
 /* USER CODE BEGIN EFP */

+ 1 - 1
MDK-ARM/RTE/RTOS/rtconfig.h

@@ -119,7 +119,7 @@
 // <h>Console Configuration
 // <c1>Using console
 //  <i>Using console
-//#define RT_USING_CONSOLE
+#define RT_USING_CONSOLE
 // </c>
 // <o>the buffer size of console <1-1024>
 //  <i>the buffer size of console

+ 1 - 1
MDK-ARM/test.uvprojx

@@ -336,7 +336,7 @@
               <MiscControls></MiscControls>
               <Define>STM32F103xE,USE_HAL_DRIVER</Define>
               <Undefine></Undefine>
-              <IncludePath>../Inc;    ../Drivers/STM32F1xx_HAL_Driver/Inc;    ../Drivers/CMSIS/Device/ST/STM32F1xx/Include;    ../Drivers/CMSIS/Include;    ../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;    ..\fal\inc;    ..\fal;    ..\flashdb\inc;    ..\tmr;    ..\cm_backtrace;    ..\syswatch\inc</IncludePath>
+              <IncludePath>../Inc;          ../Drivers/STM32F1xx_HAL_Driver/Inc;          ../Drivers/CMSIS/Device/ST/STM32F1xx/Include;          ../Drivers/CMSIS/Include;          ../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy;          ..\fal\inc;          ..\fal;          ..\flashdb\inc;          ..\tmr;          ..\cm_backtrace;          ..\syswatch\inc</IncludePath>
             </VariousControls>
           </Cads>
           <Aads>

+ 23 - 0
Src/gpio.c

@@ -37,6 +37,8 @@
         * Output
         * EVENT_OUT
         * EXTI
+        * Free pins are configured automatically as Analog (this feature is enabled through
+        * the Code Generation settings)
 */
 void MX_GPIO_Init(void)
 {
@@ -69,12 +71,33 @@ void MX_GPIO_Init(void)
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
+  /*Configure GPIO pins : PC14 PC15 PC4 */
+  GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4;
+  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+  /*Configure GPIO pins : PA0 PA1 PA4 PA5
+                           PA6 PA7 PA11 PA12
+                           PA15 */
+  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5
+                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_11|GPIO_PIN_12
+                          |GPIO_PIN_15;
+  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
   /*Configure GPIO pin : PtPin */
   GPIO_InitStruct.Pin = pwr_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
   GPIO_InitStruct.Pull = GPIO_PULLUP;
   HAL_GPIO_Init(pwr_GPIO_Port, &GPIO_InitStruct);
 
+  /*Configure GPIO pins : PB0 PB1 PB2 PB3
+                           PB4 PB5 */
+  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
+                          |GPIO_PIN_4|GPIO_PIN_5;
+  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
   /*Configure GPIO pins : PBPin PBPin PBPin PBPin
                            PBPin */
   GPIO_InitStruct.Pin = B4_Pin|B3_Pin|B2_Pin|B1_Pin

+ 4 - 1
Src/main.c

@@ -185,11 +185,14 @@ int main(void)
 	WeightConst_DELAYTIME= HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR5);	
 	WeightConst_WeightTargetAllowMin = 32767;  //目标重量的允许跳转范围
   WeightConst_WeightTargetAllowMax = -32768;  //目标重量的允许跳转范围
-	pf_comp.data.delaytime= HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR6);
+	pf_comp.data.delaytime = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR6);	
+	//WeightConst_WeightCurTem = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR7);
 	thread_beep_init();
 	output1_off();
 	output2_off();
 	AT_off();
+	
+
  // rt_kprintf("\n \\ | /\n");
 	rt_sem_take(thread_init_sem, RT_WAITING_FOREVER);   //等待初始化进程完毕
 //			 init_allflash();

+ 27 - 1
Src/rtc.c

@@ -29,17 +29,43 @@ RTC_HandleTypeDef hrtc;
 /* RTC init function */
 void MX_RTC_Init(void)
 {
+  RTC_TimeTypeDef sTime = {0};
+  RTC_DateTypeDef DateToUpdate = {0};
 
   /** Initialize RTC Only
   */
   hrtc.Instance = RTC;
   hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
-  hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
+  hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
   if (HAL_RTC_Init(&hrtc) != HAL_OK)
   {
     Error_Handler();
   }
 
+  /* USER CODE BEGIN Check_RTC_BKUP */
+
+  /* USER CODE END Check_RTC_BKUP */
+
+  /** Initialize RTC and set the Time and Date
+  */
+  sTime.Hours = 0;
+  sTime.Minutes = 0;
+  sTime.Seconds = 0;
+
+  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
+  DateToUpdate.Month = RTC_MONTH_JANUARY;
+  DateToUpdate.Date = 1;
+  DateToUpdate.Year = 0;
+
+  if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
+  {
+    Error_Handler();
+  }
+
 }
 
 void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)

+ 0 - 15
Src/stm32f1xx_it.c

@@ -69,7 +69,6 @@ extern DMA_HandleTypeDef hdma_usart2_tx;
 extern DMA_HandleTypeDef hdma_usart3_rx;
 extern DMA_HandleTypeDef hdma_usart3_tx;
 extern UART_HandleTypeDef huart4;
-extern UART_HandleTypeDef huart5;
 extern UART_HandleTypeDef huart1;
 extern UART_HandleTypeDef huart2;
 extern UART_HandleTypeDef huart3;
@@ -312,20 +311,6 @@ void UART4_IRQHandler(void)
   /* USER CODE END UART4_IRQn 1 */
 }
 
-/**
-  * @brief This function handles UART5 global interrupt.
-  */
-void UART5_IRQHandler(void)
-{
-  /* USER CODE BEGIN UART5_IRQn 0 */
-
-  /* USER CODE END UART5_IRQn 0 */
-  HAL_UART_IRQHandler(&huart5);
-  /* USER CODE BEGIN UART5_IRQn 1 */
-
-  /* USER CODE END UART5_IRQn 1 */
-}
-
 /**
   * @brief This function handles DMA2 channel3 global interrupt.
   */

+ 1 - 6
Src/usart.c

@@ -77,7 +77,7 @@ void MX_UART5_Init(void)
 {
 
   huart5.Instance = UART5;
-  huart5.Init.BaudRate = 9600;
+  huart5.Init.BaudRate = 115200;
   huart5.Init.WordLength = UART_WORDLENGTH_8B;
   huart5.Init.StopBits = UART_STOPBITS_1;
   huart5.Init.Parity = UART_PARITY_NONE;
@@ -239,9 +239,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
-    /* UART5 interrupt Init */
-    HAL_NVIC_SetPriority(UART5_IRQn, 1, 0);
-    HAL_NVIC_EnableIRQ(UART5_IRQn);
   /* USER CODE BEGIN UART5_MspInit 1 */
 
   /* USER CODE END UART5_MspInit 1 */
@@ -480,8 +477,6 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
 
     HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
 
-    /* UART5 interrupt Deinit */
-    HAL_NVIC_DisableIRQ(UART5_IRQn);
   /* USER CODE BEGIN UART5_MspDeInit 1 */
 
   /* USER CODE END UART5_MspDeInit 1 */

+ 2 - 1
fal/fal_flash_stm32f1_port.c

@@ -6,6 +6,7 @@
 
 #include <string.h>
 #include <fal.h>
+#include "iwdg.h"
 #include <stm32f1xx.h>
 
 #if defined(STM32F103xE)
@@ -50,7 +51,7 @@ int on_ic_write_cnt = 0;
 
 void feed_dog(void)
 {
-
+   HAL_IWDG_Refresh(&hiwdg);
 }
 
 static int read(long offset, uint8_t *buf, size_t size)

+ 64 - 37
test.ioc

@@ -89,50 +89,56 @@ KeepUserPlacement=false
 Mcu.Family=STM32F1
 Mcu.IP0=DMA
 Mcu.IP1=IWDG
+Mcu.IP10=USART3
 Mcu.IP2=NVIC
 Mcu.IP3=RCC
-Mcu.IP4=SYS
-Mcu.IP5=UART4
-Mcu.IP6=UART5
-Mcu.IP7=USART1
-Mcu.IP8=USART2
-Mcu.IP9=USART3
-Mcu.IPNb=10
+Mcu.IP4=RTC
+Mcu.IP5=SYS
+Mcu.IP6=UART4
+Mcu.IP7=UART5
+Mcu.IP8=USART1
+Mcu.IP9=USART2
+Mcu.IPNb=11
 Mcu.Name=STM32F103R(C-D-E)Tx
 Mcu.Package=LQFP64
 Mcu.Pin0=PC13-TAMPER-RTC
 Mcu.Pin1=PD0-OSC_IN
-Mcu.Pin10=PB11
-Mcu.Pin11=PB12
-Mcu.Pin12=PB13
-Mcu.Pin13=PB14
-Mcu.Pin14=PB15
-Mcu.Pin15=PC6
-Mcu.Pin16=PC7
-Mcu.Pin17=PC8
-Mcu.Pin18=PA9
-Mcu.Pin19=PA10
+Mcu.Pin10=PB10
+Mcu.Pin11=PB11
+Mcu.Pin12=PB12
+Mcu.Pin13=PB13
+Mcu.Pin14=PB14
+Mcu.Pin15=PB15
+Mcu.Pin16=PC6
+Mcu.Pin17=PC7
+Mcu.Pin18=PC8
+Mcu.Pin19=PC9
 Mcu.Pin2=PD1-OSC_OUT
-Mcu.Pin20=PA13
-Mcu.Pin21=PA14
-Mcu.Pin22=PC10
-Mcu.Pin23=PC11
-Mcu.Pin24=PC12
-Mcu.Pin25=PD2
-Mcu.Pin26=PB6
-Mcu.Pin27=PB7
-Mcu.Pin28=PB8
-Mcu.Pin29=PB9
+Mcu.Pin20=PA8
+Mcu.Pin21=PA9
+Mcu.Pin22=PA10
+Mcu.Pin23=PA13
+Mcu.Pin24=PA14
+Mcu.Pin25=PC10
+Mcu.Pin26=PC11
+Mcu.Pin27=PC12
+Mcu.Pin28=PD2
+Mcu.Pin29=PB6
 Mcu.Pin3=PC0
-Mcu.Pin30=VP_IWDG_VS_IWDG
-Mcu.Pin31=VP_SYS_VS_Systick
+Mcu.Pin30=PB7
+Mcu.Pin31=PB8
+Mcu.Pin32=PB9
+Mcu.Pin33=VP_IWDG_VS_IWDG
+Mcu.Pin34=VP_RTC_VS_RTC_Activate
+Mcu.Pin35=VP_RTC_No_RTC_Output
+Mcu.Pin36=VP_SYS_VS_Systick
 Mcu.Pin4=PC1
 Mcu.Pin5=PC2
 Mcu.Pin6=PC3
 Mcu.Pin7=PA2
 Mcu.Pin8=PA3
-Mcu.Pin9=PB10
-Mcu.PinsNb=32
+Mcu.Pin9=PC5
+Mcu.PinsNb=37
 Mcu.ThirdPartyNb=0
 Mcu.UserConstants=t,8
 Mcu.UserName=STM32F103RCTx
@@ -171,6 +177,11 @@ PA2.Mode=Asynchronous
 PA2.Signal=USART2_TX
 PA3.Mode=Asynchronous
 PA3.Signal=USART2_RX
+PA8.GPIOParameters=GPIO_PuPd,GPIO_Label
+PA8.GPIO_Label=ble_c
+PA8.GPIO_PuPd=GPIO_NOPULL
+PA8.Locked=true
+PA8.Signal=GPIO_Output
 PA9.Mode=Asynchronous
 PA9.Signal=USART1_TX
 PB10.Mode=Asynchronous
@@ -178,22 +189,22 @@ PB10.Signal=USART3_TX
 PB11.Mode=Asynchronous
 PB11.Signal=USART3_RX
 PB12.GPIOParameters=GPIO_PuPd,GPIO_Label
-PB12.GPIO_Label=B1
+PB12.GPIO_Label=B4
 PB12.GPIO_PuPd=GPIO_PULLDOWN
 PB12.Locked=true
 PB12.Signal=GPIO_Input
 PB13.GPIOParameters=GPIO_PuPd,GPIO_Label
-PB13.GPIO_Label=B2
+PB13.GPIO_Label=B3
 PB13.GPIO_PuPd=GPIO_PULLDOWN
 PB13.Locked=true
 PB13.Signal=GPIO_Input
 PB14.GPIOParameters=GPIO_PuPd,GPIO_Label
-PB14.GPIO_Label=B3
+PB14.GPIO_Label=B2
 PB14.GPIO_PuPd=GPIO_PULLDOWN
 PB14.Locked=true
 PB14.Signal=GPIO_Input
 PB15.GPIOParameters=GPIO_PuPd,GPIO_Label
-PB15.GPIO_Label=B4
+PB15.GPIO_Label=B1
 PB15.GPIO_PuPd=GPIO_PULLDOWN
 PB15.Locked=true
 PB15.Signal=GPIO_Input
@@ -238,6 +249,11 @@ PC2.Locked=true
 PC2.Signal=GPIO_Output
 PC3.Locked=true
 PC3.Signal=GPIO_Output
+PC5.GPIOParameters=GPIO_PuPd,GPIO_Label
+PC5.GPIO_Label=pwr
+PC5.GPIO_PuPd=GPIO_PULLUP
+PC5.Locked=true
+PC5.Signal=GPIO_Input
 PC6.GPIOParameters=GPIO_Label,GPIO_ModeDefaultOutputPP
 PC6.GPIO_Label=beep
 PC6.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP
@@ -253,6 +269,11 @@ PC8.GPIO_Label=alarm
 PC8.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP
 PC8.Locked=true
 PC8.Signal=GPIO_Output
+PC9.GPIOParameters=GPIO_PuPd,GPIO_Label
+PC9.GPIO_Label=pwr_lock
+PC9.GPIO_PuPd=GPIO_PULLUP
+PC9.Locked=true
+PC9.Signal=GPIO_Output
 PD0-OSC_IN.Mode=HSE-External-Oscillator
 PD0-OSC_IN.Signal=RCC_OSC_IN
 PD1-OSC_OUT.Mode=HSE-External-Oscillator
@@ -270,7 +291,7 @@ ProjectManager.DefaultFWLocation=true
 ProjectManager.DeletePrevious=true
 ProjectManager.DeviceId=STM32F103RCTx
 ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.4
-ProjectManager.FreePins=false
+ProjectManager.FreePins=true
 ProjectManager.HalAssertFull=false
 ProjectManager.HeapSize=0x200
 ProjectManager.KeepUserCode=true
@@ -289,7 +310,7 @@ ProjectManager.TemplateDestinationPath=D\:\\test
 ProjectManager.TemplateSourcePath=C\:\\Program Files (x86)\\STMicroelectronics\\STM32Cube\\STM32CubeMX\\db\\extra_templates
 ProjectManager.ToolChainLocation=
 ProjectManager.UnderRoot=false
-ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_UART4_Init-UART4-false-HAL-true,6-MX_UART5_Init-UART5-false-HAL-true,7-MX_USART2_UART_Init-USART2-false-HAL-true,8-MX_USART3_UART_Init-USART3-false-HAL-true,9-MX_IWDG_Init-IWDG-false-HAL-true
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_UART4_Init-UART4-false-HAL-true,6-MX_UART5_Init-UART5-false-HAL-true,7-MX_USART2_UART_Init-USART2-false-HAL-true,8-MX_USART3_UART_Init-USART3-false-HAL-true,9-MX_IWDG_Init-IWDG-false-HAL-true,10-MX_RTC_Init-RTC-false-HAL-true
 RCC.ADCFreqValue=18000000
 RCC.AHBFreq_Value=72000000
 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@@ -316,6 +337,8 @@ RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
 RCC.TimSysFreq_Value=72000000
 RCC.USBFreq_Value=72000000
 RCC.VCOOutput2Freq_Value=8000000
+RTC.Format=RTC_FORMAT_BIN
+RTC.IPParameters=Format
 UART4.BaudRate=57600
 UART4.IPParameters=VirtualMode,BaudRate
 UART4.VirtualMode=Asynchronous
@@ -332,6 +355,10 @@ USART3.IPParameters=VirtualMode,BaudRate
 USART3.VirtualMode=VM_ASYNC
 VP_IWDG_VS_IWDG.Mode=IWDG_Activate
 VP_IWDG_VS_IWDG.Signal=IWDG_VS_IWDG
+VP_RTC_No_RTC_Output.Mode=RTC_OUT_NO
+VP_RTC_No_RTC_Output.Signal=RTC_No_RTC_Output
+VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
+VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
 VP_SYS_VS_Systick.Mode=SysTick
 VP_SYS_VS_Systick.Signal=SYS_VS_Systick
 board=custom

+ 18 - 14
tmr/Ad.c

@@ -130,10 +130,10 @@ ulng get_weight(void)
     // ad_sample_=ad_sample;
     //  ad_sample=(int)((float)ad_sample * 0.01 + (1.0 - 0.01) * (float)ad_sample);
    // ad_sample = AdFilter_xf(ad_sample);  //限幅滤波	 FLT_XF_CNT=32;
-		ad_sample = middleFilter(ad_sample);		
-		
+					
 		tempvalw = ad_sample;
-		
+		ad_sample = middleFilter(ad_sample);	
+		/*
 		switch(fs[1])
 		{
 		case 1:
@@ -161,8 +161,8 @@ ulng get_weight(void)
 				ad_sample = Kalman_Filter(ad_sample, 0.125, 0.5);
 				break;
 		}	  
-	
-		//ad_sample = AdFilter(ad_sample);     //滑动滤波	  FLT_CNT=32;		
+	*/
+		ad_sample = AdFilter(ad_sample);     //滑动滤波	  FLT_CNT=32;		
 						
 		if (tempWeighttime<100){	
 			tempWeighttime ++;	
@@ -281,7 +281,7 @@ ulng Ad_Sample1(void)
             _nop_();
        //     _nop_();
         }
-/*
+
         if ((AdSample&0x00800000)!=0)
         {
             AdSample=~AdSample+1;
@@ -293,7 +293,7 @@ ulng Ad_Sample1(void)
             AdSample&=0x007fffff;
             AdSample=0x007fffff+AdSample;
         }
-				*/
+				
         if (fs[1]<=4 && fs[1]>0 )
             AdSample = AdSample>>3;
         else if (fs[1]>4 && fs[1]<=6 )
@@ -680,19 +680,23 @@ ulng Kalman_Filter(const double ResrcData, double ProcessNiose_Q,double MeasureN
 }
 
 
-ulng middleFilterdata[128];
+ulng middleFilterdata[50];
+ulng middleFilterdata1[50];
+rt_uint8_t middlepos=0;
 ulng middleFilter(ulng x)
 {
 	ulng i;
 	ulng j;
 	ulng temp;
-	for (j = 0; j < 31-1; j++)
-	  middleFilterdata[j] = middleFilterdata[j+1];
-	middleFilterdata[31] = x;
+	if (middlepos>10) middlepos=0;
+	else middlepos++;
+	middleFilterdata1[middlepos] = x;
+	for (j = 0; j < 11; j++)
+	  middleFilterdata[j] = middleFilterdata1[j];
 	
-	for (j = 0; j < 31-1; j++)
+	for (j = 0; j < 10; j++)
 	{
-		for (i = 0; i < 31-j; i++)
+		for (i = 0; i < 10-j; i++)
 		{
 			if (middleFilterdata[i] > middleFilterdata[i+1])
 			{
@@ -703,7 +707,7 @@ ulng middleFilter(ulng x)
 		}
 	}
 	
-	return middleFilterdata[floor((FLT_CNT-1)/2)];
+	return middleFilterdata[(11-1)/2];
 } 
 
 /****************************/

+ 7 - 7
tmr/daScreen.c

@@ -55,7 +55,7 @@ extern unsigned short WeightConst_productW;  //目标总量
 extern unsigned char WeightConst_feed[]; //原料名称
 extern unsigned char WeightConst_Nextfeed[]; //临时表
 extern signed short WeightConst_NextWeightTarget;      //目标重量
-extern signed long WeightConst_WeightCurTem;
+extern signed long WeightConst_WeightCur;
 extern unsigned char WeightConst_Weight_display[];
 
 extern unsigned char ScreenBuf_Pop(void);
@@ -249,7 +249,7 @@ void display_Total(signed long weight)  //  合计:           500显示当前
 			display_Total_v[13+2+i] = cmd_Sum[i];
 
 		i=35;
-	  Weight_displayW = abs(WeightConst_WeightCurTem);
+	  Weight_displayW = abs(WeightConst_WeightCur);
     if (Weight_displayW==0)
     {
         i--;
@@ -265,7 +265,7 @@ void display_Total(signed long weight)  //  合计:           500显示当前
             }
             else break;
         }
-    if (WeightConst_WeightCurTem<0) display_Total_v[i-1] = 0x2d;
+    if (WeightConst_WeightCur<0) display_Total_v[i-1] = 0x2d;
 
 }
 
@@ -468,7 +468,7 @@ void display_KPT_TMRWatch_weight_()
 			                                   0x20,0x20
                                         };
 		i=47; 
-		Weight_displayW = abs(WeightConst_WeightCurTem);
+		Weight_displayW = abs(WeightConst_WeightCur);
     if (Weight_displayW==0)
     {
         i--;
@@ -484,7 +484,7 @@ void display_KPT_TMRWatch_weight_()
             }
             else break;
         }
-    if (WeightConst_WeightCurTem<0) KPT_TMRWatch[40] = 0x2d;
+    if (WeightConst_WeightCur<0) KPT_TMRWatch[40] = 0x2d;
     display_New_(KPT_TMRWatch, 0x36,
                  0,  // 是否清除
                  1, // 区域数
@@ -616,7 +616,7 @@ void display_Now_(signed long weight)  //               少   30显示当前差
     }
 
     i= 103;
-    Weight_displayW = abs(WeightConst_WeightCurTem);
+    Weight_displayW = abs(WeightConst_WeightCur);
     if (Weight_displayW==0)
     {
         i--;
@@ -632,7 +632,7 @@ void display_Now_(signed long weight)  //               少   30显示当前差
             }
             else break;
         }
-    if (WeightConst_WeightCurTem<0) KPT_TMRWatch[96] = 0x2d;
+    if (WeightConst_WeightCur<0) KPT_TMRWatch[96] = 0x2d;
     if (WeightConst_Run || inMenu==1)
         display_New_(KPT_TMRWatch, 128,
                      0,  // 是否清除

+ 42 - 42
tmr/display.c

@@ -288,7 +288,7 @@ static void MenuDisplay_entry(void *parameter) {
 				}
 				else {
 						display_Current_noweight_();
-						display_Now_(WeightConst_WeightCurTem);
+						display_Now_(WeightConst_WeightCur);
 				}
 		}
 //	  HAL_IWDG_Refresh(&hiwdg);
@@ -377,10 +377,10 @@ void getDisplay(void)
 		else
 		{
 				if (WeightConst_Product_Run>0 && WeightConst_displayTotal==0  && pf_comp.data.pfsort!=0xFE && WeightConst_WeightHaveBegin==1)
-						WeightConst_Weight_displayW = WeightConst_WeightCurTem - WeightConst_WeightTarget;
+						WeightConst_Weight_displayW = WeightConst_WeightCur - WeightConst_WeightTarget;
 				else
-						WeightConst_Weight_displayW = WeightConst_WeightCurTem;
-        WeightConst_Weight_displayCurW = WeightConst_WeightCurTem;
+						WeightConst_Weight_displayW = WeightConst_WeightCur;
+        WeightConst_Weight_displayCurW = WeightConst_WeightCur;
 				for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++)   //ÏÔʾÖØÁ¿
 						WeightConst_Weight_display[SendDisplay_i]=0x20;	
 
@@ -799,11 +799,11 @@ static void Display_entry(void *parameter) {
 						{
 							if (isn>=1)
 							{
-								display_Now_(WeightConst_WeightCurTem);
+								display_Now_(WeightConst_WeightCur);
 							}
 							else{							
 								display_Now();
-								display_Total(WeightConst_WeightCurTem);
+								display_Total(WeightConst_WeightCur);
 								row++;
 								if (row%rowx==0){
 									for (int j=0; j<39; j++)	uart4_send_data[j] = display_productName_v[j];
@@ -869,22 +869,22 @@ static void Display_entry(void *parameter) {
 							if(WeightConst_Product_Run)
 							{
 								rt_uint8_t index = 0,value = 0;	
-                signed long WeightConst_WeightCurTem_ = 0;		
+                signed long WeightConst_WeightCur_ = 0;		
 								uart4_send_data[0]=0x20;uart4_send_data[1]=0x20;uart4_send_data[2]=0x20;
 								uart4_send_data[3]=0x20;uart4_send_data[4]=0x30;	
-                if 	(WeightConst_WeightCurTem<0)
+                if 	(WeightConst_WeightCur<0)
 								{									
-									 WeightConst_WeightCurTem_ = WeightConst_WeightCurTem*-1;
+									 WeightConst_WeightCur_ = WeightConst_WeightCur*-1;
 									 uart4_send_data[0] = 0x2D;
 								}
-                else 	WeightConst_WeightCurTem_ = WeightConst_WeightCurTem;			
+                else 	WeightConst_WeightCur_ = WeightConst_WeightCur;			
 								
 								
 								for (int SendDisplay_i = 0; SendDisplay_i < 5; SendDisplay_i++) {
-										if (SendDisplay_i>0)	WeightConst_WeightCurTem_=WeightConst_WeightCurTem_/10;
+										if (SendDisplay_i>0)	WeightConst_WeightCur_=WeightConst_WeightCur_/10;
 
-										if (WeightConst_WeightCurTem_>0)
-												uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCurTem_)%10+'0';
+										if (WeightConst_WeightCur_>0)
+												uart4_send_data[4-SendDisplay_i] = (WeightConst_WeightCur_)%10+'0';
 										else break;
 								}
 								get_msg(0,//Xstart
@@ -958,38 +958,38 @@ static void Display_entry(void *parameter) {
 
 								uart4_send_data[index++] =  0x10;			
 													
-                WeightConst_WeightCurTem_ = WeightConst_WeightTargetTemp;	
-								value = (WeightConst_WeightCurTem_ / 10000) % 10;
+                WeightConst_WeightCur_ = WeightConst_WeightTargetTemp;	
+								value = (WeightConst_WeightCur_ / 10000) % 10;
 								if(value != 0) {
 									uart4_send_data[index++] = value + 0x30;
-									uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 1000) % 10 + 0x30;
-									uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
-									uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
-									uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
+									uart4_send_data[index++] = (WeightConst_WeightCur_ / 1000) % 10 + 0x30;
+									uart4_send_data[index++] = (WeightConst_WeightCur_ / 100) % 10 + 0x30;
+									uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
+									uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
 								}
 								else {
-									  value = (WeightConst_WeightCurTem_ / 1000) % 10;
+									  value = (WeightConst_WeightCur_ / 1000) % 10;
 										if(value != 0) {
 											uart4_send_data[index++] = value + 0x30;
-											uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 100) % 10 + 0x30;
-											uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
-											uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
+											uart4_send_data[index++] = (WeightConst_WeightCur_ / 100) % 10 + 0x30;
+											uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
+											uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
 										}
 									  else {
-											value = (WeightConst_WeightCurTem_ / 100) % 10;
+											value = (WeightConst_WeightCur_ / 100) % 10;
 											if(value != 0) {
 												uart4_send_data[index++] = value + 0x30;
-												uart4_send_data[index++] = (WeightConst_WeightCurTem_ / 10) % 10 + 0x30;
-												uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
+												uart4_send_data[index++] = (WeightConst_WeightCur_ / 10) % 10 + 0x30;
+												uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
 											}
 											else {
-												value = (WeightConst_WeightCurTem_ / 10) % 10;
+												value = (WeightConst_WeightCur_ / 10) % 10;
 												if(value != 0) {
 													uart4_send_data[index++] = value + 0x30;
-												  uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
+												  uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
 												}
 												else {
-													 uart4_send_data[index++] = WeightConst_WeightCurTem_ % 10 + 0x30;
+													 uart4_send_data[index++] = WeightConst_WeightCur_ % 10 + 0x30;
 												}
 											}
 										}
@@ -1030,33 +1030,33 @@ static void Display_entry(void *parameter) {
 							uart4_send_data[1]=0;
 							uart4_send_data[2]=0;
 							uart4_send_data[3]=0;
-							if ((WeightConst_WeightTarget < WeightConst_WeightCurTem && pf_comp.data.addorout==0)
-								|| (WeightConst_WeightTarget > WeightConst_WeightCurTem && pf_comp.data.addorout==1))
+							if ((WeightConst_WeightTarget < WeightConst_WeightCur && pf_comp.data.addorout==0)
+								|| (WeightConst_WeightTarget > WeightConst_WeightCur && pf_comp.data.addorout==1))
 							{
 									uart4_send_data[0]= 100;
 								 uart4_send_data[1]=0xFF;								
 							}
 							else
 							{		
-                  if (WeightConst_WeightCurTem<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) &&  pf_comp.data.addorout==0)
+                  if (WeightConst_WeightCur<(WeightConst_WeightTarget-WeightConst_WeightTargetTemp) &&  pf_comp.data.addorout==0)
                     tempw=0;
-									else if (WeightConst_WeightCurTem>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) &&  pf_comp.data.addorout==1)
+									else if (WeightConst_WeightCur>(WeightConst_WeightTargetTemp+WeightConst_WeightTarget) &&  pf_comp.data.addorout==1)
                     tempw=0;
                   else if (pf_comp.data.addorout==0)									
-									 tempw = ( WeightConst_WeightCurTem-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp));
+									 tempw = ( WeightConst_WeightCur-(WeightConst_WeightTarget-WeightConst_WeightTargetTemp));
 									else 
-										tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCurTem);
+										tempw = ((WeightConst_WeightTarget+WeightConst_WeightTargetTemp)-WeightConst_WeightCur);
 								  uart4_send_data[0]=tempw*100/WeightConst_WeightTargetTemp;
 								
 						
-								if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) ||
-									(WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1)
+								if ((WeightConst_WeightCur>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0) ||
+									(WeightConst_WeightCur<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1)
 								)
 								{
 								   uart4_send_data[2]=0xFF;
 								}
-								else if ((WeightConst_WeightCurTem+30>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)||
-									(WeightConst_WeightCurTem-30<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
+								else if ((WeightConst_WeightCur+30>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)||
+									(WeightConst_WeightCur-30<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
 									{uart4_send_data[1]=0xFF;		uart4_send_data[3]=0xFF;	
 								}
                 else 
@@ -1167,11 +1167,11 @@ static void Display_entry(void *parameter) {
 //            if (WeightConst_Product_Run) {
 //                if(isn!=1 && (ScreenBufSize()<100)) {
 //                    display_Now();
-//                    display_Total(WeightConst_WeightCurTem);
+//                    display_Total(WeightConst_WeightCur);
 //                }
-//                else if(isn==1) display_Now_(WeightConst_WeightCurTem);
+//                else if(isn==1) display_Now_(WeightConst_WeightCur);
 //            }
-//            else if(isn==1 && WeightConst_Run==1) display_Now_(WeightConst_WeightCurTem);
+//            else if(isn==1 && WeightConst_Run==1) display_Now_(WeightConst_WeightCur);
 //        }
 
 //        if (SendRemote_timer>700 && RemoteSendDisplay &&

+ 5 - 5
tmr/flash.c

@@ -9,7 +9,7 @@
 
 uint8_t  isCC = 0 ;
 uint8_t  isBLE =0;  //用蓝牙传输
-uint8_t  isNsmall =0;  //新小屏
+uint8_t  isNsmall =1;  //新小屏
 uint8_t  isnewBan =0;  //隔离主板
 const uint8_t  isTag = 0 ; //是否含识读标签
 unsigned char  isn = 0;  //是否新大屏
@@ -23,7 +23,7 @@ uint8_t XbeeConst_UseAPI = 0x00;
 uint8_t WeightConst_TQ = 0x05;//0x05;
 uint8_t WeightConst_BLE = 0;
 uint8_t WeightConst_ChanCheShu = 0x02;
-uint8_t WeightConst_SBType = 0x01;
+uint8_t WeightConst_SBType = 0x03;
 
 
 int16_t WeightConst_WeightBegin = 0;    //按键开始重量
@@ -92,9 +92,9 @@ static void lock(fdb_db_t db)
 }
 
 static void unlock(fdb_db_t db)
-{
-	 rt_sem_release(kv_db_lock);
-	 __enable_irq();
+{	 
+	__enable_irq();
+	rt_sem_release(kv_db_lock);
 }
 
 static fdb_time_t get_keydbtime(void)

+ 1 - 1
tmr/plan.c

@@ -352,7 +352,7 @@ void pop_product_entry(void *parameter) {
 										HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR4, WeightConst_DELAYON);	
 										CanButton = 0x01;
 										WeightConst_oksum=0;
-					          WeightConst_WeightOK = 0;
+					          WeightConst_WeightOK = -32760;
 
 										if (pf_comp.data.firstReget)	{
 												pf_comp.data.needBegin = 0;

+ 9 - 7
tmr/weight.c

@@ -241,8 +241,8 @@ void CheckWeightthread(void) {
 					if (WeightConst_DELAYTIME >  (pf_comp.data.delaytime * 60))  //10 &&pf_comp.data.delaytime>0 )
 					{
 							write_Flash("begintime", &TimeConst, sizeof(TimeConst));											
-//							WeightConst_WeightBegin = WeightConst_WeightCur;					
-//              write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin)); 
+							WeightConst_WeightBegin = WeightConst_WeightCur;					
+              write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin)); 
 							pf_comp.data.delaytime = 0;
 						  WeightConst_DELAYTIME = 0;
 						  WeightConst_DELAYON = 0;
@@ -264,7 +264,8 @@ void CheckWeightthread(void) {
             WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMax; //  重量和 减去最大值
             WeightConst_WeightCount = WeightConst_WeightCount - 2;
         }
-        WeightConst_WeightCur = WeightConst_WeightSum / WeightConst_WeightCount;
+				if (WeightConst_WeightCount>0)
+          WeightConst_WeightCur = WeightConst_WeightSum / WeightConst_WeightCount;
 		  	
 				
         if (WeightConst_WeightCurCount >= 0x0F) {  //15秒准备发送后台重
@@ -1131,7 +1132,7 @@ static void P_TMI_III() {
                 }
                 setWeightSM();
                 WeightConst_RecFlag1 = 0x00;
-                WeightConst_Drop = 1; //开始抛弃数据
+                WeightConst_Drop = 0; //开始抛弃数据
             }
             /*else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x67 &&
             WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B )
@@ -1185,7 +1186,7 @@ static void P_TMI_III() {
                 }
                 setWeightSM();
                 WeightConst_RecFlag1 = 0x00;
-                WeightConst_Drop = 1; //开始抛弃数据
+                WeightConst_Drop = 0; //开始抛弃数据
             }
             WeightConst_RecWeightPoint1 = 0; //指针还原
         } else {
@@ -1940,7 +1941,7 @@ void ReadWeight(void)
 uint16_t tempWeight;
 uint16_t tempWeighttime = 0;
 void ReadWeightthread(void) {
-	  
+	  WeightConst_WeightCurTem = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR7);
 		while(1)
 		{			  
 				if (WeightConst_TQ==14 );// && CanButton== 0x01);
@@ -1952,6 +1953,7 @@ void ReadWeightthread(void) {
            
 					  if (nag)	WeightConst_WeightCurTem = (signed long)(tempWeight*-1);
 					  else WeightConst_WeightCurTem = (signed long)(tempWeight);
+					  HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR7, WeightConst_WeightCurTem);	
 						WeightConst_WeightWS = ad_Point;
 						setWeightSM();	
 						rt_sem_release(display_lock);
@@ -1965,7 +1967,7 @@ void ReadWeightthread(void) {
 union timekeyweight_t getTimeWeight(int i) {
     if ((i==0xF1) && (WeightConst_WeightOK > -32768)) {
         WeightConst_WeightLast = WeightConst_WeightOK;  //保存按键时的重量
-        WeightConst_WeightOK = 0;
+        WeightConst_WeightOK = -32760;
     }
     else {
 				rt_sem_take(weight_lock, RT_WAITING_FOREVER);

Some files were not shown because too many files changed in this diff