SOURCE CODEตู้น้ำหยอดเหรียญAT89S53 24C16 UPDATE1
10/2/2558 SONGCHAI PRAPATRUNGSEE
SOURCE CODEตู้น้ำหยอดเหรียญAT89S53 24C16 UPDATE1
#include <REGS53.H>
// Header: WATER MATCHINE
// File Name:
// Author: SONGCHAI PRAPATRUNGSEE
// Date: 6/12/2555
/* USE 11.0592MHZ WRITE 24256 WORK(AT LEAST 5MS)
IF USE 12MHZ
WRITE 24256 NOT WORK
AT TIME VALUE
0XEDFF
DELAY WRITE
24256 AT LEAST 5MS(EDFF) =WORK
DELAY READ
24256 AT LEAST 4.167MS(F10F) =WORK */
/* SAME AS 2416
DELAY WRITE
2416 AT LEAST 5MS(EDFF) =WORK
BUT SIMULATE
WITH PROTEUS
MUST SET IC
2416 AS 5MS */
//1MATCHINE CYCLE =1.085US
//INTERRUPT EVERY 200HZ =5MS
//200 =1SEC
//12000 =1MIN
/*
HH =HOUR
MM =MIN
SS =SEC
*ss =1/100
$$ =BATH
10 =HH.MM
//CLOCK
20 =SS.*ss
//WATER FLOW
30 =MM.SS //CUT
REMAIN COIN
40 =HH.MM //ON
THE LAMP
41 =HH.MM //OFF
THE LAMP
50 =XX.XX //COIN
MAX
60 =XXXX
//NUMBER OF MATCHINE
*/
/* 01 =SET TIME
02 =SET
WTD(WATER DELAY)
03 =SET
CC(CUTCOIN)
04 =SET
LON(LAMP ON)
05 =SET
LOFF(LAMP OFF)
06 =SET
RCMAX(RECEIVE COIN MAX)
07 =MACHINE
NUMBEER
*/
//#define 's'
0xf0;
sbit COIN_B=P0^0; //sbit
=COMMAND, COIN_B=VARIABLE NAME, P3^5=PIN 3.5
sbit WATER_B=P0^1;
sbit WATERNONE_B=P0^2;
sbit SDA=P2^0;//P0 NOT WORK BECAUSE AS INPUT
sbit SCL=P2^1;//P0 NOT WORK BECAUSE AS INPUT
sbit RED_GREEN=P2^4;
sbit PUMP=P2^5;
sbit LAMP=P2^6;
sbit CUT_COIN=P2^7;
sbit DG0=P3^0;
sbit DG1=P3^1;
sbit DG2=P3^2;
sbit DG3=P3^3;
sbit SET_B=P0^3;
sbit UP_B=P0^4;
sbit DOWN_B=P0^5;//DOWN/COIN_MONTH//WHEN BLINK PRESS
LONG CLEAR
sbit STORE_B=P0^6;//NEXT/SAVE/COIN_YEAR
//CONYEAR/WHEN BLINK PRESS LONG CLEAR
idata unsigned long YEAR;
idata unsigned char NS,NT,NTT;
unsigned char WTDLS;//DELAY WATER FLOW =SS
unsigned char WTDLS_S;//DELAY WATER FLOW =*ss =1/100
=SEC/100
unsigned int WTDLX;//CONVERT DELAY WATER FLOW
unsigned char CCM=12;//DELAY CUT COIN =MM.SS =MM
unsigned char CCS=34;//DELAY CUT COIN =MM.SS =SS
idata long CCX;//CONVERT DELAY CUT COIN
idata long CUTCOIN_T;
unsigned char LONH=12;//LAMP ON HI =HOUR
unsigned char LONM=34;//LAMP ON LOW =MIN
unsigned char LOFFH=12;//LAMP OFF HI =HOUR
unsigned char LOFFM=34;//LAMP OFF LOW =MIN
idata int NMCX=1234;//NUMBER MACHINE
idata char LONH2,LONH1,LONH0,LONM1,LONM0;
idata char LOFFH2,LOFFH1,LOFFH0,LOFFM1,LOFFM0;
char WTDLS1,WTDLS0,WTDLS_S1,WTDLS_S0;
unsigned char MIN,HOUR;
char WRITE;
unsigned char DIGIT[]={0XEB,0X28,0XB3,0XBA,0X78,
0XDA,0XDB,0XA8,0XFB,0XFA,};
unsigned char RCMAXB,RCMAXB1,RCMAXB0;
unsigned char RCMAXST,RCMAXST1,RCMAXST0;
int RCMAXX;
char DGIT;
idata char HOUR0,HOUR1,MIN0,MIN1,HOUR2,MIN2;
idata char CCM1,CCM0,CCS1,CCS0;
unsigned char BLINK_T,UP_T,DOWN_T,COIN_T,WATER_T;
unsigned char SET_T,WATERNONE_T,COINSAVE_T;
unsigned int YEAR_T,STORE_T,B_T,MONTH_T;
unsigned int ST_T,SAVE_T;
unsigned int FIRST_T,BLINK2_T,RCMAX_T;
bit DS1307_W,COIN_W,CLEARYEAR_W;
bit WATER_W,COINSAVE_W;
bit UP_L,DOWN_L,MODE;
int iWDL;
char DISPLAY,UPDOWN,CHANGE;
unsigned char DATA0,DATA1,DATA2,DATA3;
unsigned char READ_SECYEAR,SAVE_COIN;
unsigned char COIN,COIN_MONTH,COIN_YEAR,SET,i;
unsigned int COIN_WATER,MONTH;
unsigned int YEAR_UP,YEAR_DOWN;
bit BLINK_W;
bit YEAR_W,COINMONTH_W,MAXYEAR_W,MAXMONTH_W;
bit NS_W,NT_W,NTT_W;
//bit HOUR1_W,DIGIT2_W,DIGIT1_W,DIGIT0_W;
bit DISPLAYYEAR_W,DISPLAYMONTH_W,CLEARMONTH_W;
bit WRITE_W,SAVE_W;
bit COIN_L,WATER_L,YEAR_L,STORE_L;
bit ST_L,SAVE_L,SET_L,MAXMONTH_L,MAXYEAR_L;
bit DIGIT3_W,DIGIT2_W,DIGIT1_W,DIGIT0_W,ZERO_W;
bit FIRSTLAMP_W,CHANGE_W,FIRST_W,RCMAX_W;
idata unsigned char HOUR10,HOUR00,MIN10,MIN00;
void DELAY_T0M2(unsigned char HI_BYTE,LOW_BYTE)
{
//TIMER0 MODE2
8BIT AUTO RELOAD
TH0=HI_BYTE;//HI
BYTE
TL0=LOW_BYTE;//LOW BYTE
TF0=0;//TIMER0
OVERFLOW
TR0=1;//TIMER
START
while(TF0==0);
TR0=0;//TIMER
STOP
}
void CONVERT_DEC_TO_UNIT(unsigned int NUMBER)
{
unsigned char
NUM;
NUM=((NUMBER%10000)/1000);//PAN
DATA3=DIGIT[NUM];
NUM=((NUMBER%1000)/100);//ROY
DATA2=DIGIT[NUM];
NUM=((NUMBER%100)/10);//SIB
DATA1=DIGIT[NUM];
NUM=NUMBER%10;//NAUY
DATA0=DIGIT[NUM];
}
void CUT_ZERO()
{
if(DATA3==DIGIT[0])
{
DATA3=0X00;
}
}
void CUT_ZEROS()
{
if(DATA3==DIGIT[0])
{
DATA3=0X00;
if(DATA2==DIGIT[0])
{
DATA2=0X00;
if(DATA1==DIGIT[0])
{
DATA1=0X00;
}
}
}
}
void DISPLAY_STRING(unsigned char A,B,C,D)
{
switch (DGIT)
{
case 0:
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
P1=A;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
P1=B;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
P1=C;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
P1=D;
DGIT=0;
break;
}
}
void DISPLAY_COINYEAR(unsigned int NUMBER)
{
CONVERT_DEC_TO_UNIT(NUMBER);
switch (DGIT)
{
case 0:
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
P1=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
P1=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
P1=DATA2;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
P1=DATA3;
DGIT=0;
break;
default:
DGIT=0;
break;
}
}
void DISPLAY_COINMONTH(unsigned int NUMBER)
{
CONVERT_DEC_TO_UNIT(NUMBER);
CUT_ZEROS();
switch (DGIT)
{
case 0:
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
P1=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
P1=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
P1=DATA2;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
P1=DATA3;
DGIT=0;
break;
default:
DGIT=0;
break;
}
}
void DISPLAY_COIN(unsigned int NUMBER)
{
CONVERT_DEC_TO_UNIT(NUMBER);
CUT_ZERO();
switch (DGIT)
{
case 0:
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
P1=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
P1=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
P1=DATA2|0X04;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
P1=DATA3;
DGIT=0;
break;
default:
DGIT=0;
break;
}
}
void I2C_START()
{
SCL=1;
SDA=1;
SDA=0;
SCL=0;
}
void I2C_STOP()
{
SDA=0;
SCL=1;
SDA=1;
}
void I2C_TX(unsigned char DATTX)
{
char i;
for (i=0;i<8;i++)
{
if ((DATTX&0x80)==0x80)SDA=1;
else SDA=0;
SCL=1;
SCL=0;
DATTX<<=1;
}
SDA=0;//SEND TO ACK BIT
SCL=1;
SCL=0;
}
unsigned char I2C_RX(bit ACK)
{
unsigned char i,DATRX=0;
SDA=1;//IF THIS
ROW NONE DISPLAY TEMPERATURE 0.00
for(i=0;i<8;i++)
{
DATRX<<=1;
SCL=1;
if(SDA)//SDA DEFAULT=1
{
DATRX|=0X01;
}
else
{
DATRX&=0XFE;
}
SCL=0;
}
SDA=ACK;//SEND
ACK
SCL=1;
SCL=0;
return DATRX;
}
////////////////////////////////////////////
void WRITE_DS1307(unsigned char ADDRESS,SECYEAR)
{
I2C_START();
I2C_TX(0XD0);//D0=ADDRESSS WRITE
I2C_TX(ADDRESS);//ADDRESS=0X00=SEC 0X01=MIN............
I2C_TX(SECYEAR);//SECYEAR=VARIABLE SECYEAR=SEC MIN..............
I2C_STOP();
}
unsigned char READ_DS1307(char ADDRESS)
{
unsigned char
SECYEAR=0;
I2C_START();
I2C_TX(0XD0);//D0=ADDRESS WRITE
I2C_TX(ADDRESS);//ADDRESS=0X00=SEC 0X01=MIN..................
I2C_STOP();
I2C_START();
I2C_TX(0XD1);//D1=ADDRESS READ
SECYEAR=I2C_RX(1);
I2C_STOP();
return(SECYEAR);//=RETURN VALUE TO FUNCTION
}
void WRITE_2416(unsigned char ADDRESS,DATWR)
{
I2C_START();
I2C_TX(0XA0);
I2C_TX(ADDRESS);
I2C_TX(DATWR);
I2C_STOP();
}
unsigned int READ_2416(unsigned char ADDRESS)
{
unsigned char DATRX;
I2C_START();
I2C_TX(0XA0);
I2C_TX(ADDRESS);
I2C_START();
I2C_TX(0XA1);
DATRX=I2C_RX(1);
I2C_STOP();
return DATRX;
}
//void SET_LAMP_ON();
void T2_16BIT_AUTO()interrupt 5
{
TF2=0;//TIMER2
OVERFLOW FLAG =CLEAR
// LONH=12;//TEST
// LONM=59;//TEST
//
LOFFH=18;//TEST
//
LOFFM=59;//TEST
// HOUR=12;//TEST
// MIN=38;//TEST
HOUR10=HOUR>>4;
HOUR00=HOUR&0X0F;
HOUR2=HOUR10*10+HOUR00;
MIN10=MIN>>4;
MIN00=MIN&0X0F;
MIN2=MIN10*10+MIN00;
LONH2=LONH;
LOFFH2=LOFFH;
if(LONH2-LOFFH2>=0)
{
ZERO_W=1;
}else ZERO_W=0;
if(ZERO_W==1)//LENGH HAVE 0
{
if(HOUR2>=LONH)
{
if(HOUR2==LONH)
{
if(MIN2>=LONM)LAMP=1;
}else
LAMP=1;
}else
if(HOUR2>=0&&HOUR2<=LOFFH)
{
if(HOUR2==LOFFH)
{
if(MIN2<LOFFM)LAMP=1;
}else
LAMP=1;
}
}else//ZERO_W=0//LENGH NO 0
{
if(HOUR2>=LONH&&HOUR2<=LOFFH)
{
if(HOUR2==LONH)
{
if(MIN2>=LONM)
{
LAMP=1;
}
}else
if(HOUR2==LOFFH)
{
if(MIN2<LOFFM)LAMP=1;
}else
if(HOUR2>LONH)
{
LAMP=1;
}
}
}
if(LOFFH2-LONH2>=0)
{
ZERO_W=1;
}else ZERO_W=0;
if(ZERO_W==1)//LENGH HAVE 0
{
if(HOUR2>=LOFFH)
{
if(HOUR2==LOFFH)
{
if(MIN2>=LOFFM)LAMP=0;
}else
LAMP=0;
}else
if(HOUR2>=0&&HOUR2<=LONH)
{
if(HOUR2==LONH)
{
if(MIN2<LONM)LAMP=0;
}else
LAMP=0;
}
}else//ZERO_W=0//LENGH NO 0
{
if(HOUR2>=LOFFH&&HOUR2<=LONH)
{
if(HOUR2==LOFFH)
{
if(MIN2>=LOFFM)
{
LAMP=0;
}
}else
if(HOUR2==LONH)
{
if(MIN2<LONM)LAMP=0;
}else
if(HOUR2>LOFFH)
{
LAMP=0;
}
}
}
if(MODE==0)
{
if(WATERNONE_B==0)
{
if(++WATERNONE_T>=20)
{
WATERNONE_T=0;
RED_GREEN=1;
//CUT_COIN=1;//IF USE RELAY
CUT_COIN=0;//IF USE TRANSISTER
}
}else
if(WATERNONE_B==1&&RCMAX_W==0)
{
RED_GREEN=0;
//CUT_COIN=0;//IF USE RELAY
CUT_COIN=1;//IF USE TRANSISTER
}
if(FIRSTLAMP_W==0)
{
LAMP=1;
if(++FIRST_T>=36000)//12000=1MIN
{
FIRST_T=0;
LAMP=0;
FIRSTLAMP_W=1;
}
}
if(COIN_WATER>=RCMAXX)
{
if(++RCMAX_T>=40)//40X5MS =200MS
{
RCMAX_T=0;
RCMAX_W=1;
//CUT_COIN=1;//IF USE RELAY
CUT_COIN=0;//IF USE TRANSISTER
RED_GREEN=1;
}
}else
if(WATERNONE_B==1)
{
//CUT_COIN=0;//IF USE RELAY
CUT_COIN=1;//IF USE TRANSISTER
RED_GREEN=0;
RCMAX_W=0;
}
if(SET_B==0&&SET_L==0)
{
if(++SET_T>=20)//100MS
{
SET_T=0;
SET_L=1;
COIN_WATER=0;
MODE=1;
FIRST_T=0;
FIRSTLAMP_W=1;
}
}else
if(SET_B==1)
{
SET_T=0;
SET_L=0;
}
if(STORE_B==0&&STORE_L==0&&YEAR_W==0)
{
if(++STORE_T>=20)//20X5MS =100MS
{
STORE_T=0;
STORE_L=1;
YEAR_L=0;
YEAR_W=1;
COINMONTH_W=0;
DISPLAYMONTH_W=0;
DS1307_W=0;
COIN_W=0;
COIN_WATER=0;
MONTH_T=0;
// YEAR=12345678;
YEAR_UP=YEAR/10000;//1234
YEAR_DOWN=YEAR%10000;//5678
}
}else
if(STORE_B==1)
{
STORE_L=0;
STORE_T=0;
}
if(YEAR_W==1&&DISPLAYYEAR_W==0)
{
if(YEAR_L==0)
{
DISPLAY_COINYEAR(YEAR_UP);
if(++YEAR_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++B_T>=50)
{
B_T=0;
YEAR_L=1;
YEAR_T=0;
}
}
}else
{
DISPLAY_COINYEAR(YEAR_DOWN);
if(++YEAR_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(STORE_B==1)
{
ST_L=1;
ST_T=0;
}
if(STORE_B==0&&ST_L==1)
{
if(++ST_T>=400)
{
ST_T=0;
CLEARYEAR_W=1;
YEAR_T=0;
YEAR_L=0;
}
}else
if(STORE_B==0&&ST_L==0&&++B_T>=200)
{
B_T=0;
YEAR_T=0;
YEAR_L=0;
YEAR_W=0;
}else
if(STORE_B==1&&++B_T>=200)
{
B_T=0;
YEAR_T=0;
YEAR_L=0;
YEAR_W=0;
ST_L=0;
}
}
}
}
if(CLEARYEAR_W==1)
{
COIN_YEAR=0;
YEAR=0;
NT=0;
NTT=0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch(SAVE_COIN)
{
case
0://COIN_YEAR
WRITE_2416(3,COIN_YEAR);
SAVE_COIN=1;
break;
case
1://NT
WRITE_2416(4,NT);
SAVE_COIN=2;
break;
case
2://NTT
WRITE_2416(5,NTT);
DISPLAYYEAR_W=1;
CLEARYEAR_W=0;
SAVE_COIN=0;
break;
}
}
if(DISPLAYYEAR_W==1)
{
DS1307_W=0;
COIN_WATER=0;
STORE_L=1;
MAXYEAR_L=0;
YEAR_W=0;
DISPLAY_STRING(0X78,0X11,0X43,0XC3);//CLrY
if(++YEAR_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++B_T>=200)
{
B_T=0;
YEAR_T=0;
DISPLAYYEAR_W=0;
}
}
}
if(DOWN_B==0&&DOWN_L==0&&COINMONTH_W==0)
{
if(++DOWN_T>=4)
{
DOWN_T=0;
DOWN_L=1;
COINMONTH_W=1;
YEAR_W=0;
DISPLAYYEAR_W=0;
COIN_W=0;
COIN_WATER=0;
YEAR_T=0;
DS1307_W=0;
}
}else
if(DOWN_B==1)
{
DOWN_T=0;
DOWN_L=0;
}
if(COINMONTH_W==1&&DISPLAYMONTH_W==0)
{
DISPLAY_COINMONTH(MONTH);
if(++MONTH_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(DOWN_B==1)
{
ST_L=1;
ST_T=0;
}
if(DOWN_B==0&&ST_L==1)
{
if(++ST_T>=400)
{
ST_T=0;
ST_L=0;
DOWN_L=0;
CLEARMONTH_W=1;
MONTH_T=0;
YEAR_L=0;
}
}else
if(DOWN_B==0&&ST_L==0&&++B_T>=200)
{
B_T=0;
MONTH_T=0;
YEAR_L=0;
COINMONTH_W=0;
}else
if(DOWN_B==1&&++B_T>=200)
{
B_T=0;
MONTH_T=0;
YEAR_L=0;
COINMONTH_W=0;
ST_L=0;
}
}
}
if(CLEARMONTH_W==1)
{
COIN_MONTH=0;
NS=0;
MONTH=0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch(SAVE_COIN)
{
case
0://COIN_MONTH
WRITE_2416(1,COIN_MONTH);
SAVE_COIN=1;
break;
case
1://NS
WRITE_2416(2,NS);
DISPLAYMONTH_W=1;
CLEARMONTH_W=0;
SAVE_COIN=0;
break;
}
}
if(DISPLAYMONTH_W==1)
{
DS1307_W=0;
COIN_WATER=0;
DOWN_L=1;
MAXMONTH_L=0;
COINMONTH_W=0;
DISPLAY_STRING(0X19,0X11,0X43,0XC3);//CLrm
if(++YEAR_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++B_T>=200)
{
B_T=0;
YEAR_T=0;
DISPLAYMONTH_W=0;
}
}
}
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
BLINK_W=~BLINK_W;
}
if(WATER_B==0&&WATER_L==0&&COIN_W==1)
{
if(++WATER_T>=20)//DELAY
100MS
{
WATER_T=0;
WATER_L=1;
WATER_W=~WATER_W;
CUTCOIN_T=0;//TIME CUT REMAIN COIN
if(WATER_W==1)
{
PUMP=1;
}else
PUMP=0;
}
}else
if(WATER_B==1)
{
WATER_L=0;
WATER_T=0;
}
if(COIN_B==0&&COIN_L==0)
{
if(++COIN_T>=4)//DELAY 20MS
{
BLINK_W=0;//NOT BLINK
BLINK_T=0;
COIN_T=0;
COIN_L=1;
CUTCOIN_T=0;
COINSAVE_T=0;
RCMAX_T=0;
COIN++;
//NS=38;//TEST
if(MONTH>=9999)
{
MONTH=9999;
MAXMONTH_W=1;
}else
MAXMONTH_W=0;
if(MAXMONTH_W==0)
{
COIN_MONTH=COIN_MONTH+COIN;
MONTH=COIN_MONTH;
COINSAVE_W=1;
//COIN_MONTH=255;//TEST
if(COIN_MONTH==255)
{
COIN_MONTH=0;
NS_W=1;
NS++;
}
}
MONTH=NS*255+COIN_MONTH;
if(YEAR>=16000000)
{
YEAR=16000000;
MAXYEAR_W=1;
}else
MAXYEAR_W=0;
if(MAXYEAR_W==0)
{
COIN_YEAR=COIN_YEAR+COIN;
YEAR=YEAR+COIN;
COINSAVE_W=1;
//COIN_YEAR=255;//TEST
if(COIN_YEAR==255)
{
COIN_YEAR=0;
NT++;
NT_W=1;
//NT=254;//TEST
//NT=255;//TEST
if(NT==255)
{
NT=0;
NTT++;
//NTT=246;//TEST
//NT=15;//TEST
NTT_W=1;
}
}
}
YEAR=(NTT*65025)+NT*255+COIN_YEAR;
COIN_WATER=COIN*100+COIN_WATER;
COIN=0;
COIN_W=1;
DS1307_W=0;
}
}else
if(COIN_B==1)
{
COIN_L=0;
COIN_T=0;
}
if(COINSAVE_W==1)
{
if(++COINSAVE_T>=40&&SAVE_L==0)//200MS
{
COINSAVE_T=0;
SAVE_L=1;
WRITE_W=1;
}
if(WRITE_W==1)
{
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch(SAVE_COIN)
{
case
0://COIN_MONTH
if(MAXMONTH_W==0)
{
WRITE_2416(1,COIN_MONTH);
}else
if(MAXMONTH_W==1&&MAXMONTH_L==0)
{
MAXMONTH_L=1;
WRITE_2416(1,COIN_MONTH);
}
SAVE_COIN=1;
break;
case 1://NS
if(NS_W==1)
{
NS_W=0;
WRITE_2416(2,NS);
}
SAVE_COIN=2;
break;
case
2://COIN_YEAR
if(MAXYEAR_W==0)
{
WRITE_2416(3,COIN_YEAR);
}else
if(MAXYEAR_W==1&&MAXYEAR_L==0)
{
MAXYEAR_L=1;
WRITE_2416(3,COIN_YEAR);
}
SAVE_COIN=3;
break;
case
3://NT
if(NT_W==1)
{
NT_W=0;
WRITE_2416(4,NT);
}
SAVE_COIN=4;
break;
case
4://NTT
if(NTT_W==1)
{
NTT_W=0;
WRITE_2416(5,NTT);
}
COINSAVE_W=0;
SAVE_COIN=0;
SAVE_L=0;
WRITE_W=0;
COINSAVE_T=0;
break;
}
}
}
if(COIN_W==1)
{
if(WATER_W==0)
{
if(++CUTCOIN_T>=CCX)//CUT_COIN
{
CUTCOIN_T=0;
COIN_WATER=0;
}
}
if(BLINK_W==0)//NOT BLINK
{
DISPLAY_COIN(COIN_WATER);
}else
{
DG0=DG1=DG2=DG3=0;//REAL
}
}
if(COIN_WATER==0&&YEAR_W==0&&COINMONTH_W==0
&&DISPLAYYEAR_W==0&&DISPLAYMONTH_W==0)
{
DS1307_W=1;
COIN_W=0;
}else
DS1307_W=0;
if(DS1307_W==1)
{
switch(READ_SECYEAR)
{
case
0://MIN
MIN=READ_DS1307(1);
MIN0=MIN&0X0F;
MIN1=MIN>>4;
READ_SECYEAR=1;
break;
case
1://HOUR
HOUR=READ_DS1307(2);
HOUR0=HOUR&0X0F;
HOUR1=HOUR>>4;
READ_SECYEAR=0;
break;
}
switch(DISPLAY)
{
case
0://MIN0
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
P1=DIGIT[MIN0];
DISPLAY=1;
break;
case
1://MIN1
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
P1=DIGIT[MIN1];
DISPLAY=2;
break;
case
2://HOUR0
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
P1=DIGIT[HOUR0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=3;
break;
case
3://HOUR
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
P1=DIGIT[HOUR1];
DISPLAY=0;
break;
}
}
}else//MODE=1
========================================
{
if(++BLINK2_T>=2000)//200=1SEC
{
BLINK2_T=0;
CHANGE_W=1;
}
if(++BLINK_T>100)
{
BLINK_T=0;
BLINK_W=~BLINK_W;
}
if(SET_B==0&&SET_L==0)
{
if(++SET_T>=20)//NEXT
{
SET_T=0;
SET_L=1;
FIRST_W=0;
FIRST_T=0;
SET++;//SET NEXT
if(SET>7)
{
CHANGE_W=1;
}
BLINK2_T=0;
SAVE_T=0;
SAVE_W=0;
WRITE=0;
WRITE_W=0;
DIGIT3_W=0;
DIGIT2_W=0;
DIGIT1_W=0;
DIGIT0_W=0;
UPDOWN=1;
}
}else
if(SET_B==1)
{
SET_L=0;
SAVE_L=0;
SET_T=0;
}
if(CHANGE_W==1)
{
switch(CHANGE)
{
case 0:
DG3=DG2=DG1=DG0=0;//REAL
if(++FIRST_T>=200)
{
FIRST_T=0;
CHANGE=1;
}
break;
case 1:
DISPLAY_STRING(0X10,0X10,0X10,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=0;
SET=1;
CHANGE=0;
CHANGE_W=0;
DIGIT3_W=0;
DIGIT2_W=0;
DIGIT1_W=0;
DIGIT0_W=0;
UPDOWN=1;
MODE=0;
}
break;
}
return;
}
if(STORE_B==0&&STORE_L==0)//NEXT,SAVE
{
if(++STORE_T>=20)//NEXT
{
STORE_L=1;
UPDOWN++;//NEXT
if(UPDOWN>4)UPDOWN=1;
BLINK2_T=0;
SAVE_T=0;
SAVE_W=0;
DIGIT3_W=0;
DIGIT2_W=0;
DIGIT1_W=0;
DIGIT0_W=0;
}
}else
if(STORE_B==0&&SAVE_L==0)
{
if(++STORE_T>=400)
{
STORE_T=0;
SAVE_L=1;
WRITE_W=1;
}
}else
if(STORE_B==1)
{
STORE_L=0;
SAVE_L=0;
STORE_T=0;
}
switch(SET)
{
case 1://SET
TIME
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0X28,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
WRITE_W=0;
//IF
HOUR=12,
//HOUR1=HOUR/10;//HOUR1=1=0X01
HOUR1=HOUR1<<4;//HOUR=0X10
//HOUR0=HOUR%10;// HOUR0=2=0X02
HOUR=HOUR1|HOUR0;//HOUR=0X12
//MIN1=MIN/10;//MIN1=1=0X01
MIN1=MIN1<<4;//MIN=0X10
//MIN0=MIN%10;// MIN0=2=0X02
MIN=MIN1|MIN0;//HOUR=0X12
WRITE_DS1307(1,MIN);
WRITE_DS1307(2,HOUR);
HOUR1=HOUR1>>4;
MIN1=MIN1>>4;
SAVE_W=1;
}
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://HOUR1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[HOUR1];
DISPLAY=1;
break;
case
1://HOUR0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[HOUR0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case
2://MIN1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[MIN1];
DISPLAY=3;
break;
case
3://MIN0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[MIN0];
DISPLAY=0;
break;
}
}else
if(SAVE_W==1)
{
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}
switch(UPDOWN)
{
case
1://HOUR
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)//20X5MS =100MS
{
UP_T=0;
UP_L=1;
HOUR1++;
if(HOUR1>2)HOUR1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
HOUR1++;
if(HOUR1>2)HOUR1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(HOUR1==0)HOUR1=3;
HOUR1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(HOUR1==0)HOUR1=3;
HOUR1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://HOUR0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
HOUR0++;
if(HOUR0>9)HOUR0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
HOUR0++;
if(HOUR0>9)HOUR0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(HOUR0==0)HOUR0=10;
HOUR0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(HOUR0==0)HOUR0=10;
HOUR0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
3://MIN1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
MIN1++;
if(MIN1>5)MIN1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
MIN1++;
if(MIN1>5)MIN1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(MIN1==0)MIN1=6;
MIN1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(MIN1==0)MIN1=6;
MIN1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
4://MIN0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
MIN0++;
if(MIN0>9)MIN0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
MIN0++;
if(MIN0>9)MIN0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(MIN0==0)MIN0=10;
MIN0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(MIN0==0)MIN0=10;
MIN0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case 2://SET
WATER DELAY====================
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0XB3,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
WTDLS=WTDLS1*10+WTDLS0;
WTDLS_S=WTDLS_S1*10+WTDLS_S0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch
(WRITE)
{
case
0://WATER DELAY SEC
WRITE_2416(6,WTDLS);
WRITE=1;
break;
case
1://WATER DELAY SEC/100
WRITE_2416(7,WTDLS_S);
WRITE=2;
break;
case
2://WATER DELAY SEC/100
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
if(WTDLS==0&&WTDLS_S==0)
{
WTDLS0=7;
WTDLS=7;
}
WTDLX=WTDLS*100+WTDLS_S;
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}else
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://WTDLS1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[WTDLS1];
DISPLAY=1;
break;
case
1://WTDLS0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[WTDLS0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case
2://WTDLS_S1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[WTDLS_S1];
DISPLAY=3;
break;
case
3://WTDLS_S0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[WTDLS_S0];
DISPLAY=0;
break;
}
}
switch(UPDOWN)
{
case
1://WTDLS1
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
BLINK2_T=0;
WTDLS1++;
if(WTDLS1>9)WTDLS1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
WTDLS1++;
if(WTDLS1>9)WTDLS1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(WTDLS1==0)WTDLS1=10;
WTDLS1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(WTDLS1==0)WTDLS1=10;
WTDLS1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://WTDLS0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
WTDLS0++;
if(WTDLS0>9)WTDLS0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
WTDLS0++;
if(WTDLS0>9)WTDLS0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(WTDLS0==0)WTDLS0=10;
WTDLS0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(WTDLS0==0)WTDLS0=10;
WTDLS0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
3://WTDLS_S1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
WTDLS_S1++;
if(WTDLS_S1>9)WTDLS_S1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
WTDLS_S1++;
if(WTDLS_S1>9)WTDLS_S1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(WTDLS_S1==0)WTDLS_S1=10;
WTDLS_S1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(WTDLS_S1==0)WTDLS_S1=10;
WTDLS_S1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
4://WTDLS_S0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
WTDLS_S0++;
if(WTDLS_S0>9)WTDLS_S0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
WTDLS_S0++;
if(WTDLS_S0>9)WTDLS_S0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(WTDLS_S0==0)WTDLS_S0=10;
WTDLS_S0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(WTDLS_S0==0)WTDLS_S0=10;
WTDLS_S0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case 3://SET
CUT_COIN======================
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0XBA,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
CCM=CCM1*10+CCM0;
CCS=CCS1*10+CCS0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch
(WRITE)
{
case
0://CUT_COIN MIN
WRITE_2416(8,CCM);
WRITE=1;
break;
case
1://CUT_COIN SEC
WRITE_2416(9,CCS);
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
//CUT_COIN TIME
if(CCM==0&&CCS==0)
{
CCM0=5;
CCM=5;
}
CCX=(long)CCM*12000;//12000N=MIN 1N=5MS
CCX=CCX+CCS*200;//200N=SEC 1N=5MS
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}else
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://CCM1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[CCM1];
DISPLAY=1;
break;
case
1://CCM0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[CCM0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case 2://CCS1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[CCS1];
DISPLAY=3;
break;
case
3://CCS0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[CCS0];
DISPLAY=0;
break;
}
}
switch(UPDOWN)
{
case
1://CCM1
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
CCM1++;
if(CCM1>9)CCM1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
CCM1++;
if(CCM1>9)CCM1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(CCM1==0)CCM1=10;
CCM1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(CCM1==0)CCM1=10;
CCM1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://CCM0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
CCM0++;
if(CCM0>9)CCM0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
CCM0++;
if(CCM0>9)CCM0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(CCM0==0)CCM0=10;
CCM0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(CCM0==0)CCM0=10;
CCM0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
3://CCS1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
CCS1++;
if(CCS1>5)CCS1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
CCS1++;
if(CCS1>5)CCS1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(CCS1==0)CCS1=6;
CCS1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(CCS1==0)CCS1=6;
CCS1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
4://CCS0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
CCS0++;
if(CCS0>9)CCS0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
CCS0++;
if(CCS0>9)CCS0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF
NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(CCS0==0)CCS0=10;
CCS0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(CCS0==0)CCS0=10;
CCS0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case 4://SET
LAMP ON TIME
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0X78,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
LONH=LONH1*10+LONH0;
LONM=LONM1*10+LONM0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch
(WRITE)
{
case 0://CUT_COIN MIN
WRITE_2416(10,LONH);
WRITE=1;
break;
case
1://CUT_COIN SEC
WRITE_2416(11,LONM);
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
//LAMP
ON TIME
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}else
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://LONH1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[LONH1];
DISPLAY=1;
break;
case
1://LONH0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[LONH0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case
2://LONM1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[LONM1];
DISPLAY=3;
break;
case
3://LONM0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[LONM0];
DISPLAY=0;
break;
}
}
switch(UPDOWN)
{
case
1://LONH1
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LONH1++;
if(LONH1>2)LONH1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LONH1++;
if(LONH1>2)LONH1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LONH1==0)LONH1=3;
LONH1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LONH1==0)LONH1=3;
LONH1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://LONH0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LONH0++;
if(LONH0>9)LONH0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LONH0++;
if(LONH0>9)LONH0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LONH0==0)LONH0=10;
LONH0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LONH0==0)LONH0=10;
LONH0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case 3://LONM1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LONM1++;
if(LONM1>5)LONM1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LONM1++;
if(LONM1>5)LONM1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LONM1==0)LONM1=6;
LONM1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LONM1==0)LONM1=6;
LONM1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
4://LONM0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LONM0++;
if(LONM0>9)LONM0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LONM0++;
if(LONM0>9)LONM0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LONM0==0)LONM0=10;
LONM0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LONM0==0)LONM0=10;
LONM0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN
2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case
5://LAMP OFF TIME
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0XDA,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
LOFFH=LOFFH1*10+LOFFH0;
LOFFM=LOFFM1*10+LOFFM0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch
(WRITE)
{
case
0://CUT_COIN MIN
WRITE_2416(12,LOFFH);
WRITE=1;
break;
case
1://CUT_COIN SEC
WRITE_2416(13,LOFFM);
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
//LAMP
ON TIME
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}else
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://LOFFH1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[LOFFH1];
DISPLAY=1;
break;
case
1://LOFFH0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[LOFFH0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case
2://LOFFM1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[LOFFM1];
DISPLAY=3;
break;
case
3://LOFFM0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[LOFFM0];
DISPLAY=0;
break;
}
}
switch(UPDOWN)
{
case
1://LOFFH1
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LOFFH1++;
if(LOFFH1>2)LOFFH1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LOFFH1++;
if(LOFFH1>2)LOFFH1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LOFFH1==0)LOFFH1=3;
LOFFH1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LOFFH1==0)LOFFH1=3;
LOFFH1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://LOFFH0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LOFFH0++;
if(LOFFH0>9)LOFFH0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LOFFH0++;
if(LOFFH0>9)LOFFH0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LOFFH0==0)LOFFH0=10;
LOFFH0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LOFFH0==0)LOFFH0=10;
LOFFH0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
3://LOFFM1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LOFFM1++;
if(LOFFM1>5)LOFFM1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LOFFM1++;
if(LOFFM1>5)LOFFM1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LOFFM1==0)LOFFM1=6;
LOFFM1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LOFFM1==0)LOFFM1=6;
LOFFM1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case 4://LOFFM0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
LOFFM0++;
if(LOFFM0>9)LOFFM0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
LOFFM0++;
if(LOFFM0>9)LOFFM0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(LOFFM0==0)LOFFM0=10;
LOFFM0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(LOFFM0==0)LOFFM0=10;
LOFFM0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case 6://SET
RECEIVE COIN MAX
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0XDB,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(WRITE_W==1)
{
RCMAXB=RCMAXB1*10+RCMAXB0;
RCMAXST=RCMAXST1*10+RCMAXST0;
TR2=0;
TH2=0XEA;//HI BYTE TIMER2//EA66=6MS AT 11.0592MHZ
TL2=0X66;//LOW BYTE TIMER2
TR2=1;
switch
(WRITE)
{
case
0://WATER DELAY SEC
WRITE_2416(14,RCMAXB);
WRITE=1;
break;
case
1://WATER DELAY SEC/100
WRITE_2416(15,RCMAXST);
WRITE=2;
break;
case
2://WATER DELAY SEC/100
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
if(RCMAXB==0&&RCMAXST==0)
{
RCMAXB1=5;
RCMAXB=50;
}
RCMAXX=RCMAXB*100+RCMAXST;
DISPLAY_STRING(0XD3,0X6B,0XF9,0XDA);//SAVE
if(++SAVE_T>=200)
{
DG3=DG2=DG1=DG0=0;//REAL
if(++SAVE_T>=400)
{
SAVE_T=0;
SAVE_W=0;
}
}
}else
if(SAVE_W==0)
{
switch(DISPLAY)
{
case
0://RCMAXB1
if(DIGIT3_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
}
P1=DIGIT[RCMAXB1];
DISPLAY=1;
break;
case
1://RCMAXB0
if(DIGIT2_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
}
P1=DIGIT[RCMAXB0];
if(BLINK_W==0)
{
P1=P1|0X04;
}
DISPLAY=2;
break;
case
2://RCMAXST1
if(DIGIT1_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
}
P1=DIGIT[RCMAXST1];
DISPLAY=3;
break;
case
3://RCMAXST0
if(DIGIT0_W==1)
{
if(BLINK_W==0)
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=0;
}
}else
{
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
}
P1=DIGIT[RCMAXST0];
DISPLAY=0;
break;
}
}
switch(UPDOWN)
{
case
1://RCMAXB1
DIGIT3_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
RCMAXB1++;
if(RCMAXB1>9)RCMAXB1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
RCMAXB1++;
if(RCMAXB1>9)RCMAXB1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(RCMAXB1==0)RCMAXB1=10;
RCMAXB1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(RCMAXB1==0)RCMAXB1=10;
RCMAXB1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
2://RCMAXB0
DIGIT2_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
RCMAXB0++;
if(RCMAXB0>9)RCMAXB0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
RCMAXB0++;
if(RCMAXB0>9)RCMAXB0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(RCMAXB0==0)RCMAXB0=10;
RCMAXB0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(RCMAXB0==0)RCMAXB0=10;
RCMAXB0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
3://RCMAXST1
DIGIT1_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
RCMAXST1++;
if(RCMAXST1>9)RCMAXST1=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
RCMAXST1++;
if(RCMAXST1>9)RCMAXST1=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(RCMAXST1==0)RCMAXST1=10;
RCMAXST1--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(RCMAXST1==0)RCMAXST1=10;
RCMAXST1--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
case
4://RCMAXST0
DIGIT0_W=1;
if(UP_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(UP_L==0)
{
if(++UP_T>=20)
{
UP_T=0;
UP_L=1;
RCMAXST0++;
if(RCMAXST0>9)RCMAXST0=0;
}
}
if(UP_L==1)
{
UP_T++;
if(UP_T>=50)
{
UP_T=0;
RCMAXST0++;
if(RCMAXST0>9)RCMAXST0=0;
}
}
}else
{
UP_L=0;
UP_T=0;//IF NO HAVE SOMETIME UP 2TIME
}
if(DOWN_B==0)
{
BLINK_W=0;
BLINK_T=0;
BLINK2_T=0;
if(DOWN_L==0)
{
if(++DOWN_T>=20)
{
DOWN_T=0;
DOWN_L=1;
if(RCMAXST0==0)RCMAXST0=10;
RCMAXST0--;
}
}
if(DOWN_L==1)
{
DOWN_T++;
if(DOWN_T>=50)
{
DOWN_T=0;
if(RCMAXST0==0)RCMAXST0=10;
RCMAXST0--;
}
}
}else
{
DOWN_L=0;
DOWN_T=0;//IF NO HAVE SOMETIME DOWN 2TIME
}
break;
default:
UPDOWN=1;
break;
}
break;
case 7:
if(FIRST_W==0)
{
DISPLAY_STRING(0X10,0XA8,0XEB,0X10);
if(++FIRST_T>=200)
{
FIRST_T=0;
FIRST_W=1;
}
return;
}
if(BLINK_W==0)
{
DISPLAY_COINYEAR(NMCX);//NUMBER MACHINE
}else
DG3=DG2=DG1=DG0=0;//REAL
break;
default:
SET=1;
break;
}
}
}
void main()
{
T2MOD=0;//TIMER2
MODE
T2CON=0;//TIMER2
CONTROLL
TMOD=0X12;//TIMER0 MODE2 8BIT AUTO RELOAD
TCON=0X00;//TIMER CONTROLL=STOP TIMER
TH2=0XED;//HI
BYTE TIMER2//EDFF=5MS AT 11.0592MHZ
TL2=0XFF;//LOW
BYTE TIMER2
RCAP2H=0XED;//HI
BYTE AUTO RELOAD TIMER2
RCAP2L=0XFF;//LOW BYTE AUTO RELOAD TIMER2
IE=0XA0;//INTERRUPT ENABLE
IP=0;//INTERRUPT
PRIORITY
TR2=1;//START
TIMER2
P1=0;
COIN_MONTH=READ_2416(1);
NS=READ_2416(2);
COIN_YEAR=READ_2416(3);
NT=READ_2416(4);
NTT=READ_2416(5);
WTDLS=READ_2416(6);//WATER DELAY SEC
WTDLS_S=READ_2416(7);//WATER DELAY SEC/100
CCM=READ_2416(8);//CUT_COIN MIN
CCS=READ_2416(9);//CUT_COIN SEC
//DELAY IF NO,
LONH READ ERROR=BUG OF PROTEUS
for(i=0;i<50;i++)
{
DELAY_T0M2(0XC1,0XC1);//101US *50=5MS
}
LONH=READ_2416(10);//LAMP ON HOUR
LONM=READ_2416(11);//LAMP ON MIN
LOFFH=READ_2416(12);//LAMP OFF HOUR
LOFFM=READ_2416(13);//LAMP OFF MIN
RCMAXB=READ_2416(14);//RECEIVE COIN MAX BATH
RCMAXST=READ_2416(15);//RECEIVE COIN MAX SATANG
if(COIN_MONTH==255)COIN_MONTH=0;
if(NS==255)NS=0;
MONTH=NS*255+COIN_MONTH;
if(COIN_YEAR==255)COIN_YEAR=0;
if(NT==255)NT=0;
if(NTT==255)NTT=0;
YEAR=(NTT*65025)+NT*255+COIN_YEAR;
//WATER DELAY
TIME
if(WTDLS>99)
{
WTDLS=7;//WATER DELAY SEC
}
if(WTDLS_S>99)
{
WTDLS_S=0;//WATER DELAY SEC/100
}
if(WTDLS==0&&WTDLS_S==0)WTDLS=7;
//IF WATER DELAY
12.34SEC
WTDLS1=WTDLS/10;
WTDLS0=WTDLS%10;
WTDLS_S1=WTDLS_S/10;
WTDLS_S0=WTDLS_S%10;
WTDLX=WTDLS*100+WTDLS_S;
//CUT_COIN TIME
if(CCM>99)
{
CCM=5;//CUT_COIN MIN
}
if(CCS>99)
{
CCS=0;//CUT_COIN SEC
}
if(CCM==0&&CCS==0)CCM=5;
//IF CUT_COIN
12.34MIN
//CCM=10;//TEST
//CCS=0;//TEST
CCM1=CCM/10;
CCM0=CCM%10;
CCS1=CCS/10;
CCS0=CCS%10;
CCX=CCM*100+CCS;
//CUT_COIN TIME
//IF VALUE long
MUST HAVE(long),IF NO VALUE=int
//IF VALUE
int,(int)HAVE NO HAVE OK
//CCM=11;//TEST
//CCS=0;//TEST
CCX=(long)CCM*12000;//12000N=MIN 1N=5MS
CCX=CCX+CCS*200;//200N=SEC 1N=5MS
//CCX=1000;//TEST
//LAMP ON TIME
if(LONH>99)
{
LONH=18;//LAMP
ON HOUR
}
if(LONM>99)
{
LONM=0;//LAMP
ON MIN
}
LONH1=LONH/10;
LONH0=LONH%10;
LONM1=LONM/10;
LONM0=LONM%10;
//LAMP ON TIME
if(LOFFH>99)
{
LOFFH=6;
}
if(LOFFM>99)
{
LOFFM=0;
}
LOFFH1=LOFFH/10;
LOFFH0=LOFFH%10;
LOFFM1=LOFFM/10;
LOFFM0=LOFFM%10;
//RECEIVE COIN
MAX
if(RCMAXB>99)
{
RCMAXB=50;//RECEIVE COIN MAX BATH
}
if(RCMAXST>99)
{
RCMAXST=0;//RECEIVE COIN MAX SATANG
}
if(RCMAXB==0&&RCMAXST==0)RCMAXB=50;
//IF RECEIVE
COIN MAX 12.34 BATH
RCMAXB1=RCMAXB/10;
RCMAXB0=RCMAXB%10;
RCMAXST1=RCMAXST/10;
RCMAXST0=RCMAXST%10;
RCMAXX=RCMAXB*100+RCMAXST;
RED_GREEN=0;
PUMP=0;
LAMP=0;
//CUT_COIN=0;//IF USE RELAY
while(1)
{
if(WATER_W==1)
{
BLINK_W=0;
BLINK_T=0;
for(iWDL=0;iWDL<WTDLX;iWDL++)//WATER FLOW MAX 99.99SEC
//WTDLX =MAX
9999
//1SEC
=100*100US*100 =1SEC
{
DELAY_T0M2(0XC5,0XC5);//79US+ORTHER=100US
}
if(COIN_WATER>0)
{
COIN_WATER--;
}
if(COIN_WATER==0)
{
WATER_W=0;
PUMP=0;
}
}
}
}
3 ความคิดเห็น:
สวัสดีครับ ตอนผมทำ Hex file มันเป็นแบบนี้ครับ แก้ยังไงครบ
MODULE: .\Objects\Water.obj (WATER)
*** ERROR L120: CONTENT BELONGS TO ERRONEOUS SEGMENT
SEGMENT: ?PR?MAIN?WATER
MODULE: .\Objects\Water.obj (WATER)
*** ERROR L118: REFERENCE MADE TO ERRONEOUS EXTERNAL
SYMBOL: MAIN
MODULE: C:\KEIL_V5\C51\LIB\C51S.LIB (?C_INIT)
ADDRESS: 2F6DH
*** ERROR L119: REFERENCE MADE TO ERRONEOUS SEGMENT
SEGMENT: ?C_C51STARTUP
MODULE: C:\KEIL_V5\C51\LIB\C51S.LIB (?C_INIT)
ADDRESS: 2FA8H
*** ERROR L120: CONTENT BELONGS TO ERRONEOUS SEGMENT
SEGMENT: ?C_INITSEG
MODULE: C:\KEIL_V5\C51\LIB\C51S.LIB (?C_INIT)
*** FATAL ERROR L250: CODE SIZE LIMIT IN RESTRICTED VERSION EXCEEDED
MODULE: C:\KEIL_V5\C51\LIB\C51S.LIB (-----)
LIMIT: 0800H BYTES
Target not created.
Build Time Elapsed: 00:00:01
ต้องใช้ C51 ตัวเต็ม
และต้องใช้เบอร์ AT89S53
ถ้าเป็นตัวดาวน์โหลดฟรีใช้ไม่ได้เพราะจำกัด
C51 ตัวเต็ม หาชื้อได้ที่ไหนครับ?
แสดงความคิดเห็น