📄 waterctrlv3.c
字号:
// 0x0f ---- Card type error
// 0x20 ---- Card stop option
// 0x21 ---- User setting value erroe
// 0x22 ---- card been removed
// 0x23 ---- card setting dang jia error
// 0x24 ---- system startupcard checksum is error
// 0x25 ---- start useing mater is not ok
// 0x26 ---- read/write e2prom error
// 0x27 ---- soft card passwork error
// 0x28 ---- system serial is error
// 0x29 ---- stopcard bytes is error
// 0x2a ---- Stop mater option is error
// 0x2b ---- card no effect
// 0x2c ---- 6v battery voltage is low that 5.7v
// 0x2d ---- 6v battery voltage is High that 5.7v
// 0x2e ---- Guan Yu Li samll that Lowset value
// 0x2f ----- Guan Yu Li Dig that Highset value
// 0X30 ---- card is no money
// 0x31 ---- GuanHuangGuan disturb
//
//----------------------------------------------------------------------------------//
//aboat water value
//unit price from 00.00 to 99.99
//water count unit from 1000L to 10L
//
unsigned char DanJ[2]; //xx.xx yuan/m3
unsigned char DanJCnt[5]; //xx xx x.x xx xx yuan/m3
unsigned char YongSL[3]; //xx x.x xx m3
unsigned char YongJE[5]; //xx xx x.x xx xx yuan
unsigned char CardYE[5]; //xx xx x.x xx xx yuan
unsigned char SheDSL[3]; //0x x.x xx m3
unsigned char LieJSL[5]; //xx xx xx x.x xx m3
unsigned char PressureVal; //
unsigned char VoltageVal; //
const unsigned char OPnum1[5] = {0,0,0,0,2};
const unsigned char OPnum2[5] = {0,0,0,0,1};
#ifdef WATER_COUNT_UNIT_10L
const unsigned char OPnum3[3] = {0x0,0x0,0x05};
const unsigned char OPnum4[5] = {0x0,0x0,0x0,0x0,0x05};
#endif
#ifdef WATER_COUNT_UNIT_100L
const unsigned char OPnum3[3] = {0x0,0x0,0x50};
const unsigned char OPnum4[5] = {0x0,0x0,0x0,0x00,0x50};
#endif
#ifdef WATER_COUNT_UNIT_1000L
const unsigned char OPnum3[3] = {0x0,0x05,0x0};
const unsigned char OPnum4[5] = {0x0,0x0,0x0,0x05,0x0};
#endif
const unsigned char voltAD[26]={128,130,132,134,136,138,140,143,146,148,150,153,157,159,162,164,166,168,171,174,177,179,182,185,187,190};
//------------------------- LCD Number type Tab ----------------------------//
//LcdNum[X]= B( x x x x x x x x )
// d3 d2 d1 d0 d3 d2 d1 d0
// ---HighAddr-- ---LowAddr---
//[0] '0': x 1 1 1 0 1 1 1 HEX: 0x77
//[1] '1': x 0 0 1 0 0 1 0 HEX: 0x12
//[2] '2': x 1 1 0 1 0 1 1 HEX: 0x6b
//[3] '3': x 1 0 1 1 0 1 1 HEX: 0x5b
//[4] '4': x 0 0 1 1 1 1 0 HEX: 0x1e
//[5] '5': x 1 0 1 1 1 0 1 HEX: 0x5d
//[6] '6': x 1 1 1 1 1 0 1 HEX: 0x7d
//[7] '7': x 0 0 1 0 0 1 1 HEX: 0x13
//[8] '8': x 1 1 1 1 1 1 1 HEX: 0x7f
//[9] '9': x 1 0 1 1 1 1 1 HEX: 0x5f
//[10] 'A': x 0 1 1 1 1 1 1 HEX: 0x3f
//[11] 'b': x 1 1 1 1 1 0 0 HEX: 0x7c
//[12] 'c': x 1 1 0 1 0 0 0 HEX: 0x68
//[13] 'd': x 1 1 1 1 0 1 0 HEX: 0x7a
//[14] 'E': x 1 1 0 1 1 0 1 HEX: 0x6d
//[15] 'F': x 0 1 0 1 1 0 1 HEX: 0x2d
//[16] 'G': x
//[17] 'h': x 0 1 1 1 1 0 0 HEX: 0x3c
//[18] 'o': x 1 1 1 1 0 0 0 HEX: 0x78
//[19] '-': x 0 0 0 1 0 0 0 HEX: 0x08
//[20] '_': x 1 0 0 0 0 0 0 HEX: 0x60
//[21] ' ': x 0 0 0 0 0 0 0 HEX: 0x00 //on display
//[22] 'a' x 1 1 1 1 0 1 1 HEX: 0x7b
//[23] 'C' x 0 0 1 1 1 0 1 HEX: 0x65
//[24] 'r' x 0 1 0 0 1 0 1 HEX: 0x25
//[25] 'V' x 1 1 1 0 1 1 0 HEX: 0x76
//[26] 'n' x 0 1 1 1 0 0 0 HEX: 0x28
//[27] ''
//[28] ''
//
//[31] 'T' x 0 1 0 0 1 0 1 HEX:0x25
//[32] 'P' x 0 1 0 1 1 1 1 HEX:0x2f
//[33] 'L' x 1 1 0 0 1 0 0 HEX:0x64
//[34] 'I' x 0 1 0 0 1 0 0 HEX:0x24
//[35] 'Y' x 1 0 1 1 1 1 0 HEX:0x5e
//------------------------- ------------------ ----------------------------//
const unsigned char LcdNum[36]=
{
0x77,0x12,0x6b,0x5b,0x1e,0x5d,
0x7d,0x13,0x7f,0x5f,0x3f,0x7c,
0x68,0x7a,0x6d,0x2d,0x00,0x3c,
0x78,0x08,0x60,0x00,0x7b,0x65,
0x25,0x76,0x38,0x28,0x18,0x70,
0x76,0x25,0x2f,0x64,0x24,0x5e
};
//Number type:('0'-'1'-'2'-'3'-'4'-'5'-'6'-'7'-'8'-'9'-'A'-'b'-'c'-'d'-'E'-'F'-'G'-'h'-'o'-'-'-'_'-' ')
const struct LcdNumArea
{
unsigned char LowAdr;
unsigned char HighAdr;
}NumNum[40] = { {0,1} ,{2,3} ,{4,5} ,{6,7} ,{8,9} ,{10,11},{12,13},{14,15},{16,17},{18,19},
{20,21},{22,23},{24,25},{26,27},{28,29},{30,31},{32,33},{34,35},{36,37},{38,39},
{40,41},{42,43},{44,45},{46,47},{48,49},{50,51},{52,53},{54,55},{56,57},{58,59},
{60,61},{62,63},{64,65},{66,67},{68,69},{70,71},{72,73},{74,75},{76,77},{78,79}
};
//This struck is statement the each Display-Number on LCD that what`s address at HT1623 Memory Map
//Use NumNum[?].HighAdr/NumNum[?].LowAdr
//********************************* Main ***********************************//
void main(void)
{
InitializeSystem();
#ifdef _CLRE2_
//clear E2prom
systemtemp = 0xff;
for(systemtempint1=0;systemtempint1<4096;systemtempint1++)
{
WRITE_1_BYTE_E2PROM(&systemtemp,systemtempint1,0);
}
#endif
while(1)
{
ReadTime(systemtime);
//-------------------------------------recevice whole frame from Infrared?
if(systemflag&0x80)
{
systemflag &= 0x7f;
}
//-------------------------------------recevice whole frame from GSM?
if(systemflag&0x40)
{
systemflag &= 0xbf;
}
//-------------------------------------fault precaution close velue
if(systemflag3&0x02)
{
systemflag3 &= 0xfd;
}
//-------------------------------------Directness use water key on
if(systemflag2&0x08)
{
systemflag2 = systemflag2 & 0xf7;
systemflag2 = systemflag2 & 0x7f; //Clear setting use water mode flag
goto startreadcard;
}
//-------------------------------------Setting use water mode key on?
if(systemflag2&0x01)
{
systemflag2 = systemflag2 & 0xfe; //clear flag
systemflag2 = systemflag2 | 0x80; //Set setting use water mode flag
KEYUPDS;
KEYDOWNDS;
startreadcard:
FM1702PWRON;
InitLcdDpy()
// ---------------------------------------------------------------test 6v power and display
ADTEST(3); //test PressureVal
ADTEST(1); //test 6v volt
//fine romtable to get 6V volt number
systemtemp1 = 50;
for(systemtemp=0;systemtemp<25;systemtemp++)
{
RevBuffer[0] = voltAD[systemtemp];
RevBuffer[1] = voltAD[systemtemp+1];
if((RevBuffer[0] <=VoltageVal)&&( VoltageVal<RevBuffer[1]))
{
systemtemp = (&(voltAD[systemtemp])-&(voltAD[0]));
systemtemp1 = systemtemp1+systemtemp;
break;
}
}
systemtemp = systemtemp1;
// VoltageVal HEX to BCD
systemtemp1 = 0;
while(systemtemp>=10)
{
systemtemp -= 10;
systemtemp1+=1;
}
systemtemp1 = systemtemp1<<4;
YongSL[1] =systemtemp1+systemtemp ;
// write to e2paom
WRITE_1_BYTE_E2PROM(&VoltageVal,Current6vBatVolt,0);
WRITE_1_BYTE_E2PROM(YongSL+1,Current6vBatVolt+1,0);
// VoltageVal BCD display to LCD
DPY_SLorJE_Num(YongSL,0);
UnDPY_SL_Area();
OneLcdFlagSET(21);
Wr1BCDNumToLcd(0 , 12);
Wr1BCDNumToLcd(25 , 13);
OneLcdFlagSET(67);
//get PressureVal number
systemtemp = PressureVal;
systemtemp = systemtemp>>3; //systemtemp/8 = x/10 Kg
systemtemp1 = PressureVal - (systemtemp<<3);
for(YongJE[0]=0;YongJE[0]<10;YongJE[0]++)
{
YongJE[1] = systemtemp1+YongJE[1];
}
systemtemp1 = YongJE[1]>>3; //systemtemp1/8 = x/100 Kg
YongJE[0] = 0;
YongJE[1] = 0;
YongJE[2] = 0;
YongJE[3] = systemtemp1<<4;
while(systemtemp>9)
{
systemtemp -= 10;
YongJE[2] += 0x10;
}
YongJE[2] += systemtemp;
//WRITE to E2PROM
WRITE_1_BYTE_E2PROM(&PressureVal,CurrentGuanYaLi,0);
WRITE_E2PROM(YongJE+2,CurrentGuanYaLi+1,2,0);
//----------------------------------------display PressureVal
DPY_SLorJE_Num(YongJE,1);
UnDPY_JE_Area();
OneLcdFlagSET(63);
Wr1BCDNumToLcd(21 , 34);
Wr1BCDNumToLcd(32 , 34);
YongJE[2] = 0;
YongJE[3] = 0;
//dispaly 6V voltage level
if(VoltageVal<138) // Volt < 5.6V
{
systemflag4 |= 0x01; //set low power flag
DPY_0Pow_Flg();
carderrorbyte = 0x2c;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
else if(VoltageVal<157) //5.5v~6.0v
{
DPY_1Pow_Flg();
}
else if(VoltageVal<166) //6.0v~6.5v
{
DPY_2Pow_Flg();
}
else if(VoltageVal<190) //6.5~7.5
{
DPY_3Pow_Flg();
}
else //high volt error // Volt > 7.5V
{
systemflag4 |= 0x10; //set
carderrorbyte = 0x2d;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
//---------------------------Is PressureVal Error?
if(PressureVal<LOWPressureVal )
{
systemflag4 |= 0x40;
carderrorbyte = 0x2e;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
if(PressureVal>HIGHPressureVal )
{
systemflag4 |= 0x20;
carderrorbyte = 0x2f;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
FM1702PWRON;
Delay10KTCYx(255);
Delay10KTCYx(100);
//-------------------------------------------clear display
BACKLEDON; //open LED BACKLIGHT
Wr1BCDNumToLcd(21 , 8);
Wr1BCDNumToLcd(21 , 9);
Wr1BCDNumToLcd(21 , 10);
Wr1BCDNumToLcd(21 , 11);
Wr1BCDNumToLcd(21 , 12);
Wr1BCDNumToLcd(21 , 13);
Wr1BCDNumToLcd(21 , 29);
Wr1BCDNumToLcd(21 , 30);
Wr1BCDNumToLcd(21 , 31);
Wr1BCDNumToLcd(21 , 32);
Wr1BCDNumToLcd(21 , 33);
Wr1BCDNumToLcd(21 , 34);
UnDPY_SL_Area();
UnDPY_JE_Area();
InitialFM1702(0); //initialize FM1702
//----------------------------chcek card?
carderrorbyte = IsFindCard();
if(carderrorbyte != 0x01)
{
FM1702PWROFF;
systemflag4 |= 0x08;
KEYUPEN;
KEYDOWNEN;
break;
}
//-------------------------------------------------------------------------------END
InitLcdDpy(); //initialize HT1623
ANALYSE_CARD ();
if(systemflag2 & 0x40)
{
systemflag |= 0xbf;
break;
}
//--------------------------------------------
if(0)
{
checkerror1:
systemflag4 |= 0x80; //system stop
systemflag3 |= 0x01; //will sleep
BACKLEDOFF; //open LED BACKLIGHT
FM1702PWROFF;
Dsdisplay(); //
KEYUPEN;
KEYDOWNEN;
break;
}
systemflag &= 0xf7;
DPY_LJSLorRQ_Num(LieJSL,1);
DPY_Card_YLorJE_Num(CardYE,0x00);
DPY_SDZorDJ_Num(DanJ,0x00);
DPY_SLorJE_Num(YongSL,0x00); //display ShuiLiang
DPY_SLorJE_Num(YongJE,0x01); //display JinE
ReflashLcdTimeDpy(1);
KEYUPEN;
KEYDOWNEN; //Setting use water mode
KEYSELDS;
KEYONOFFDS;
if(systemflag2 & 0x80)
{
LcdWheelDisplay();
}
else //directness use water mode
{
SheDSL[0] = 0x00; //10M3
SheDSL[1] = 0x25;
SheDSL[2] = 0x00;
}
KEYUPDS;
KEYSELDS;
KEYONOFFDS;
KEYDOWNDS;
//she ding liang is 0?
if(SheDSL[0] == 0)
if(SheDSL[1] == 0)
if(SheDSL[2]<0x50)
{
goto checkerror1;
}
for(systemtemp=0;systemtemp<10;systemtemp++) //dec 50L
{
AddUsingValueOp();
//BCDBytesSub(CardYE,DanJCnt,5); //
}
systemtemp = CntReturnWr();
if(systemtemp != 0x01)
{
carderrorbyte = 0x22;
goto stopusewater;
}
ReflhDisplayVal();
DYP_OpenValve_Flg();
OPVEL;
systemflag4 |= 0x02;
SIN1INTEN;
SIN2INTEN;
OPOUT1;
OPOUT2;
carderrorbyte = 1;
systemflag2 &= 0xf0;
countWTRCNT = 0;
cntkeyerr = 0;
cntorder = 0;
systemtemp = 0;
while(VELSTACLIN)
{
if(countWTRCNT> 0)
{
countWTRCNT -= 1;
AddUsingValueOp();
WaterWheelStChg();
ClearNumDpy(4,4); //
DPY_LJSLorRQ_Num(LieJSL,1);
ReflhDisplayVal();
}
ReflashLcdTimeDpy(0);
}
RSTVEL;
systemflag &= 0xfd;
KEYDOWNEN;
loopcnt = 0;
//---------------------------------this loop is aboat count value of uesing water
while(1)
{
loopcnt += 1;
//-------------------------------------
DSGIE;
if(SheDSL[0]<=YongSL[0]) //setting water is over
{
if(SheDSL[1]<=YongSL[1])
{
if(SheDSL[2]<=YongSL[2])
{
// systemflag2 |= 0x20;
goto stopusewater;
}
}
}
//-------------------------------------Card Eu E emtpy
if(CardYE[0]==0)
{
if(CardYE[1]==0)
{
if(CardYE[2]==0)
{
carderrorbyte = 0x30;
CdBnk5Grp[14] |=0x02;
goto stopusewater;
}
}
}
ENGIE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -