?? host.c
字號:
break;
default:
//KeyFuncIndex = 30;//默認顯示電流
//DisplayCurrent();
return;
}
rst_wdog();
KeyFuncPtr = KeyTab[KeyFuncIndex].CurrentOperate;
(*KeyFuncPtr)(); //執行
}
return;
}
void GetParamsCode(uchar *pChar, uchar begin, word wData) reentrant //段碼、顯示片選起點、參數
{
uchar i;
if (wData > 0)
{
for (i=4; i>=begin; i--)
{
pChar[i] = uLEDChar[wData % 10];
wData = wData / 10;
rst_wdog();
}
if (Param.PointPos < 5)
pChar[Param.PointPos] |= 0x40;
}
}
void Hints(uchar *pChar) reentrant
{
byte i;
TRG = 1;
TRG = 0;
I_Send('T');
Delay(1, 5);
for (i=0; i<5; i++)
{
I_Send(pChar[4-i]);
rst_wdog();
}
return;
}
//顯示測量數據
void DisplayCurrent()
{
uchar i;
dword dwCurrent;
dword Count;
word wOutput, wALR_L, wALR_H;
Count = GetCount();
//計算
wOutput = Param.wOutput.w;
wALR_L = Param.wALR_L.w;
wALR_H = Param.wALR_H.w;
for (i=0; i<4-Param.PointPos; i++)
{
wOutput /= 10;
wALR_L /= 10;
wALR_H /= 10;
rst_wdog();
}
//計算轉換量
if (Count >= Param.wZero.dw)
dwCurrent = (Count - Param.wZero.dw) * wOutput * 100 / (Param.wInCount.dw - Param.wZero.dw);
Param.Current.w = dwCurrent / 10;
if ((dwCurrent % 10) > 4) //四舍五入
Param.Current.w ++ ;
rst_wdog();
//報警
if (Param.bAlert)
{
if (Param.Current.w < wALR_L * 10) //低報警
JDQL = 0;
if (Param.Current.w > wALR_L * 12) //低報警回滯
JDQL = 1;
if (Param.Current.w > wALR_H * 10) //高報警
JDQH = 0;
if (Param.Current.w < wALR_H * 8) //高報警回滯
JDQH = 1;
rst_wdog();
}
//顯示
Display(Param.Current.w, 3);
//Display(Count, 5);
return;
}
uchar GetKeyValue(word *pValue, word Data, uchar uNum) reentrant
{
uchar KeyValue, i;
uchar CodeIndex[4] = {0, 0, 0 ,0}; //段碼下標,依次對應片1, 2, 3, 4
uchar uSelIndex = 4; //片選下標
word Value = 0;
//換算得到當前值的下標
for (i=0; i<uNum; i++)
{
CodeIndex[3-i] = Data % 10 + 1;
Data = Data / 10;
rst_wdog();
}
while (1)
{
KeyValue = P2 & 0xF0; //去掉低4位
if (KeyValue != 0xF0)
{
Delay(10, 500);
KeyValue = P2 & 0xF0;
switch (KeyValue)
{
case 0xE0: //左鍵, 翻數字
TRG = 1;
TRG = 0;
I_Send('S');
Delay(1, 5);
I_Send(uSelIndex);
I_Send(uLEDChar[CodeIndex[uSelIndex - 1]++]);
CodeIndex[uSelIndex - 1] = CodeIndex[uSelIndex - 1] % 10;
break;
case 0xD0: //右鍵, 翻片子
uSelIndex ++;
if (uSelIndex > 4)
uSelIndex = 5 - uNum;
TRG = 1;
TRG = 0;
I_Send('S');
Delay(1, 5);
I_Send(uSelIndex + 4);
break;
case 0xB0: //MENU,取消操作
TRG = 1; //停止閃爍
TRG = 0;
I_Send('N');
return 0xB0;
case 0x70: //回車,確認操作
TRG = 1; //靜止顯示
TRG = 0;
I_Send('A');
//計算數據
for (i=4-uNum; i<4; i++)
Value = Value * 10 + CodeIndex[i] - 1;
*pValue = Value;
changed = 1;
Delay(50, 1000);
TRG = 1; //停止閃爍
TRG = 0;
I_Send('N');
return 0x70;
default:
break;
}
}
rst_wdog();
}
return 0x70;
}
void KeyResult(uchar uKey, uchar uMenu, uchar uEnter, word Value) reentrant
{
dword wInCount;
uchar uKeyValue;
if (uKey == 0xB0) //MENU,取消操作
{
rst_wdog();
KeyFuncIndex = uMenu; //跳到上一層
KeyFuncPtr = KeyTab[KeyFuncIndex].CurrentOperate;
(*KeyFuncPtr)(); //執行
}
if (uKey == 0x70) //回車,確認操作
{
if (uEnter == 7)
{
//計算輸入值并保存
Param.wInput.w = Value;
wInCount = GetCount();
if (wInCount < 14158) //小于標稱值20%
{
Hints(In_LHint);
return;
}
if (wInCount > 21236) //大于標稱值20%
{
Hints(In_HHint);
return;
}
Param.wInCount.dw = wInCount;
Param.bAlert = 0; //關閉報警
JDQL = 1;
JDQH = 1;
rst_wdog();
}
if (uEnter == 26)
{
Param.wOutput.w = Value;
Param.bAlert = 0; //關閉報警
JDQL = 1;
JDQH = 1;
rst_wdog();
}
if (uEnter == 23)
{
Param.wALR_L.w = Value;
rst_wdog();
}
if (uEnter == 22)
{
if (Value <= Param.wOutput.w)
Param.wALR_H.w = Value;
else
Param.wALR_H.w = Param.wOutput.w;
rst_wdog();
}
if (uEnter == 19)
{
if (Value <256)
Param.bAddress = Value;
rst_wdog();
}
if (uEnter == 4)
{
if ((Param.Password.w == Value) || (Value == 0)) //密碼核對
{
uKeyValue = GetKeyValue(&Value, Value, 4);
if (uKeyValue == 0x70)
{
if (Value != 0)
{
Param.Password.w = Value; //設置密碼
rst_wdog();
}
}
}
else
{
Hints(ErrorHint);
Delay(30, 1000);
}
}
changed = 1;
KeyFuncIndex = uEnter; //跳到...
KeyFuncPtr = KeyTab[KeyFuncIndex].CurrentOperate;
(*KeyFuncPtr)(); //執行
}
return;
}
//測量BUSY的量(查詢方式)
dword GetCount ()
{
uchar i = 5;
dword Counts[5], AddCount = 0;
WordType Count; //記數值
TMOD = 0x01; //定時器
while (i--)
{
TL0 = 0;
TH0 = 0; //初始化
while (!BUSY);
//開計數器
TR0 = 1;
while (BUSY);
TR0 = 0; //關閉計數器
Count.b[1] = TL0;
Count.b[0] = TH0;
if (Count.w >= 24651)
Counts[i] = Count.w - 24651;
else
i++;
rst_wdog();
}
for(i=0; i<5; i++)
{
AddCount += Counts[i];
rst_wdog();
}
AddCount = AddCount / 10;
return AddCount;
}
void OptionProg() reentrant
{
if (changed && !flag)
{
//提示保存
Hints(SaveHint);
while (1)
{
uchar KeyValue;
KeyValue = P2 & 0xF0; //去掉低4位
if (KeyValue != 0xF0)
{
Delay(10, 500);
KeyValue = P2 & 0xF0;
while ((P2 & 0xF0) != 0xF0)
rst_wdog();
if (KeyValue == 0xB0) //MENU
{
//恢復參數,讀芯片
ReadParams(); //讀參數
SetTimer(Param.BaudIndex);
break;
}
if (KeyValue == 0x70) //回車
{
uchar uKey, i;
word Value;
word Passward = 0;
for (i=0; i<3; i++)
{
//要求輸入密碼
Hints(PwdHint);
uKey = GetKeyValue(&Value, Passward, 4);
if (uKey == 0x70)
{
if ((Value == Param.Password.w) || (Value == 0)) //比較密碼
{
WriteParams(); //保存參數,寫芯片
i = 3;
}
}
else break;
rst_wdog();
}
break;
}
}
rst_wdog();
}
changed = 0;
}
Hints(ProgHint); //顯示提示
return;
}
void OptionAYS() reentrant
{
Hints(A_YSHint); //顯示提示
return;
}
void OptionIn_Out() reentrant
{
Hints(In_OuHint); //顯示提示
return;
}
void OptionALR() reentrant
{
Hints(ALRHint); //顯示提示
return;
}
void OptionSecr() reentrant
{
Hints(SecrHint); //顯示提示
return;
}
void OptionAdBd() reentrant
{
Hints(Ad_BdHint); //顯示提示
return;
}
//顯示零點
void AutoZero() reentrant
{
Param.wZero.dw = GetCount(); //得到零
Display(Param.wZero.w[1], 5);
changed = 1;
/*
Delay(25, 1000);
TRG = 1; //閃爍顯示
TRG = 0;
I_Send('A');
Delay(25, 1000);
TRG = 1; //靜止顯示
TRG = 0;
I_Send('N');
*/
return;
}
void InputX() reentrant //顯示輸入值
{
byte Input[] = {0x06, 0x00, 0x00, 0xB6, 0xB6};
GetParamsCode(Input, 3, Param.wInput.w);
Input[Param.PointPos] &= 0xBF;
Hints(Input); //顯示提示
return;
}
void OutputX() reentrant //顯示輸出值
{
byte Output[] = {0x9B, 0xB6, 0xB6, 0xB6, 0xB6};
GetParamsCode(Output, 1, Param.wOutput.w);
Hints(Output); //顯示提示
return;
}
void ALROFF() reentrant //關閉報警
{
Hints(OFFHint); //顯示OFF
Param.bAlert = 0;
changed = 1;
return;
}
void ALRON() reentrant //啟動報警
{
Hints(ONHint); //顯示ON
Param.bAlert = 1;
return;
}
void Passward() reentrant //顯示密碼輸入界面
{
uchar uKeyValue;
word Value;
word Passward = 0;
Hints(PwdHint);
uKeyValue = GetKeyValue(&Value, Passward, 4);
KeyResult(uKeyValue, 4, 4, Value);
return;
}
void AddrX() reentrant //顯示當前地址
{
byte AddrFace[] = {0xB7, 0x9E, 0xB6, 0xB6, 0xB6};
GetParamsCode(AddrFace, 2, Param.bAddress);
AddrFace[Param.PointPos] &= 0xBF;
Hints(AddrFace); //顯示當前地址
return;
}
void BaudX() reentrant //顯示當前波特率
{
Hints(Bauds[Param.BaudIndex]); //顯示當前波特率
return;
}
void Inp() reentrant //顯示INP
{
Hints(INPHint); //顯示INP
return;
}
void Oup() reentrant //顯示OUP
{
Hints(OUPHint); //顯示OUP
return;
}
void Point() reentrant //提示小數點輸入
{
Hints(PoInHint);
return;
}
void SetInput() reentrant //設置輸入值
{
uchar uKey;
word Value;
word wInput = Param.wInput.w;
InputX(); //顯示當前值
uKey = GetKeyValue(&Value, wInput, 2);
KeyResult(uKey, 14, 7, Value);
return;
}
void SetOutput() reentrant
{
word Value;
uchar uKey;
word wOutput = Param.wOutput.w;
OutputX(); //顯示當前值
uKey = GetKeyValue(&Value, wOutput, 4);
KeyResult(uKey, 15, 26, Value);
return;
}
void SetPoint() reentrant //設置小數點
{
uchar KeyValue;
uint Div = 1;
uchar uSelIndex = Param.PointPos; //片選下標
OutputX(); //顯示當前值
while (1)
{
KeyValue = P2 & 0xF0; //去掉低4位
if (KeyValue != 0xF0)
{
Delay(15, 500);
KeyValue = P2 & 0xF0;
switch (KeyValue)
{
case 0xE0: //左鍵, 左翻片子
uSelIndex --;
if (uSelIndex < 1)
uSelIndex = 4;
TRG = 1;
TRG = 0;
I_Send('P');
Delay(1, 5);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -