📄 untitled.c
字号:
// 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 ----
// 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
//----------------------------------------------------------------------------------//
//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
//------------------------- ------------------ ----------------------------//
const unsigned char LcdNum[33]=
{
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
};
//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;
CloseValve();
}
//-------------------------------------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
startreadcard:
FM1702PWRON;
Delay10KTCYx(255);
InitialFM1702(0); //initialize FM1702
//----------------------------chcek card?
carderrorbyte = IsFindCard();
if(carderrorbyte != 0x01)
{
FM1702PWROFF;
systemflag3 |= 0x01;
break;
}
Endisplay(); //enaible HT1623 work
ClearLcdMem(); //clear LCD display
// ---------------------------------------------------------------test 6v power and display
ADTEST(1); //test 6v volt
ADTEST(3); //test PressureVal
//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<146) // Volt < 5.7V
{
systemflag4 |= 0x01; //set low power flag
DPY_0Pow_Flg();
carderrorbyte = 0x2c;
DisplayErrCode(carderrorbyte);
Delay10KTCYx(255);
goto checkerror1;
}
else if(VoltageVal<157) //6.2v~5.7v
{
DPY_1Pow_Flg();
}
else if(VoltageVal<166) //6.2v~6.7v
{
DPY_2Pow_Flg();
}
else if(VoltageVal<190) //6.7~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;
}
Delay10KTCYx(255);
Delay10KTCYx(255);
Delay10KTCYx(255);
//-------------------------------------------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();
//-------------------------------------------------------------------------------END
InitLcdDpy(); //initialize HT1623
ANALYSE_CARD ();
//--------------------------------------------
if(0)
{
checkerror1:
systemflag4 |= 0x80; //system stop
systemflag3 |= 0x01; //will sleep
BACKLEDOFF; //open LED BACKLIGHT
FM1702PWROFF;
Dsdisplay(); //
}
}
//-------------------------------------read user card ok that into uesr setting function
if(systemflag & 0x08)
{
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
DPY_Time();
Delay10KTCYx(100);
DPY_Time();
Delay10KTCYx(100);
DPY_Time();
Delay10KTCYx(100);
DPY_Time();
Delay10KTCYx(100);
DPY_Time();
AddUsingValueOp(); //DEC 1 Unit
if(systemflag2 & 0x80)
{ //Setting use water mode
LcdWheelDisplay();
}
else //directness use water mode
{
SheDSL[0] = 0x01; //10M3
SheDSL[1] = 0x00;
SheDSL[2] = 0x00;
goto cardwillcheckcardmove;
}
}
//-------------------------------------begin use water
if(systemflag&0x04)
{
systemflag &= 0xfb;
cardwillcheckcardmove:
OPOUT1;
OPOUT2;
OpenValve();
loopcnt = 0;
systemtemp = 0;
systemflag2 &= 0xf0;
//---------------------------------this loop is aboat count value of uesing water
while(1)
{
loopcnt += 1;
//-------------------------------------have on water ?
if(YongSL[0]==SheDSL[0]) //setting water is over
if(YongSL[1]==SheDSL[1])
if(YongSL[2]==SheDSL[2])
{
systemflag2 |= 0x20;
CLOUT1;
CLOUT2;
}
//-------------------------------------
systemtempint1 = loopcnt & 0x1fff;
if(systemtempint1 == 0x01fff)
{
carderrorbyte=CheckCardIsMove();
if(carderrorbyte!=0x01) //card been remove
{
CLOUT1;
CLOUT2;
timerscnt = 0;
systemflag2 |= 0x10;
carderrorbyte =0x22;
}
}
if(loopcnt==29000)
{
timerscnt += 1;
loopcnt=0;
ReflashLcdTimeDpy(1);
}
if(timerscnt==10)
{
timerscnt+=1;
if(systemflag2&0x80)
{
ClearNumDpy(1,1); //display SheDinLiang
DPY_SDZorDJ_Num(SheDSL,0x01);
}
ClearNumDpy(4,4);
DPY_LJSLorRQ_Num(LieJSL,1); //display LieJiLiang
systemflag4 |= 0x01;
}
if(timerscnt>22)
{
timerscnt=0;
ClearNumDpy(1,1); //display DJ
DPY_SDZorDJ_Num(DanJ,0x00);
ClearNumDpy(4,4);
DPY_LJSLorRQ_Num(systemtime,0) ; //display date
systemflag4 &= 0xfe;
}
//-------------------------user use water stop not in geal
if(systemflag2&0x10)
{
systemflag2 &=0xef;
CLOUT1;
CLOUT2;
SIN1INTEN;
SIN2INTEN;
CLR_INT0F;
CLR_INT1F;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -