📄 main.c
字号:
MacheineSleepReady = 1;
MacheineSleepCount = 0;
}
}
void main(void)
{
byte i,input;
unsigned int j;
unsigned int i_delay;
// Initialize system
InitSystems();
// enable interrupts
EnableInterrupts;
// Initialize I/O
InitIO();
// Initialize timer(TPM)
InitTimer();
// Initialize keyboard interrupt
InitKBI();
// Initialize ISD4002
SPI1Init();
// Initialize device
InitDevice();
Display_timer1_start();
CoinOutput_timer2_start();
compute_win_rate();
while(1)
{
if( ((Group0_key_pressed==0) && ((!PTCD_PTCD0) && Count_CoinInput) || (IsFixedTimeOut)))
{
if(!IsGameStart)
{
Update_Display_Period(0, 1);
// Initialization
GameStart(0);
IsFixedTimeOut = 0;
}
}
if(IsGameStart)
{
if( (!PTFD_PTFD5) || (output_random == CINKER)) // 锤子键
{
IsYellowLEDsFlash = 0;
CurrentFlashCount = 0;
PTFD_PTFD2 = 1;
PTED_PTED4 = 0;
PTFD_PTFD1 = 0;
Game_Result = Compute_GameResult( CINKER, Count_CoinInput, &machine_output, IsMachineRandOut);
IsPeopleActed = YES;
Count_Game = 0;
output_random = 0xff;
}
else if( (!PTFD_PTFD6) || (output_random == CUT) ) // 剪刀键
{
IsYellowLEDsFlash = 0;
CurrentFlashCount = 0;
PTED_PTED4 = 1;
PTFD_PTFD2 = 0;
PTFD_PTFD1 = 0;
Game_Result = Compute_GameResult( CUT, Count_CoinInput, &machine_output, IsMachineRandOut);
IsPeopleActed = YES;
Count_Game = 0;
output_random = 0xff;
}
else if( (!PTFD_PTFD7) || (output_random == CLOTH) ) // 布
{
IsYellowLEDsFlash = 0;
CurrentFlashCount = 0;
PTFD_PTFD1 = 1;
PTFD_PTFD2 = 0;
PTED_PTED4 = 0;
Game_Result = Compute_GameResult( CLOTH, Count_CoinInput, &machine_output, IsMachineRandOut);
IsPeopleActed = YES;
Count_Game = 0;
output_random = 0xff;
}
if( IsPeopleActed )
{
stopPlay();
if(machine_output == CINKER)
{
PTJD_PTJD0 = 1;
}
else if(machine_output == CUT)
{
PTDD_PTDD4 = 1;
}
else if(machine_output == CLOTH)
{
PTDD_PTDD3 = 1;
}
if(Game_Result == GAME_WIN)
{
Update_LEDs_Data(3, 10, DISPLAY_GAP);
Update_Display_Period(1, DISPLAY_GAP);
Update_Display_Period(2, DISPLAY_GAP);
i_DisplayCount[1] = 0;
i_DisplayCount[2] = 0;
i_DisplayCount[3] = 0;
// delay 1s
// delay_s(1);
for(j=0;j<0xfff;j++);
if(Count_CoinInput<=4)
{
play(0x7f);
}
else if(Count_CoinInput<=8)
{
play(0x30);
play(0x8b);
}
else
{
play(0x30);
play(0x97);
}
// output coin
machine_status = coin_output( CoinOutput_table[Count_CoinInput]);
Gamer_Total_Win += (CoinOutput_table[Count_CoinInput]-Count_CoinInput);
if(machine_status == ERROR)
{
play(0x30);
play(0x6c);
while(1)
{
}
}
else
{
Update_Display_Period(3, 1);
Update_Display_Period(1, 1);
Update_Display_Period(2, 1);
}
}
else if(Game_Result == GAME_FAIL)
{
Update_LEDs_Data(3, 11, DISPLAY_GAP);
Machine_Total_Win += Count_CoinInput;
// delay 1s
// delay_s(1);
for(j=0;j<0xfff;j++);
play(0x30);
play(0xa4);
}
else if(Game_Result == GAME_EVEN)
{
// delay 1s
// delay_s(1);
for(j=0;j<0xfff;j++);
play(0x30);
play(0xb3);
}
Game_restart( Game_Result );
}
}
if((!IsMacheineNotSleep) && ( (CurrCom012Sleep== 20) || (CurrCom012Sleep== 80)) )
{
if(CurrCom012Sleep== 20)
{
play(0x30);
play(0x00);
}
else
{
play(0x30);
play(0x0a);
}
}
if(Group0_key_pressed && Group0_key_debounced)
{
input = PTAD;
if( (input & 0x4) == 0) // PTA2 cornnect Coin_Out_Service button
{
IsMacheineNotSleep = 1;
PTGD_PTGD6 = 1;
PTGDD_PTGDD6 = 1;
while( (PTAD & 0x4) == 0 );
PTGD_PTGD6 = 0;
PTGDD_PTGDD6 = 1;
}
else if( (input & 0x8) == 0 ) // PTA3 connect Coin_In button
{
if(!IsGameStart)
{
Count_CoinInput++;
if(Count_CoinInput == 1)
{
srand(TPM2CNT);
}
IsMacheineNotSleep = 1;
MacheineSleepReady = 0;
MacheineSleepCount = 0;
IsCoinIn_start = 1;
if(IsCoinIn_start)
{
Count_CoinIn = 0;
}
if(Count_CoinInput==2)
{
play(0x30);
play(0x1c);
}
else
{
play(0x7a);
}
Update_LEDs_Data(0, Count_CoinInput, DISPLAY_GAP);
Update_LEDs_Data(1, Display[Count_CoinInput][1], 1);
Update_LEDs_Data(2, Display[Count_CoinInput][2], 1);
// 2008-04-06
PTGD_PTGD4 = 1;
PTGDD_PTGDD4 = 1;
delay_50ms();
PTGD_PTGD4 = 0;
if(Count_CoinInput >= 9)
{
Update_Display_Period(0, 1);
GameStart(0);
}
}
while( (PTAD & 0x8) == 0 );
}
else if( (input & 0x2) == 0 ) // PTA1 connect Coin_In_Service button
{
IsMacheineNotSleep = 1;
Count_CoinInput++;
PTGD_PTGD4 = 1;
PTGDD_PTGDD4 = 1;
delay_50ms();
PTGD_PTGD4 = 0;
Update_LEDs_Data(0, Count_CoinInput, 1);
Update_LEDs_Data(1, Display[Count_CoinInput][1], 1);
Update_LEDs_Data(2, Display[Count_CoinInput][2], 1);
while( (PTAD & 0x2) == 0 );
}
/* 2008-04-06
Group0_key_debounced = NO;
// timer3 start
Debounce_timer3_start();
// debounce key
while (!Group0_key_debounced);
*/
Group0_key_pressed = NO;
Group0_key_debounced = NO;
KBI1SC_KBIE = 1; // enable KBI1 interrupts
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -