Просмотр исходного кода

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

zhuhongbin 2 лет назад
Родитель
Сommit
484ed0f9a2
11 измененных файлов с 94 добавлено и 49 удалено
  1. 1 1
      MDK-ARM/test.uvprojx
  2. 4 9
      Src/gpio.c
  3. 2 3
      Src/main.c
  4. 1 1
      test.ioc
  5. 2 2
      tmr/buffer.c
  6. 26 25
      tmr/button.c
  7. 26 0
      tmr/display.c
  8. 4 0
      tmr/display.h
  9. 3 3
      tmr/flash.c
  10. 17 4
      tmr/plan.c
  11. 8 1
      tmr/weight.c

+ 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>

+ 4 - 9
Src/gpio.c

@@ -63,9 +63,11 @@ void MX_GPIO_Init(void)
   HAL_GPIO_WritePin(GPIOB, output1_Pin|output2_Pin|AD_SYNC_Pin, GPIO_PIN_RESET);
 
   /*Configure GPIO pins : PC13 PCPin PCPin PCPin
-                           PC3 PCPin PCPin PCPin */
+                           PC3 PCPin PCPin PCPin
+                           PCPin */
   GPIO_InitStruct.Pin = GPIO_PIN_13|AD_DIN_Pin|AD_CS_Pin|AD_CLK_Pin
-                          |GPIO_PIN_3|beep_Pin|led_Pin|alarm_Pin;
+                          |GPIO_PIN_3|beep_Pin|led_Pin|alarm_Pin
+                          |pwr_lock_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@@ -106,13 +108,6 @@ void MX_GPIO_Init(void)
   GPIO_InitStruct.Pull = GPIO_PULLDOWN;
   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
-  /*Configure GPIO pin : PtPin */
-  GPIO_InitStruct.Pin = pwr_lock_Pin;
-  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-  GPIO_InitStruct.Pull = GPIO_PULLUP;
-  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-  HAL_GPIO_Init(pwr_lock_GPIO_Port, &GPIO_InitStruct);
-
   /*Configure GPIO pin : PtPin */
   GPIO_InitStruct.Pin = ble_c_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

+ 2 - 3
Src/main.c

@@ -145,7 +145,6 @@ int main(void)
 
   /* USER CODE BEGIN SysInit */
 	MX_GPIO_Init();	
-	pwr_lock_on();
 	MX_IWDG_Init();  
   onbordflash_init();
 	HAL_IWDG_Refresh(&hiwdg);
@@ -163,7 +162,7 @@ int main(void)
   MX_RTC_Init();
   /* USER CODE BEGIN 2 */
   rt_show_version();  
-	
+
  /* 使能备份时钟:备份寄存器 */
 	__HAL_RCC_BKP_CLK_ENABLE();
 	HAL_PWR_EnableBkUpAccess();
@@ -339,7 +338,7 @@ uint8_t rDataBuffer;
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
 {  
 	if (huart->Instance == UART5 && isTag>0){
-		if (isTag) {
+		if (isTag>0) {
 			USART_Push(5, rDataBuffer);
 			rt_sem_release(thread_EmptyBuffer_sem); 	
 		}		

+ 1 - 1
test.ioc

@@ -271,7 +271,7 @@ PC8.Locked=true
 PC8.Signal=GPIO_Output
 PC9.GPIOParameters=GPIO_PuPd,GPIO_Label
 PC9.GPIO_Label=pwr_lock
-PC9.GPIO_PuPd=GPIO_PULLUP
+PC9.GPIO_PuPd=GPIO_NOPULL
 PC9.Locked=true
 PC9.Signal=GPIO_Output
 PD0-OSC_IN.Mode=HSE-External-Oscillator

+ 2 - 2
tmr/buffer.c

@@ -847,8 +847,8 @@ extern uint8_t rDataBuffer;
 static void threadEmptyBuffer_entry(void *parameter)
 {
 		unsigned char tempval;
-	  if (isTag > 0 )
-  	  HAL_UART_Receive_IT(&huart5, &rDataBuffer, 1); 
+//	  if (isTag >0 )
+//  	  HAL_UART_Receive_IT(&huart5, &rDataBuffer, 1); 
 		while(1)
 		{
 			 rt_sem_take(thread_EmptyBuffer_sem, RT_WAITING_FOREVER);   //µÈ´ý´®¿ÚÏûÏ¢

+ 26 - 25
tmr/button.c

@@ -69,14 +69,16 @@ static void CheckMenuButton_entry(void *parameter) {
 		if (button_state.b4>=5)	button_state.b4 = 0;
 		if (button_state.b5>=5)	button_state.b5 = 0;
 		if (button_state.b7>=15)	button_state.b7 = 0;
-
-//    if (HAL_GPIO_ReadPin(pwr_GPIO_Port, pwr_Pin) == 0) {
-//			rt_thread_mdelay(2000);
-//			if ((HAL_GPIO_ReadPin(pwr_GPIO_Port, pwr_Pin) == 0) ) {
-//				beep();
-//				pwr_lock_off();
-//			}
-//    }
+//		if (WeightConst_SBType == 3 && isnewBan==1)
+					{	
+			if (HAL_GPIO_ReadPin(pwr_GPIO_Port, pwr_Pin) == 0) {
+				rt_thread_mdelay(2000);
+				if ((HAL_GPIO_ReadPin(pwr_GPIO_Port, pwr_Pin) == 0) ) {
+					beep();
+					pwr_lock_on();
+				}
+			}
+		}
 		
 		//  if (WeightConst_TQ==14)  ad_sample=Ad_Sample1();//get_weight();
 		if (WeightConst_SBType<5)
@@ -469,7 +471,7 @@ static void CheckButton_entry(void *parameter) {
 						rt_thread_mdelay(2000);
 						if ((HAL_GPIO_ReadPin(pwr_GPIO_Port, pwr_Pin) == 0) ) {
 							beep();
-							pwr_lock_off();
+							pwr_lock_on();
 						}
 					}
 		  	}
@@ -482,20 +484,20 @@ static void CheckButton_entry(void *parameter) {
                       //  beep(); 
                       //  WeightConst_DELAYTIME = (pf_comp.data.delaytime*60)+1;    //ÔÊÐí°´¼üÌø¹ý½Á°èÑÓʱ
                     }
-                    else if (pf_comp.data.needBegin==1 && WeightConst_WeightHaveBegin==0)
+                   else if (pf_comp.data.needBegin==1 && WeightConst_WeightHaveBegin==0)
                     {
-                        beep();
-												rt_sem_take(weight_lock, RT_WAITING_FOREVER);
-                        WeightConst_WeightBegin = WeightConst_WeightCur;
-												rt_sem_release(weight_lock);
-											  CompleteTarget_order = pf_comp.data.pfsort;
-											  write_Flash("completeorder", &CompleteTarget_order, sizeof(CompleteTarget_order));	
-											  rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
-											  write_Flash("begintime", &TimeConst, sizeof(TimeConst));				
-											  rt_sem_release(setTIME_lock);							
-                        write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin)); 
-                        getTargetWeight();
-                    }
+//                        beep();
+//												rt_sem_take(weight_lock, RT_WAITING_FOREVER);
+//                        WeightConst_WeightBegin = WeightConst_WeightCur;
+//												rt_sem_release(weight_lock);
+//											  CompleteTarget_order = pf_comp.data.pfsort;
+//											  write_Flash("completeorder", &CompleteTarget_order, sizeof(CompleteTarget_order));	
+//											  rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
+//											  write_Flash("begintime", &TimeConst, sizeof(TimeConst));				
+//											  rt_sem_release(setTIME_lock);							
+//                        write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin)); 
+//                        getTargetWeight();
+                    } 
                     else if (tsdb_recordcount('p')>0 && delayKeying == 0 && WeightConst_Product_Run)
 						      	{			
 												rt_sem_release(delay_key_sem); 													
@@ -697,8 +699,7 @@ static void CheckButton_entry(void *parameter) {
                     beep();
                 }
 								else {
-								 // Planback();
-									/*
+								 // Planback();									
 									if (pf_comp.data.needBegin==1 && WeightConst_WeightHaveBegin==0)
                     {
                         beep();
@@ -712,7 +713,7 @@ static void CheckButton_entry(void *parameter) {
 											  rt_sem_release(setTIME_lock);							
                         write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin)); 
                         getTargetWeight();
-                    }*/
+                    }
 								}
             }
             else

+ 26 - 0
tmr/display.c

@@ -1325,3 +1325,29 @@ unsigned char get_msg(  unsigned char Xstart,// 0 - 191
 		rt_thread_mdelay(150);
     return 0;
 }
+
+
+//01 05 20 00 FF 00 87 FA
+unsigned char uart_send_buf_modbus[10];
+unsigned char get_modbusmsg(unsigned char addr,// 0 - 191
+                        unsigned char func, //0 - 47
+                        unsigned short dataaddr,//1 or 2 or 3
+                        unsigned short state)
+{
+    unsigned char i=0;
+    unsigned short int calcCRC;
+  	uart_send_buf_modbus[0] = addr;
+    uart_send_buf_modbus[1] = func;
+    uart_send_buf_modbus[2] = (dataaddr>>8)&0xFF;
+    uart_send_buf_modbus[3] = dataaddr&0xFF;
+    uart_send_buf_modbus[4] = (state>>8)&0xFF;
+    uart_send_buf_modbus[5] = state&0xFF;
+
+    calcCRC = CRC16(uart_send_buf_modbus, 6);
+    uart_send_buf_modbus[6] = (unsigned char)(calcCRC>>8);  //µÍλ
+    uart_send_buf_modbus[7] = (unsigned char)(calcCRC);  //¸ßλ
+    for(i=0; i<=7; i++)
+	    HAL_UART_Transmit(&huart5, (uint8_t *)&uart_send_buf_modbus[i], 1, 1);
+		rt_thread_mdelay(150);
+    return 0;
+}

+ 4 - 0
tmr/display.h

@@ -46,5 +46,9 @@ extern unsigned char get_msg(  unsigned char Xstart,// 0 - 191
                                unsigned char Xend,
                                unsigned char f,
                                unsigned char * ASCII_buf);
+extern unsigned char get_modbusmsg(unsigned char addr,// 0 - 191
+                        unsigned char func, //0 - 47
+                        unsigned short dataaddr,//1 or 2 or 3
+                        unsigned short state);
 
 #endif 

+ 3 - 3
tmr/flash.c

@@ -9,8 +9,8 @@
 
 uint8_t  isCC = 0 ;
 uint8_t  isBLE =0;  //用蓝牙传输
-uint8_t  isNsmall =1;  //新小屏
-uint8_t  isnewBan =0;  //隔离主板
+uint8_t  isNsmall =0;  //新小屏
+uint8_t  isnewBan =1;  //隔离主板
 const uint8_t  isTag = 0 ; //是否含识读标签
 unsigned char  isn = 0;  //是否新大屏
 unsigned char  remote_sumweight = 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 = 0x03;
+uint8_t WeightConst_SBType = 0x01;
 
 
 int16_t WeightConst_WeightBegin = -3000;    //按键开始重量

+ 17 - 4
tmr/plan.c

@@ -47,6 +47,7 @@ unsigned char XbeeConst_lastsort;        //
 unsigned char XbeeConst_lastinorout;        //保存刚刚收到的发料或加料
 unsigned char XbeeConst_FrameNum = 0;  //帧编号
 
+unsigned char feedpos = 0;  //罐号
 //__attribute__((zero_init))  uint8_t XbeeConst_FrameNum;//帧编号
 unsigned char XbeeConst_CanSend=1;
 unsigned char getPlaning=0;
@@ -354,7 +355,12 @@ void pop_product_entry(void *parameter) {
 										WeightConst_oksum=0;										
 				          	WeightConst_joksum = 0;
 					          WeightConst_WeightOK = -32760;
-
+										feedpos = 0;
+										if (isTag==2 && pf_comp.data.addorout==0 && pf_comp.data.pfsort<253)
+										{
+											pf_comp.data.pfsort = (pf_comp.data.pfsort & 0x0F);
+											feedpos = ((pf_comp.data.pfsort>>4) & 0x0f);
+										}
 										if (pf_comp.data.firstReget)	{
 												pf_comp.data.needBegin = 0;
 												plan_comp.data.reget = 0;
@@ -617,9 +623,16 @@ void getTargetWeight(void)
 
 		if (isTag==1)
     {
-              Rec_watchTag_point=0;  //接收标签
-              ReadTag_state=0;   //读标签状态  0  没读或已读成功,1  开始读 ,2  正在读
-              WriteTag_state=0;  //写标签状态  0  没写或已写成功,1  开始写 ,2  正在写  
+			Rec_watchTag_point=0;  //接收标签
+			ReadTag_state=0;   //读标签状态  0  没读或已读成功,1  开始读 ,2  正在读
+			WriteTag_state=0;  //写标签状态  0  没写或已写成功,1  开始写 ,2  正在写  
+    }else if (isTag==2)
+    {
+			if (feedpos>0)
+			{ 
+				if (feedpos<8) get_modbusmsg(1,10,feedpos+300,WeightConst_WeightTargetTemp);
+				get_modbusmsg(1,5,feedpos + 0x2000,0xFF00);
+			}
     }
 		
 		if (WeightConst_SBType>2 && WeightConst_SBType<7) {

+ 8 - 1
tmr/weight.c

@@ -115,6 +115,10 @@ void weight_usart_Init(UART_HandleTypeDef* uartHandle)
 					uartHandle->Init.StopBits    = UART_STOPBITS_1;	 //停止位1位		
 			}		
   }
+	else if (uartHandle->Instance==UART5)
+	{
+		 uartHandle->Init.BaudRate = 9600;
+	}
 //	else if ((uartHandle->Instance==USART3) && (iscowweight==1))
 //	{
 //		 uartHandle->Init.BaudRate = 19200;
@@ -147,7 +151,10 @@ static void setWeightSM() {  // 
         WeightConst_WeightCount++; // 重量采样数	
 		   	WeightConst_allsum++;
 		  	rt_sem_release(weight_lock);
-			
+				if (isTag==2)
+				{
+					get_modbusmsg(1,10,308,WeightConst_WeightCurTem);
+				}
         //判断是否在范围内
         if(pf_comp.data.autosecond>0 &&  WeightConst_WeightHaveBegin==1 && WeightConst_Product_Run > 0) { //跳转时间大于0
             if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin &&