From 7d8ba5df7d883c86c24aa38449c4a6dd126e920f Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期二, 06 八月 2024 14:41:31 +0800
Subject: [PATCH] Radio_LLCC68 1.15, Stable version

---
 ComLib/Src/ModbusRTU.c |   30 +++++++-----------------------
 1 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/ComLib/Src/ModbusRTU.c b/ComLib/Src/ModbusRTU.c
index f143e6c..89509c5 100644
--- a/ComLib/Src/ModbusRTU.c
+++ b/ComLib/Src/ModbusRTU.c
@@ -61,25 +61,7 @@
 	return(crc);
 }
 */ 
-const uint16_t crctalbeabs[] = { 
-	0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 
-	0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 
-};
 
-uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len) 
-{
-	uint16_t crc = 0xffff; 
-	uint16_t i;
-	uint8_t ch;
- 
-	for (i = 0; i < len; i++) {
-		ch = *ptr++;
-		crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4);
-		crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4);
-	} 
-	
-	return crc;
-}
 
 //**********************************************************************
 //******************  Modbus slave  ************************************
@@ -236,15 +218,17 @@
 		case WriteCoil:	//5  bit
 		//Store Datas;
 			//SetBitValue(&KMem.WR[Addr1],bitAddr,pPkg->nCount);	
+				Addr1=(Addr&0xfff0)>>4;
+				bitAddr=Addr&0xf;
 			if (nCount == 0)		// set to 0
 			{
-				ResetBit(&KMem.WY[Addr1],bitAddr);
+				if (Addr < 2048) { ResetBit(&KMem.WY[Addr1],bitAddr);}
+				else {ResetBit(&KMem.WR[Addr1-128],bitAddr);}				
 			}else if (nCount == 0xFF00)	// set to 1
 			{
-				SetAddrBit(&KMem.WY[Addr1],bitAddr);
-			}else
-			{
-				//error
+				if (Addr < 2048) { SetAddrBit(&KMem.WY[Addr1],bitAddr);}
+				else {SetAddrBit(&KMem.WR[Addr1-128],bitAddr);}
+				
 			}
 			memcpy(Pkgbuf,ptr,len);
 			needcrc=0;

--
Gitblit v1.9.1