📄 waterctrlv2.c
字号:
//[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] ''
//------------------------- ------------------ ----------------------------//
const unsigned char LcdNum[31]=
{
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
};
//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();
while(1)
{
//-------------------------------------Reflash time and data
ReflashLcdTimeDpy();
//-------------------------------------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 Directness use water mode flag
startreadcard:
HQCPWRCTRLOUT = 1; //FM1702 power on
InitLcdDpy(); //initialize HT1623
InitialFM1702(0); //initialize FM1702
ANALYSE_CARD ();
}
//-------------------------------------read user card ok that into uesr setting function
if(systemflag & 0x08)
{
systemflag &= 0xf7;
GetHalfDJ();
switch(MtWkSeBRam&0x30) //Select Use water unit
{
case 0x00:panma = 0; break;
case 0x10:panma = 1; break;
case 0x20:panma = 2; break;
case 0x30:panma = 3; break;
}
if(usercardstateB&0x01) //lawless exit at this times befor
{
AddUsingValueOp(panma);
}
usercardstateB&=0x01; //fisrt must set 1
if(MtWkSeBRam&0x40) //the value in the card what`s mean that water m3 or CardBalance
{
DPY_Card_YLorJE_Num(CardBalance,0x00);
}
else
{
DPY_Card_YLorJE_Num(ShenYuShuiLiang,0x01);
}
DPY_SDZorDJ_Num(Settingprice,0x00);
DPY_SLorJE_Num(ShuiLiang,0x00); //display ShuiLiang
DPY_SLorJE_Num(JinE,0x01); //display JinE
if(systemflag2 & 0x80)
{ //Setting use water mode
LcdWheelDisplay();
}
else //directness use water mode
{
goto cardwillcheckcardmove;
}
}
//-------------------------------------begin use water
if(systemflag&0x04)
{
systemflag &= 0xfb;
cardwillcheckcardmove:
DSGIE;
usercardstateB |= 0x01;
CntReturnWr();
ENGIE;
if(carderrorbyte=0x01)
{
OpenValve();
}
else
{
systemflag2 |= 0x10; // : )
}
//deduct 1 unit water of card vaule
loopcnt = 0;
systemtemp = 0;
//---------------------------------this loop is aboat count value of uesing water
while(1)
{
loopcnt += 1;
if(loopcnt==10000)
{
carderrorbyte=CheckCardIsMove();
if(carderrorbyte!=0x01) //card been remove
{
timerscnt = 0;
systemflag2 |= 0x10;
carderrorbyte =0x22;
}
}
if(loopcnt==30000)
{
timerscnt += 1;
loopcnt=0;
ReflashLcdTimeDpy();
}
if(timerscnt==10)
{
timerscnt+=1;
if(systemflag2&0x80) //setting use water mode or directness use water mode?
{
ClearNumDpy(1,1); //display SheDinLiang
DPY_SDZorDJ_Num(SheDinLiang,0x01);
// ClearNumDpy(0,0);
// DPY_Card_YLorJE_Num(ShenYuShuiLiang,1);
}
}
if(timerscnt>22)
{
timerscnt=0;
ClearNumDpy(1,1); //display DJ
DPY_SDZorDJ_Num(Settingprice,0x00);
// ClearNumDpy(0,0);
// DPY_Card_YLorJE_Num(CardBalance,0);
}
//-------------------------user use water stop not in geal
if(systemflag2&0x10)
{
systemflag &=0xef;
HQCPWRCTRLOUT = 0;
CloseValve();
DPY_CloseValve_Flg();
RevBuffer[19]=6;
UnDYP_CardOn_Flg();
for(RevBuffer[19];RevBuffer[19]>0;RevBuffer[19]--)
{
// ClearNumDpy(0,0);
if(systemflag2&0x80) //setting mode or directness mode
{
ClearNumDpy(1,1);
ClearNumDpy(2,2);
Delay10KTCYx(0);// 0.16s
// DPY_Card_YLorJE_Num(CardBalance,0);
DPY_SLorJE_Num(ShuiLiang,0);
DPY_SDZorDJ_Num(SheDinLiang,1);
Delay10KTCYx(0);// 0.16s
}
else
{
Delay10KTCYx(0);// 0.16s
Delay10KTCYx(0);// 0.16s
}
}
DYP_Failure_Flg();
ClearNumDpy(1,1);
DisplayErrCode(carderrorbyte);
ClearNumDpy(0,0);
Wr1BCDNumToLcd(23,1); //C
Wr1BCDNumToLcd(22,2); //a
Wr1BCDNumToLcd(24,3); //r
Wr1BCDNumToLcd(13,4); //d
Wr1BCDNumToLcd(19,5); //-
Wr1BCDNumToLcd(18,6); //o
Wr1BCDNumToLcd(29,7); //u
Wr1BCDNumToLcd(28,8); //t
Delay10KTCYx(0);
Delay10KTCYx(0);
Delay10KTCYx(0);
ClearNumDpy(0,0);
ClearNumDpy(1,1);
ClearNumDpy(2,2);
ClearNumDpy(3,3);
Settingpricehalf[0]=0;
Settingpricehalf[1]=0;
Settingpricehalf[2]=0;
KEYONOFFEN;
KEYDOWNEN;
KEYUPDS;
KEYSELDS;
LEDCTRL = 0; //CLOSE BACK LED LIGHT
systemflag |= 0x10; //set flag to note and error manage
break;
}
//-------------------user turn on the ON/OFF KEY
if(systemflag2&0x01)
{
systemflag2 &= 0xfe;
systemflag3 |= 0x08;
}
//-------------------user setting water value is over
if(systemflag2 &0x20)
{
systemflag2 &= 0xdf;
systemflag3 |= 0x08;
}
//-------------------user use water stop in geal?
if(systemflag3&0x08)
{
systemflag2&=0xf7;
AddUsingValueOp(panma);
DSGIE;
RevBuffer[16] &= 0xfe;
carderrorbyte=WrCdOneBnk(5);
ENGIE;
if(carderrorbyte!=0x01)
{
systemflag2 |= 0x10;
}
else
{
break;
}
CloseValve();
DPY_CloseValve_Flg();
HQCPWRCTRLOUT = 0; //fm1702 power down
RevBuffer[19]=6;
for(RevBuffer[19];RevBuffer[19]>0;RevBuffer[19]--)
{
// ClearNumDpy(0,0);
ClearNumDpy(1,1);
ClearNumDpy(2,2);
Delay10KTCYx(0); // 0.16s
// DPY_Card_YLorJE_Num(CardBalance,0);
DPY_SLorJE_Num(ShuiLiang,0);
DPY_SDZorDJ_Num(SheDinLiang,1);
Delay10KTCYx(0); // 0.16s
}
ClearNumDpy(0,0);
Wr1BCDNumToLcd(0,1);
Wr1BCDNumToLcd(25,2);
Wr1BCDNumToLcd(14,3);
Wr1BCDNumToLcd(10,4);
Delay10KTCYx(0);
Delay10KTCYx(0);
Delay10KTCYx(0);
ClearNumDpy(0,0);
ClearNumDpy(1,1);
ClearNumDpy(2,2);
ClearNumDpy(3,3);
LEDCTRL = 0; //CLOSE BACK LED LIGHT
Settingpricehalf[0]=0;
Settingpricehalf[1]=0;
Settingpricehalf[2]=0;
UnDYP_CardOn_Flg();
KEYONOFFEN;
KEYDOWNEN;
KEYUPDS;
KEYSELDS;
systemflag |= 0x10; //set flag to note and error manage
break;
}
}
}
//-------------------------------------save user note and error manage
if(systemflag & 0x10)
{
systemflag &= 0xef;
// ClearRamValue();
}
//-------------------------------------recevice whole frame from RS485?
if(systemflag & 0x40)//
{
systemflag &= 0xbf;
}
}
}
//*****************************************************************//
//Name :InitialPort
//Input :void
//Output :void
//Function :This function initialize all mcu i/oport
//D.R.P :QiuHao
//Date :06.06.05
//*****************************************************************//
void InitializeSystem(void)
{
INTCONbits.GIE=0;
INTCONbits.PEIE = 0;
//-----------------------FM1702 Using I/O Port
/* DS1302 */
SETDSCLK;
SETDSRST;
SETDSDA;
/* AT24C1024 */
SETE2WP;
SETE2CLK;
SETE2DA;
/* MOTOR DREVIC */
SETCLOSE;
SETOPEN;
SETVELSTAOP;
SETVELSTACL;
SETMTRDET_ANIN;
/* SIN1~3 */
SETSIN1;
SETSIN2;
SETSIN3;
SETSOUT1;
SETSOUT2;
SETSOUT3;
/* USER KEY */
SETKEYDOWN;
SETKEYUP;
SETKEYONOFF;
SETKEYSEL;
SETKBINT;
/* HT1623 LCD DISPLAY */
SETLEDCTRL ;
SETLCDCS;
SETLCDRD;
SETLCDRW;
SETLCDDA;
/* FM1702 R/W CARD DEVICE */
SETHQCCLK;
SETHQCMN;
SETHQCDI;
SETHQCDO;
SETHQCRST;
SETHQCPWRCTRL;
/* TC35i R/T SMS DEVICE */
SETGSMPWRCTRL;
SETPD;
SETIGT;
SETDTETXD;
SETDTERXD;
/* buzzer */
SETBZ;
/* PRESSURE DETECT */
SETYLDET_ANIN;
SETYLPWRCTRL;
/* UART1 */
SETTXD1;
SETRXD2;
/* SOLAD battery charge up CONTRL */
SETCDCTRL;
/* Power Voltage detect */
SETPWRDET_ANIN;
/* SOLAD battery Voltage detect */
SETSPWRDET_ANIN;
/* Temputer detect */
SETTEMPUTERDET_ANIN;
//-----------------------Pic18f6720 device
/* A/D Conversion Setting */
ADCON0bits.ADON = 0; //close AD moudule
PIE1bits.ADIE = 0; //disable AD Interrupt
ADCON1bits.VCFG1 = 0; //use vcc and vss for Vref
ADCON1bits.VCFG0 = 0;
ADCON1bits.PCFG3 = 1; //AN0~AN6 available
ADCON1bits.PCFG2 = 0;
ADCON1bits.PCFG1 = 0;
ADCON1bits.PCFG0 = 0;
// ADCON2 bits.ADCS2 = 1; //4uS a bit
ADCON2bits.ADCS1 = 1;
ADCON2bits.ADCS0 = 0;
/* UART1 for infrared ray */
SPBRG1 = 207; //1.2Kbit/s
//Sent mode
TXSTA1bits.SYNC = 0; //ASYN mode
TXSTA1bits.BRGH = 0; //Low buad reta Mode
TXSTA1bits.TXEN = 1; //TX enialbe
RCSTA1bits.CREN = 1; //Continuum receive enialbe
RCSTA1bits.SPEN = 1; //Serial port1 enabled.
PIE1bits.TX1IE = 0;
IPR1bits.TX1IP = 0;
IPR1bits.RC1IP = 0; //Low prionty int
PIE1bits.RC1IE = 1;
/* UART2 for GSM TC35i */
SPBRG2 = 25; // 25:= 9.6Kbit/s
//Sent mode
TXSTA2bits.SYNC = 0; //ASYN mode
TXSTA2bits.BRGH = 0; //Low buad reta Mode
TXSTA2bits.TXEN = 1; //TX enialbe
RCSTA2bits.CREN = 1; //Continuum receive enialbe
RCSTA2bits.SPEN = 1; //Serial port2 enabled.
PIE3bits.TX2IE = 0;
IPR3bits.TX2IP = 0;
PIE3bits.RC2IE = 1;
IPR3bits.RC2IP = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -