📄 com1process.c
字号:
#define COM1_GLOBALS
#include "Macro.h"
#include "Main.h"
#define M_DELAY 100
#define A_DELAY 40
void Port1Process(void)
{
struct Serial_rcv xdata *Com;
static unsigned char xdata tmpBuff[256];
static unsigned int xdata RcvingTimer;
static unsigned char xdata sndCnt;
static unsigned char xdata hwInit = 0;
static unsigned char xdata CmdPtr;
unsigned int xdata iTmp;
unsigned char cTmp;
unsigned char xdata *mPtr;
if (!hwInit) {
mPtr = tmpBuff;
for ( iTmp=0; iTmp<sizeof(tmpBuff); iTmp++ ) *(mPtr++) =0;
Port1Data[0] = 0;
Port1Data[1] = 0;
CmdPtr = 1;
hwInit = 1;
}
if (Port1Timer > 36000) Port1Timer = 36000;
if ( (Port1Data[0] != 0) || (Port1Data[1] != 0) ) return;
Com = Rcv + 1;
while ( Com->Tail != Com->Head ) {
cTmp = Com->Data[Com->Head++];
Com->Head = Com->Head % sizeof(Com->Data);
Com->Buff[Com->pos++] = cTmp;
Com->pos = Com->pos % sizeof(Com->Buff);
RcvingTimer = Port1Timer; // 10 * 100ms
sndCnt = 0;
continue;
}
if ( (Port1Timer - RcvingTimer) > 10 ) { // 10 * 100ms
// receive data is over
Port1Data[0] = Com->pos % 256;
Port1Data[1] = (Com->pos / 256) & 0xff;
memcpy(&Port1Data[2], Com->Buff, Com->pos);
Com->pos = 0;
}
if ( (Port1Data[0] != 0) || (Port1Data[1] != 0) )return;
//
if (Port1Timer > A_DELAY) { // * 100ms
if (CmdPtr == 0) {
if (Port1Timer < M_DELAY) return;
}
Port1Timer = 0;
sndCnt++;
if (Port1Cmd[0]==0) return;
CmdPtr = CmdPtr % Port1Cmd[0];
if ( sndCnt == 1) {
CmdPtr += 1;
CmdPtr = CmdPtr % Port1Cmd[0];
}
iTmp = CmdPtr * LENCMD + 1;
if (Port1Cmd[iTmp]==0) return;
Send_To_Port_Buffer(1, &Port1Cmd[iTmp + 1], Port1Cmd[iTmp]);
SendStart(1);
Com->pos = 0;
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -