📄 waterctrl4-wdt.c
字号:
// 0x04 set1 1:Setting Card id OK
// 0x08 set1 1:will check velue is close?
// 0x10 set1 1:high 6v volt error
// 0x20 set1 1:PressureVal is too high
// 0x40 set1 1:PressureVal is too low
// 0x80 set1 1:system is stop use
unsigned char cntkeyerr;
// 0x01:
// 0x02:SIN1 SIN2 ALL ON
// 0x04:SIN1 ON TWO TIMES
// 0x08:
// 0x10:
// 0x20:SIN2 SIN1 ALL ON
// 0x40:SIN2 ON TWO TIMES
// 0x80:
unsigned char cntorder;
//0x01:1:sin1 is on
//0x02:1:sin2 is on
//0x04:
//
unsigned char GuHGERRCNT;
extern unsigned char systemtime[7]; //rtc time datatype sec,min,hour,day,week,mon,year
unsigned char systemtemp;
unsigned char systemtemp1;
unsigned char RtWrCdCNT;
unsigned int systemtempint1;
unsigned int timerscnt;
unsigned char timer3counter;
unsigned char timer3cntadj;
unsigned char wheelcnt1;
unsigned char WheelTimes;
unsigned char MtWkSeBRam;
unsigned char systemtemp;
unsigned int loopcnt;
unsigned char loopcnt2;
unsigned char usercardstateB;
//0x01: 1: lawless exit at this times befor 0:exit in gear at this times befor
//0x02:
//0x04:
//0x08:
//0x10:
//0x20:
//0x40:
//0x80:
unsigned int adresult; //meter current setting
//------------------------------------------------------------------------------//
unsigned char carderrorbyte;
//------------------- meter option error code ---------------------------//
// store in value of carderrorbyte
// 0x01 ---- options is Ok
// 0x00 ---- Find card is error
// 0x02 ---- Prevent conflict defeated
// 0x03 ---- Select card defeated
// 0x04 ---- mater is be using and download m1 crad key code defeated
// 0x05 ---- Read Which data of bank defested
// 0x06 ---- Which Bank data CS error
// 0x07 ---- start up card return write is error
// 0x08 ---- Card Software Password error
// 0x09 ---- mater is not be using and download m1 crad key code defeated
// 0x0a ---- Card hart password error
// 0x0b ---- count DanJia error
// 0x0c ---- One GuanHuanGuang error
// 0x0d ---- user card YuE error
// 0x0e ---- card momey < 1.0 yuan
// 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
// 0x32 ---- setting card data error
//----------------------------------------------------------------------------------//
//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; //
unsigned char YaLitemp[2];
unsigned char Volttemp;
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
//[36] 't' x 1 1 0 1 1 0 0 HEX:0x6c
//------------------------- ------------------ ----------------------------//
const unsigned char LcdNum[37]=
{
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,
0x6c
};
//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;
// }
//-------------------------------------Setting use water mode key on?
if(systemflag2&0x08)
{
KEYDOWNDS;
systemflag2 = systemflag2 & 0xf7; //clear flag
ADPWRON;
Endisplay();
ClearLcdMem();
Delay10KTCYx(255);
Delay10KTCYx(255);
ADTEST(1);
if(VoltageVal > 148 ) //< 5.9?
{
systemflag4 &= 0xfe;
if(VoltageVal > 164 )
{
DPY_3Pow_Flg();
}
if(VoltageVal > 150 )
{
DPY_2Pow_Flg();
}
DPY_1Pow_Flg();
}
else
{
DPY_0Pow_Flg();
DYP_Failure_Flg();
carderrorbyte = 0x2c;
DisplayErrCode(carderrorbyte);
systemflag4 |= 0x01;
Delay10KTCYx(255);
Delay10KTCYx(255);
goto checkerror1;
}
FM1702PWRON;
Delay10KTCYx(100);
InitialFM1702(0); //initialize FM1702
//----------------------------chcek card?
carderrorbyte = IsFindCard();
if(carderrorbyte != 0x01)
{
carderrorbyte = 0x00;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
BACKLEDON;
Endisplay();
ClearLcdMem();
DPY_Full_SigleLv_Flg();
DPY_CloseValve_Flg();
DPY_WaterWheelSt1();
//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);
READ_E2PROM(RevBuffer+23,Current6vBatVolt,2,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);
READ_E2PROM(RevBuffer+20,CurrentGuanYaLi,3,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;
}
// systemflag4 |= 0xfe; //set low power flag
//---------------------------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;
}
// //-------------------------------------------clear display
// 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();
ANALYSE_CARD ();
if(systemflag2 & 0x40)
{
systemflag |= 0xbf;
checkerror1:
systemflag3 |= 0x01; //will sleep
BACKLEDOFF; //open LED BACKLIGHT
FM1702PWROFF;
Dsdisplay(); //
continue;
}
//-------------------------------------------------------------------------------Setting or Open Valev loop
KEYDOWNEN;
KEYUPEN;
DPY_Card_YLorJE_Num(CardYE);
ClearNumDpy(1,1);
DPY_LJSLorRQ_Num(LieJSL,1);
DPY_SLorJE_Num(YongSL,0x00);
DPY_SLorJE_Num(YongJE,0x01);
DPY_SDZorDJ_Num(DanJ,0x00);
SheDSL[0] = 0x00; //2.5M3
SheDSL[1] = 0x25;
SheDSL[2] = 0x00;
systemtempint1 = 0;
loopcnt = 0;
loopcnt2 = 0;
while(1)
{
systemtempint1++;
if(systemtempint1==1000)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -