SOURCE CODEตู้น้ำหยอดเหรียญATMEGA16 24C16 CVR UPDATE1
10/2/2558 SONGCHAI PRAPATRUNGSEE
SOURCE CODEตู้น้ำหยอดเหรียญATMEGA16 24C16 CVR UPDATE1
SOURCE CODEตู้น้ำหยอดเหรียญATMEGA16 24C16 CVR UPDATE1
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
ฉ Copyright 1998-2010 Pavel
Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date :
31/12/2012
Author :
Company :
Comments:
Chip type
: ATmega16
Program type
: Application
AVR Core Clock frequency: 8.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 256
*****************************************************/
#include <mega16.h>
#include <delay.h>
// I2C Bus functions
#asm
.equ
__i2c_port=0x18 ;PORTB
.equ __sda_bit=6
.equ
__scl_bit=5
#endasm
#include <i2c.h>
//IF USE _Bool = WATER_W=~WATER_W NOT WORK
//IF USE bit = WATER_W=~WATER_W WORK
// 8MHZ NOT WORK IN PROTEUS7.10
// 4MHZ CAN WORK IN PROTEUS7.10
// Header: WATER MATCHINE
// File Name:
// Author: SONGCHAI PRAPATRUNGSEE
// Date: 15/12/2555
/* WRITE 24256 WORK(AT LEAST 5MS)
DELAY WRITE
24256 AT LEAST 5MS =WORK
DELAY READ
24256 AT LEAST 4.167MS =WORK */
/* SAME AS 2416
DELAY WRITE
2416 AT LEAST 5MS =WORK
BUT SIMULATE
WITH PROTEUS
MUST SET IC
2416 AS 5MS */
//ATMEGA =CRYSTAL/1 =1MATCHINE CYCLE =1COUNT
//IF CRYSTAL =8MHZ =8/1 =8MHZ
//1MATCHINE CYCLE =1/8MHZ =0.125US
//IF YOU WANT TIME 5MS =5MS/0.125US =40000MATCHINE CYCLE
//INTERRUPT EVERY 200HZ =5MS
//200 INTERRUPT =1SEC
//12000 INTERRUPT =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
50 =HH.MM //OFF
THE LAMP
60 =XX.XX //COIN
MAX
70 =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 SET_B PINA.7
#define UP_B PINA.6
#define DOWN_B PINA.5//DOWN/COIN_MONTH//WHEN BLINK PRESS
LONG CLEAR
#define STORE_B PINA.4//NEXT/SAVE/COIN_YEAR
//CONYEAR/WHEN BLINK PRESS LONG CLEAR
#define WATER_B PINA.3
#define WATERNONE_B PINA.2
#define COIN_B PINA.1
#define G_COIN PORTA.0//G_COIN
#define DG0 PORTD.6
#define DG1 PORTD.5
#define DG2 PORTD.4
#define DG3 PORTD.3
#define LAMP PORTD.2
#define PUMP PORTD.1
#define RED_GREEN PORTD.0
unsigned long YEAR;
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
unsigned long CCX;//CONVERT DELAY CUT REMAIN COIN
unsigned 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
unsigned int NMCX=1234;//NUMBER MACHINE
char LONH2,LONH1,LONH0,LONM1,LONM0;
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,};//TOF_4403CMRL-B
unsigned char DIGIT[]={0X3F,0X06,0X5B,0X4F,0X66,
0x6D,0X7D,0X07,0X7F,0X6F};//~ALL SEGMENT
//char DP=0X04;//TOF_4403CMRL-B
char DP=0X80;//~ALL SEGMENT
unsigned char RCMAXB,RCMAXB1,RCMAXB0;
unsigned char RCMAXST,RCMAXST1,RCMAXST0;
unsigned int RCMAXX;
char DGIT;
char HOUR0,HOUR1,MIN0,MIN1,HOUR2,MIN2;
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;
_Bool DS1307_W,COIN_W,CLEARYEAR_W;
_Bool BLINK_W;
_Bool COINSAVE_W;
_Bool UP_L,DOWN_L,MODE;
unsigned 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 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,WATER_W,SAVE_W;
_Bool COIN_L,WATER_L,YEAR_L,STORE_L;
_Bool ST_L,SAVE_L,SET_L,MAXMONTH_L,MAXYEAR_L;
_Bool DIGIT3_W,DIGIT2_W,DIGIT1_W,DIGIT0_W,ZERO_W;
_Bool FIRSTLAMP_W,CHANGE_W,FIRST_W,RCMAX_W;
unsigned char HOUR10,HOUR00,MIN10,MIN00;
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,unsigned char B,
unsigned char C,unsigned char D)
{
switch (DGIT)
{
case 0:
DG0=DG1=DG2=DG3=0;//REAL
DG0=1;
PORTC=A;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
PORTC=B;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
PORTC=C;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
PORTC=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;
PORTC=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
PORTC=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
PORTC=DATA2;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
PORTC=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;
PORTC=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
PORTC=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
PORTC=DATA2;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
PORTC=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;
PORTC=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
PORTC=DATA1;
DGIT=2;
break;
case 2:
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
PORTC=DATA2|DP;
DGIT=3;
break;
case 3:
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
PORTC=DATA3;
DGIT=0;
break;
default:
DGIT=0;
break;
}
}
////////////////////////////////////////////
void WRITE_DS1307(unsigned char ADDRESS,unsigned char
SECYEAR)
{
i2c_start();
i2c_write(0XD0);//D0=ADDRESSS WRITE
i2c_write(ADDRESS);//ADDRESS=0X00=SEC 0X01=MIN............
i2c_write(SECYEAR);//SECYEAR=VARIABLE SECYEAR=SEC MIN..............
i2c_stop();
}
unsigned char READ_DS1307(char ADDRESS)
{
unsigned char
SECYEAR=0;
i2c_start();
i2c_write(0XD0);//D0=ADDRESS WRITE
i2c_write(ADDRESS);//ADDRESS=0X00=SEC 0X01=MIN..................
i2c_stop();
i2c_start();
i2c_write(0XD1);//D1=ADDRESS READ
SECYEAR=i2c_read(0);//IF 1 =READ ERROR
i2c_stop();
return(SECYEAR);//=RETURN VALUE TO FUNCTION
}
void WRITE_2416(unsigned char ADDRESS,unsigned char
DATWR)
{
i2c_start();
i2c_write(0XA0);
i2c_write(ADDRESS);
i2c_write(DATWR);
i2c_stop();
}
unsigned char READ_2416(unsigned char ADDRESS)
{
unsigned char
DATRX;
i2c_start();
i2c_write(0XA0);
i2c_write(ADDRESS);
i2c_start();
i2c_write(0XA1);
DATRX=i2c_read(0);
i2c_stop();
return DATRX;
}
// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
#asm("wdr")//WATCHDOG RESET
// Reinitialize
Timer1 value
TCNT1H=0x63BF
>> 8;
TCNT1L=0x63BF
& 0xff;
// Place your
code here
// 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;
//G_COIN=1;//IF USE RELAY
G_COIN=0;//IF USE TRANSISTER
}
}else
if(WATERNONE_B==1&&RCMAX_W==0)
{
RED_GREEN=0;
//G_COIN=0;//IF USE RELAY
G_COIN=1;//IF USE TRANSISTER
}
if(FIRSTLAMP_W==0)
{
LAMP=1;
if(++FIRST_T>=12000)//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;
//G_COIN=1;//IF USE RELAY
G_COIN=0;//IF USE TRANSISTER
RED_GREEN=1;
}
}else
if(WATERNONE_B==1)
{
//G_COIN=0;//IF USE RELAY
G_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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
switch(SAVE_COIN)
{
case
0://COIN_MONTH
WRITE_2416(1,COIN_MONTH);
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
SAVE_COIN=1;
break;
case
1://NS
WRITE_2416(2,NS);
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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;
//WATER_W=1;//TEST
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++;
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 1
if(COIN_MONTH==255)
{
COIN_MONTH=0;
NS_W=1;
NS++;
//NS=39;//TEST 1
}
}
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 2
if(COIN_YEAR==255)
{
COIN_YEAR=0;
NT++;
NT_W=1;
//NT=254;//TEST
//NT=255;//TEST 2
if(NT==255)
{
NT=0;
NTT++;
//NTT=246;//TEST 2
//NT=15;//TEST 2
NTT_W=1;
}
}
}
//YEAR=(int32)(NTT*65025)+(int32)NT*255+COIN_YEAR;//NOTWORK
YEAR=(unsigned long)((unsigned long)NTT*65025)+
(unsigned long)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)
{
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F
& 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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);
}
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
SAVE_COIN=1;
break;
case
1://NS
if(NS_W==1)
{
NS_W=0;
WRITE_2416(2,NS);
}
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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 REMAIN 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;
PORTC=DIGIT[MIN0];
DISPLAY=1;
break;
case
1://MIN1
DG0=DG1=DG2=DG3=0;//REAL
DG1=1;
PORTC=DIGIT[MIN1];
DISPLAY=2;
break;
case
2://HOUR0
DG0=DG1=DG2=DG3=0;//REAL
DG2=1;
PORTC=DIGIT[HOUR0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
DISPLAY=3;
break;
case
3://HOUR
DG0=DG1=DG2=DG3=0;//REAL
DG3=1;
PORTC=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;
}
PORTC=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;
}
PORTC=DIGIT[HOUR0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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;
}
PORTC=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;
}
PORTC=DIGIT[WTDLS0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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 REMAIN 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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
switch
(WRITE)
{
case
0://CUT REMAIN COIN MIN
WRITE_2416(8,CCM);
WRITE=1;
break;
case
1://CUT REMAIN COIN SEC
WRITE_2416(9,CCS);
WRITE_W=0;
SAVE_W=1;
WRITE=0;
break;
}
}
if(SAVE_W==1)
{
//CUT
REMAIN COIN TIME
if(CCM==0&&CCS==0)
{
CCM0=5;
CCM=5;
}
CCX=(unsigned long)CCM*12000;//12000N=MIN 1N=5MS
CCX=CCX+(unsigned long)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;
}
PORTC=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;
}
PORTC=DIGIT[CCM0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
switch
(WRITE)
{
case
0://CUT REMAIN COIN MIN
WRITE_2416(10,LONH);
WRITE=1;
break;
case
1://CUT REMAIN 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;
}
PORTC=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;
}
PORTC=DIGIT[LONH0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
switch
(WRITE)
{
case
0://CUT REMAIN COIN MIN
WRITE_2416(12,LOFFH);
WRITE=1;
break;
case
1://CUT REMAIN 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;
}
PORTC=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;
}
PORTC=DIGIT[LOFFH0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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;
//TCNT1H=0x63BF >> 8;
//TCNT1L=0x63BF & 0xff;//5MS
//TCNT1H=0x447F >> 8;
//TCNT1L=0x447F & 0xff;//6MS
TCNT1H=0x253F >> 8;
TCNT1L=0x253F & 0xff;//7MS
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;
}
PORTC=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;
}
PORTC=DIGIT[RCMAXB0];
if(BLINK_W==0)
{
PORTC=PORTC|DP;
}
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;
}
PORTC=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;
}
PORTC=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;
}
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In
Func1=In Func0=Out
// State7=P State6=P State5=P State4=P State3=P State2=P
State1=P State0=0
PORTA=0B11111100;
DDRA=0x01;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In
Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T
State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out
Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0
State1=0 State0=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out
Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0
State1=0 State0=0
PORTD=0x00;
DDRD=0xFF;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 8000.000 kHz
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x01;
TCNT1H=0x63;
TCNT1L=0xBF;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1:
Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Watchdog Timer initialization
// Watchdog Timer Prescaler: OSC/2048k =1.8 SEC
#pragma optsize-
WDTCR=0x1F;
WDTCR=0x0F;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// I2C Bus initialization
i2c_init();
// Global enable interrupts
#asm("sei")
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 REMAIN COIN MIN
CCS=READ_2416(9);//CUT REMAIN COIN SEC
//DELAY IF NO,
LONH READ ERROR=BUG OF PROTEUS
for(i=0;i<50;i++)
{
delay_us(100);//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
//COIN_MONTH=45;//TEST
//NS=10;//TEST
if(COIN_MONTH==255)COIN_MONTH=0;
if(NS==255)NS=0;
//MONTH=NS*255+COIN_MONTH;//NOT WORK
MONTH=NS*255+COIN_MONTH;
if(COIN_YEAR==255)COIN_YEAR=0;
if(NT==255)NT=0;
if(NTT==255)NTT=0;
//YEAR=(int32)(NTT*65025)+NT*255+COIN_YEAR;//NOT WORK
YEAR=(unsigned
long)((unsigned long)NTT*65025)+
(unsigned
long)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 REMAIN
COIN TIME
if(CCM>99)
{
CCM=5;//CUT
REMAIN COIN MIN
}
if(CCS>99)
{
CCS=0;//CUT
REMAIN COIN SEC
}
if(CCM==0&&CCS==0)CCM=5;
//IF CUT REMAIN
COIN 12.34MIN
//CCM=10;//TEST
//CCS=0;//TEST
CCM1=CCM/10;
CCM0=CCM%10;
CCS1=CCS/10;
CCS0=CCS%10;
//CCX=(int32)CCM*100+CCS;
//CUT REMAIN
COIN TIME
//IF VALUE int32
MUST HAVE(int32),IF NO VALUE=int
//IF VALUE
int,(int)HAVE NO HAVE OK
//CCM=11;//TEST
//CCS=0;//TEST
CCX=(unsigned
long)CCM*12000;//12000N=MIN 1N=5MS
CCX=CCX+(unsigned long)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;
while (1)
{
// Place
your code here
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_us(90);//90US+ORTHER=100US
}
if(COIN_WATER>0)
{
COIN_WATER--;
}
if(COIN_WATER==0)
{
WATER_W=0;
PUMP=0;
}
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น