SOURCE CODEหยอดเหรียญเครื่องซักผ้าATMEGA48V
EEPROM CVR UPDATE1
10/2/2558 SONGCHAI PRAPATRUNGSEE
SOURCE CODEหยอดเหรียญเครื่องซักผ้าATMEGA48V
EEPROM 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 :CAPER
Version :
Date : 5/8/2012
-7/8/2012 REVISION
Author :
Company :
Comments:
Chip type
: ATmega48V
AVR Core Clock frequency: 8.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 128
*****************************************************/
#include <mega48.h>
#include <delay.h>
//eeprom int NE @0x80;//COIN X BATH
//eeprom int PE @0x90;//+5, +10
//eeprom int LE @0x70;//LEVEL WATER X TIME
eeprom char NCE;//NUMBER COIN EEPROM
eeprom char PLE;//PLUS EEPROM
eeprom char LVE;//LEVEL EEPROM
#define DG1 PORTB.0
#define DG0 PORTB.1
#define SETCOIN_B PINB.2
#define SETLEVEL_B PINB.3
#define COIN_B PINC.0
#define GROUND_COIN PORTC.1
#define POWER PORTC.2
#define LEVEL PORTC.3
#define START PORTC.4
#define STB_NUMBER PINC.5
// Declare your global variables here
int NCX;//COIN X BATH
int LVX;//LEVEL WATER X TIME
char PLX;//PLUS +5, +10
//unsigned char DIGIT[]={0X10,0XB6,0X28,0X22,0X86,0X42,
//
0X40,0X36,0X00,0X02,0XFF};//TOD-5261HMR-B
unsigned char
DIGIT[]={~0X3F<<1,~0X06<<1,~0X5B<<1,~0X4F<<1,~0X66<<1,
~0x6D<<1,~0X7D<<1,~0X07<<1,~0X7F<<1,~0X6F<<1};//~ALL
SEGMENT
unsigned char DGIT,NUMBER,BLINK_T,N;
unsigned char DATA0,DATA1,i,j,NUMSAVE;
unsigned char
SETCOIN_T,SELECTCOIN_T,SETLEVEL_T,SELECTLEVEL_T;
unsigned int TIME,COIN_T;
_Bool BLINK1_W,COL0_W,MATCHINE_W,CHECK_W,SETCOIN_W;
_Bool SET5_W,SET10_W,UP5_W,UP10_W,SAVECOIN_W;
_Bool SETLEVEL_W,SAVELEVEL_W,SAVE_W,NORMAL_W;
_Bool COIN_L,NUMBER_L,CHECK_L,FIRST_L,FIRSTUP_L;
_Bool FIRST2_L,BLINK3_W,BLINK2_W;
void CONVERT_DEC_TO_UNIT(unsigned char NUMBER)
{
unsigned char
NUM;
NUM=((NUMBER%100)/10);//SIB
DATA1=DIGIT[NUM];
NUM=NUMBER%10;//NAUY
DATA0=DIGIT[NUM];
}
void CUT_ZERO()
{
if(DATA1==DIGIT[0])
{
DATA1=0XFF;
}
}
void DISPLAY(unsigned char NUMBER)
{
CONVERT_DEC_TO_UNIT(NUMBER);
CUT_ZERO();
switch (DGIT)
{
case 0:
DG0=DG1=1;
DG0=0;
PORTD=DATA0;
DGIT=1;
break;
case 1:
DG0=DG1=1;
DG1=0;
PORTD=DATA1;
DGIT=0;
break;
default:
DGIT=0;
break;
}
}
// Timer1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer1 value
TCNT1H=0x63;
TCNT1L=0xBF;
// Place your code here
#asm("wdr") //WATCHDOG RESET
if(SETCOIN_B==0&&FIRST_L==0)
{
if(++SETCOIN_T>=20)//100MS
{
SETCOIN_T=0;
FIRST_L=1;
SETCOIN_W=1;
NORMAL_W=1;
TIME=0;
CHECK_W=0;
BLINK1_W=0;
BLINK2_W=0;//BLINK NUMBER
NUMBER_L=0;
NUMBER=0;
GROUND_COIN=1;
}
}else
if(SETCOIN_B==1)
{
SETCOIN_T=0;
}else
if(SETCOIN_B==0)
{
SELECTCOIN_T=0;
}
if(SETLEVEL_B==0&&FIRST_L==0)
{
if(++SETLEVEL_T>=20)//100MS
{
SETLEVEL_T=0;
FIRST_L=1;
SETLEVEL_W=1;
NORMAL_W=1;
TIME=0;
CHECK_W=0;
BLINK1_W=0;
BLINK2_W=0;//BLINK NUMBER
NUMBER_L=0;
NUMBER=0;
GROUND_COIN=1;
}
}else
if(SETLEVEL_B==1)
{
SETLEVEL_T=0;
}else
if(SETLEVEL_B==0)
{
SELECTLEVEL_T=0;
}
////////////////////////////////////////////////////////////////
if(SETCOIN_W==1)//BLINK5 BLINK10
{
if(BLINK1_W==0)//BLINK 5
{
if(SETCOIN_B==1)
{
if(++SELECTCOIN_T>=20)//100MS
{
SELECTCOIN_T=0;
SETCOIN_W=0;
SET5_W=1;
}
}
DISPLAY(5);
if(++BLINK_T>=200)//500MS
{
BLINK_T=0;
BLINK1_W=1;
}
}else
if(BLINK1_W==1)//BLINK 10
{
if(SETCOIN_B==1)
{
if(++SELECTCOIN_T>=20)//100MS
{
SELECTCOIN_T=0;
SETCOIN_W=0;
SET10_W=1;
}
}
DISPLAY(10);
if(++BLINK_T>=200)//500MS
{
BLINK_T=0;
BLINK1_W=0;
}
}
}
///////////////////////////////////////////////////////////////
if(SETLEVEL_W==1)
{
if(FIRST2_L==0)
{
FIRST2_L=1;
i=1;
}
if(SETLEVEL_B==1)
{
if(++SELECTLEVEL_T>=200)//1000MS
{
SELECTLEVEL_T=0;
SETLEVEL_W=0;
SAVE_W=1;
SAVELEVEL_W=1;
}
}else
{
if(i>9)i=1;
if(++SETLEVEL_T>=200)//1S
{
SETLEVEL_T=0;
i++;
}
}
DISPLAY(i);
}
///////////////////////////////////////////////////////////////
if(NORMAL_W==0)//NORMAL MODE
{
if(CHECK_W==1)
{
if(STB_NUMBER==0)
{
if(++TIME>=1000)//200=1SEC
{
TIME=0;
CHECK_W=0;
BLINK1_W=0;
BLINK2_W=0;//BLINK NUMBER
NUMBER_L=0;
NUMBER=0;
GROUND_COIN=1;
}
}
}
if(COIN_B==0&&COIN_L==0)
{
if(++COIN_T>=4)//DELAY 20MS
{
COIN_T=0;
COIN_L=1;
CHECK_L=0;
BLINK1_W=1;
BLINK3_W=0;
BLINK_T=0;
NUMBER=NUMBER+PLX;
}
}else
if(COIN_B==1)
{
COIN_T=0;
COIN_L=0;
}
if(BLINK1_W==0)//BLINK0 BLINK0
{
if(COL0_W==0)
{
DISPLAY(0);
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
COL0_W=1;
}
}else
if(COL0_W==1)
{
DG0=DG1=1;
DG1=0;
PORTD=DIGIT[0];
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
COL0_W=0;
}
}
}else
if(BLINK1_W==1)//BLINK0 STOP
{
if(BLINK2_W==0)
{
if(++BLINK_T>=100)
{
BLINK_T=0;
BLINK3_W=~BLINK3_W;
}
if(BLINK3_W==0)
{
DISPLAY(NUMBER);
}else DG0=DG1=1;
}else
{
DISPLAY(NUMBER);
}
if(NUMBER>=NCX&&NUMBER_L==0)
{
NUMBER_L=1;
BLINK2_W=1;
MATCHINE_W=1;
}
}
}
////////////////////////////////////////////////////////////////
if(SET5_W==1)//MODE 5BATH BLINK 5
{
if(BLINK1_W==0)
{
if(SETCOIN_B==0)
{
if(++SETCOIN_T>=20)//100MS
{
SETCOIN_T=0;
UP5_W=1;
SET5_W=0;
}
}
DISPLAY(5);
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
BLINK1_W=1;
}
}else//BLINK
SPACE
{
DG0=DG1=1;
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
BLINK1_W=0;
if(N++>=10)//N TIME EXIT
{
N=0;
SETCOIN_W=0;
SET5_W=0;
FIRST_L=0;
NORMAL_W=0;
}
}
}
}
if(UP5_W==1)
{
if(FIRSTUP_L==0)
{
FIRSTUP_L=1;
NUMSAVE=5;
}
DISPLAY(NUMSAVE);
if(SETCOIN_B==1)
{
if(++SELECTCOIN_T>=200)//1SEC
{
SELECTCOIN_T=0;
SAVE_W=1;
PLX=5;//+5
SAVECOIN_W=1;
}
}else
{
if(++TIME>=200)
{
TIME=0;
NUMSAVE=NUMSAVE+10;
if(NUMSAVE>=100)NUMSAVE=5;
}
}
}
/////////////////////////////////////////////////////////
if(SET10_W==1)//MODE 10BATH BLINK10
{
if(BLINK1_W==0)
{
if(SETCOIN_B==0)
{
if(++SETCOIN_T>=20)//100MS
{
SETCOIN_T=0;
UP10_W=1;
SET10_W=0;
}
}
DISPLAY(10);
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
BLINK1_W=1;
}
}else//BLINK
SPACE
{
DG0=DG1=1;
if(++BLINK_T>=100)//500MS
{
BLINK_T=0;
BLINK1_W=0;
if(N++>=10)//N TIME EXIT
{
N=0;
SETCOIN_W=0;
SET10_W=0;
FIRST_L=0;
NORMAL_W=0;
}
}
}
}
if(UP10_W==1)
{
if(FIRSTUP_L==0)
{
FIRSTUP_L=1;
NUMSAVE=10;
}
DISPLAY(NUMSAVE);
if(SETCOIN_B==1)
{
if(++SELECTCOIN_T>=200)//1SEC
{
SELECTCOIN_T=0;
SAVE_W=1;
PLX=10;//+10
SAVECOIN_W=1;
}
}else
if(++TIME>=200)
{
TIME=0;
NUMSAVE=NUMSAVE+10;
if(NUMSAVE>=100)NUMSAVE=10;
}
}
}
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=In
Func2=In Func1=In Func0=In
// State7=T State6=T State5=0 State4=0 State3=T State2=T
State1=T State0=P
//PORTB=0x00;
//DDRB=0x30;
// Port C initialization
// Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out
Func1=Out Func0=Out
// State6=0 State5=0 State4=0 State3=0 State2=0 State1=0
State0=0
///PORTC=0x00;
//DDRC=0x7F;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In
Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=1 State3=P State2=P
State1=P State0=P
//PORTD=0x1F;
//DDRD=0xF0;
/////////////////////////////////////////////////////////////
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In
Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=P State2=P
State1=0 State0=0
PORTB=0x0C;
DDRB=0x03;
// Port C initialization
// Func6=In Func5=In Func4=Out Func3=Out Func2=Out
Func1=Out Func0=In
// State6=T State5=P State4=0 State3=0 State2=0 State1=0
State0=P
PORTC=0x21;
DDRC=0x1E;
PORTD=0xFF;
DDRD=0xFE;
// 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 1 Interrupt(s) initialization
TIMSK1=0x01;
//// Watchdog Timer initialization
//// Watchdog Timer Prescaler: OSC/1024k
//// Watchdog Timer interrupt: Off
//#pragma optsize-
//#asm("wdr")
//WDTCSR=0x39;
//WDTCSR=0x29;
//#ifdef _OPTIMIZE_SIZE_
//#pragma optsize+
//#endif
WDTCSR=0x18;//SET WATCHDOG ENABLE, WATCHDOG CHANGE
WDTCSR=0x29;//SET WATCHDOG TIME
// Global enable interrupts
#asm("sei")
NCX=NCE;//NUMBER COIN X BATH
PLX=PLE ;//PLUS =+5, +10
LVX=LVE ;//LEVEL
GROUND_COIN=1;
while (1)
{
// Place your code here
if(MATCHINE_W==1)
{
GROUND_COIN=0;
POWER=1;
delay_ms(1000);
POWER=0;
delay_ms(1000);
for(j=0;j<LVX;j++)
{
LEVEL=1;
delay_ms(1000);
LEVEL=0;
delay_ms(1000);
}
START=1;
delay_ms(1000);
START=0;
delay_ms(1000);
MATCHINE_W=0;
CHECK_W=1;
}
if(SAVE_W==1)
{
if(SAVELEVEL_W==1)
{
SAVELEVEL_W=0;
LVE=i;
LVX=i;
delay_ms(1000);
}else
if(SAVECOIN_W==1)
{
SAVECOIN_W=0;
NCE=NUMSAVE;
PLE=PLX;
NCX=NUMSAVE;
delay_ms(1000);
UP5_W=0;
UP10_W=0;
}
for(i=0;i<100;i++)
{
DG0=DG1=1;
DG0=0;
PORTD=0X04;//A
delay_ms(5);
DG0=DG1=1;
DG1=0;
PORTD=0X42;//S
delay_ms(5);
}
FIRST_L=0;
FIRSTUP_L=0;
NUMSAVE=0;
SAVE_W=0;
TIME=0;
NORMAL_W=0;
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น