From 842bb64195f958b050867c50db66fc0aa413dafb Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期六, 27 七月 2024 10:42:56 +0800
Subject: [PATCH] KBus upgrade

---
 KSingleLineBus/user/main.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/KSingleLineBus/user/main.c b/KSingleLineBus/user/main.c
index 4ca5711..768e02e 100644
--- a/KSingleLineBus/user/main.c
+++ b/KSingleLineBus/user/main.c
@@ -74,6 +74,10 @@
 
 int nCount=0;
 
+stSLPDef SLP1;
+
+unsigned char bSLPMaster;
+unsigned char nSLPStation;
 
 
 void PutOutput(uchar a);
@@ -94,6 +98,8 @@
 }Coils;
 	
 Coils inputdata;	
+
+/*
 void Delay1ms()		//@22.1184MHz
 {
 	uchar data i, j;
@@ -108,7 +114,6 @@
 	} while (--i);
 }
 
-
 void Delay_ms(uint n)
 {
 	while(n--)
@@ -117,7 +122,7 @@
 	}
 	
 }	
-
+*/
 void Delay_us(uint n)
 {
 	uchar data j;
@@ -298,11 +303,12 @@
 		uart3busy=1;
 	}
 }
+/*
 void SLPSendPacket(char * str, uchar len)
 {
 	Uart3SendPacket(str,len);
 }
-
+*/
 void Uart3RecvPacket()
 {
 		if (uart3recvtimeout <2){
@@ -310,7 +316,7 @@
 	}else
 	{ /// recieved packet;
 			RUN=~RUN;		//闪灯				
-			SLPparsePacket(uart3recvbuf,uart3recvlen);
+			SLPparsePacket(&SLP1,uart3recvbuf,uart3recvlen);
 			uart3recvlen =0;
 	}
 }
@@ -378,7 +384,11 @@
 	
 	inputdata.Byte = GetJumper();		
 	bSLPMaster = inputdata.bits.b5 ; //master?
-	nStation = inputdata.Byte & 0x0f;
+	nSLPStation = inputdata.Byte & 0x0f;
+	SLPInit(&SLP1,Uart3SendPacket);
+	SLP1.bSLPMaster = bSLPMaster;
+	SLP1.nStation = nSLPStation;
+	
 //	bSLPMaster=1;
 	
 	while(1)
@@ -389,15 +399,15 @@
 		
 		// Get Input Port;
 		inputdata.Byte = GetInput();		
-		SLPinputB = inputdata.Byte; 
+		SLP1.SLPinputB = inputdata.Byte; 
 				RUN =~ RUN;
 //		Delay_ms(1);
 		// receive packet 
 		Uart3RecvPacket();
 		// Process Packet
-		SLPProcess();
+		SLPProcess(&SLP1);
 		
-		if (SLPErrSign) {
+		if (SLP1.SLPErrSign) {
 			ERR = 0;
 		}else {
 			ERR =1;
@@ -405,7 +415,7 @@
 		}
 		
 		// Set Ouput Port
-		PutOutput(SLPoutputB);
+		PutOutput(SLP1.SLPoutputB);
 
 		
 		// receive packet 

--
Gitblit v1.9.1