📄 zj__.c
字号:
#include <Mega16.h>
#define BIT( x ) ( 1 << x )
#include "uart.h"
#include "vox.h"
#define HC273_LED_VAL 0
#define HC273_PNT_VAL 1
#define HC273_LED_CS 2
#define HC273_LAMP 3
#define HC245_IN_KEY 4
#define HC245_IN_SENSOR 5
#define HC245_KEYS 6
#define HC245_SW1 7
#define HC245_SW2 8
const unsigned char con_fenji_count[8] = { 8 , 12 , 16 , 18 , 24 , 30 , 36 , 64 } ;
#define MAXCNT_SAM 5
volatile unsigned char in_key_sam[MAXCNT_SAM] , in_sensor_sam[MAXCNT_SAM] ;
volatile unsigned char sam_cnt ;
volatile unsigned char in_key_old , in_key_new , in_key_down ;
volatile unsigned char in_sensor_old , in_sensor_new , in_sensor_down ;
volatile unsigned char keys_old , keys_new , keys_down ;
volatile unsigned char sw1_old , sw2_old ;
#define MAXTIME_INHOLE1 5
#define MAXTIME_INHOLE2 3
volatile unsigned char time_long[COLOR_COUNT] ;
#define KEY1_CLICK ( keys_down & 0x10 )
#define KEY2_CLICK ( keys_down & 0x20 )
#define KEY3_CLICK ( keys_down & 0x40 )
#define KEY1_DOWN ( ( ~ keys_old ) & 0x10 )
#define KEY2_DOWN ( ( ~ keys_old ) & 0x20 )
#define KEY3_DOWN ( ( ~ keys_old ) & 0x40 )
volatile unsigned char time_10ms , time_50ms , time_1s , time_cnt , time_delay ;
volatile unsigned char time_add ,time_add1 , time_long1 , time_long2 ;
#define MAXTIME_FLASH 2
volatile unsigned char time_flash , led_no ;
/* 显示数字、字母 */
const char byte_model[] = { 0x3f , 0x6 , 0x5b , 0x4f , 0x66 , 0x6d , 0x7d , 0x7 , 0x7f , 0x6f , 0x77 , 0x7c , 0x39 , 0x5e , 0x79 , 0x71 , 0x50 , 0x40 , 0x38 , 0x73 } ;
#define LED_R 0x10
#define LED_Minus 0x11
#define LED_L 0x12
#define LED_P 0x13
#define LED_OFF 0xff
const unsigned char music_player[36] = { VOX_PLAY1 , VOX_PLAY2 , VOX_PLAY3 , VOX_PLAY4 , VOX_PLAY5 , VOX_PLAY6 , VOX_PLAY7 , VOX_PLAY8 , VOX_PLAY9 , VOX_PLAY10 ,
VOX_PLAY11 , VOX_PLAY12 , VOX_PLAY13 , VOX_PLAY14 , VOX_PLAY15 , VOX_PLAY16 , VOX_PLAY17 , VOX_PLAY18 , VOX_PLAY19 , VOX_PLAY20 ,
VOX_PLAY21 , VOX_PLAY22 , VOX_PLAY23 , VOX_PLAY24 , VOX_PLAY25 , VOX_PLAY26 , VOX_PLAY27 , VOX_PLAY28 , VOX_PLAY29 , VOX_PLAY30 ,
VOX_PLAY31 , VOX_PLAY32 , VOX_PLAY33 , VOX_PLAY34 , VOX_PLAY35 , VOX_PLAY36 } ;
const unsigned char music_color[8] = { VOX_GOLD1 , VOX_RED , VOX_BLACK , VOX_WHITE , VOX_ORANGE , VOX_PINK , VOX_YELLOW , VOX_GREEN } ;
volatile unsigned char music ;
bit printtype ;
bit wait_music ;
bit check_fen , print_count , no_printer ;
bit blink_on , count_flag;
#define NO_RESULT 9
#define RESULT_GOLD 0
#define ERR_NONE 0
#define MAXTIME_BOARDCOLOR 13
#define MAXTIME_GETACC 11
#define MAXTIME_PRINT 100
#define ERR_SELFTEST 1
volatile unsigned char statue_sys , errcode , result , max_fj ;
volatile unsigned char time_boardcolor ;
volatile unsigned char time_get_account ;
volatile unsigned char time_print ;
union
{
unsigned long int dblword ;
unsigned int word[2] ;
unsigned char byte[4] ;
} zsf_long , ztf_long ;
volatile signed long int pnt_zj , this_earn , last_earn , between_earn ;
const signed char chn_title[] = "欢迎使用抛球至尊" ;
const signed char chn_zsf[] = "总上分:" ;
const signed char chn_ztf[] = "总退分:" ;
const signed char chn_xj[] = "小 计:" ;
const signed char chn_zj[] = "总 计:" ;
const signed char chn_fj[] = "号分机:" ;
const signed char chn_finish[] = "打印完成" ;
const signed char chn_xh[] = "序 号:" ;
volatile unsigned int max_yz , max_yz_temp ;
volatile unsigned char max_yz_player ;
volatile unsigned char time_blink , on_fjs ;
volatile unsigned char time_welcome ;
#define TEST_NONE 0
#define TEST_SET_COLOR 1
#define TEST_SETPL_1 2
#define TEST_SETPL_2 3
#define TEST_SETPL_3 4
#define TEST_SETPL_4 5
#define MAX_TEST 6
#define MAX_CHECK 8
#define MAX_SET 9
#define SET_LIMIT_YF 1
#define SET_LIMIT_YF1 2
#define SET_LIMIT_YF2 3
#define SET_LIMIT_YF3 4
#define SET_LIMIT_YF4 5
#define SET_LIMIT_YF5 6
#define SET_FIRST_YF 7
#define SET_SECOND_YF 8
volatile unsigned char testmode , checkmode ;
volatile unsigned char color_order[COLOR_COUNT] ;
volatile unsigned int color_pl[COLOR_COUNT] ;
const unsigned char con_color_pl[COLOR_COUNT] = { 30 , 10 , 1 , 1 } ;
volatile unsigned char test_temp ;
volatile unsigned char setmode ;
eeprom unsigned char bianma = 0 ,bianma1 = 0, bianma2 = 0 ;
eeprom unsigned char eep_color_order[COLOR_COUNT] = { 1 , 2 , 3 , 4 } ;
eeprom unsigned int eep_color_pl[COLOR_COUNT] = { 30 , 10 , 1 , 1 } ;
eeprom unsigned long int last_zsf = 0 , last_ztf = 0 , this_zsf = 0 , this_ztf = 0 , bianhao = 1 ;
eeprom unsigned int first_yf = 0xffff , second_yf = 0xffff , limit_yf = 0xffff , limit_yf1 = 0xffff , limit_yf2 = 0xffff , limit_yf3 = 0xffff , limit_yf4 = 0xffff , limit_yf5 = 0xffff ;
#define PNT_SIZE 45
volatile unsigned char pnt_buf[PNT_SIZE] ;
volatile unsigned char pnt_in , pnt_read ;
volatile unsigned char time_countdown , time_voice ;
const unsigned char con_maxtime_countdown[] = { 20 , 30 , 40 , 50 } ;
void write273( unsigned char no , unsigned char value )
{
PORTA = value ;
DDRA = 0xff ;
#asm("nop") ;
PORTC |= BIT( no ) ;
#asm("nop") ;
PORTC = 0xf0 ;
DDRA = 0 ;
}
unsigned char xianxi( unsigned char no , signed long int value )
{
unsigned char r1 ;
unsigned long int t1 ;
if( value < 0 )
{
value = 0 - value ;
}
t1 = 1 ;
for( r1=0 ; r1 < no ; r1 ++ )
{
t1 = t1 * 10 ;
}
if( value >= t1 )
{
r1 = ( value % ( t1 * 10 ) ) / t1 ;
}
else
{
r1 = 0xff ;
if( no == 0 )
{
r1 = 0 ;
}
}
return r1 ;
}
unsigned char read245( unsigned char no )
{
unsigned char r1 ;
if ( no < 8 )
{
PORTC &= ~ BIT( no ) ;
#asm("nop") ;
r1 = PINB ;
PORTC = 0xf0 ;
}
else
{
PORTD.6 = 0 ;
#asm("nop") ;
r1 = PINB ;
PORTD.6 = 1 ;
}
return r1 ;
}
void write_led( unsigned char value )
{
if(led_no>=6)
{
write273( HC273_LED_CS , 0 ) ;
if ( result != NO_RESULT )
{
if ( blink_on )
{
write273( HC273_LAMP , BIT( result+2 ) | BIT( led_no-6 ) ) ;
}
else
{
write273( HC273_LAMP , BIT( led_no-6 ) ) ;
}
}
else
{
write273( HC273_LAMP , BIT( led_no-6 ) ) ;
}
// write273( HC273_LAMP , BIT( led_no-6 ) ) ;
//else
//{
//} // 2,由led_no决定显示哪个数码管
if ( value < sizeof( byte_model ) )
{
write273( HC273_LED_VAL , byte_model[value] ) ;//0,
}
else
{
write273( HC273_LED_VAL , 0 ) ;
}
}
else
{
write273( HC273_LAMP , 0 ) ;
if ( result != NO_RESULT )
{
if ( blink_on )
{
write273( HC273_LAMP , BIT( result+2 ) ) ;
}
}
write273( HC273_LED_CS , BIT( led_no ) ) ;
// 2,由led_no决定显示哪个数码管
if ( value < sizeof( byte_model ) )
{
write273( HC273_LED_VAL , byte_model[value] ) ;//0,
}
else
{
write273( HC273_LED_VAL , 0 ) ;
}
}
}
void write_pnt( unsigned char value )
{
write273( HC273_PNT_VAL , value ) ; // 打印机将数据读入
PORTD.7 = 0 ;
#asm("nop") ;
PORTD.7 = 1 ;
}
void write_com6295( unsigned char value )
{
PORTA = value ;
DDRA = 0xff ;
PORTD.4 = 0 ;
PORTD.2 = 0 ;
#asm("nop") ;
#asm("nop") ;
#asm("nop") ;
#asm("nop") ;
PORTD.2 = 1 ;
PORTD.4 = 1 ;
DDRA = 0 ;
}
/*
#define NO_SOUND ( ( read_com6295() & 0x1 ) == 0 )
unsigned char read_com6295( void )
{
unsigned char r1 ;
PORTD.4 = 0 ;
PORTD.3 = 0 ;
#asm("nop") ;
#asm("nop") ;
#asm("nop") ;
#asm("nop") ;
r1 = PINA ;
PORTD.3 = 1 ;
PORTD.4 = 1 ;
return ( r1 & 0xf ) ;
}
*/
void Play_Music( unsigned char Music_Num , unsigned char Chanel_Num , unsigned char Vol )
{
/*
Chanel_Num 1 - 4
Vol 0 - 15
*/
unsigned char i ;
Chanel_Num = Chanel_Num << 3 ;
write_com6295( Chanel_Num ) ; //stop this channel
for ( i = 0; i < 100; i ++ );
if ( Music_Num > VOX_PAGE0_MAX )
{
Music_Num -= VOX_PAGE0_MAX ;
PORTD.5 = 1 ;
}
else
{
PORTD.5 = 0 ;
}
Music_Num |= 0x80 ;
write_com6295( Music_Num ) ;
Chanel_Num = Chanel_Num << 1 ;
Chanel_Num |= Vol ;
write_com6295( Chanel_Num ) ;
}
void switch_music( unsigned char value )
{
music = value ;
wait_music = 1 ;
}
void change_statue( unsigned char statue )
{
unsigned char c1 ;
statue_sys = statue ;
parm[0] = statue ;
send_order( BOARD_IP , CMD_SEND_STATUE ) ; // 0,1
check_send();
switch( statue )
{
case ZJ_WELCOME :
parm[0] = (unsigned char)( limit_yf & 0x7f ) ;
parm[1] = (unsigned char)( ( limit_yf >> 7 ) & 0x7f ) ;
parm[2] = (unsigned char)( ( limit_yf >> 14 ) & 0x7f ) ;
parm[3] = (unsigned char)( limit_yf1 & 0x7f ) ;
parm[4] = (unsigned char)( ( limit_yf1 >> 7 ) & 0x7f ) ;
parm[5] = (unsigned char)( ( limit_yf1 >> 14 ) & 0x7f ) ;
parm[6] = (unsigned char)( limit_yf2 & 0x7f ) ;
parm[7] = (unsigned char)( ( limit_yf2 >> 7 ) & 0x7f ) ;
parm[8] = (unsigned char)( ( limit_yf2 >> 14 ) & 0x7f ) ;
parm[9] = (unsigned char)( limit_yf3 & 0x7f ) ;
parm[10] = (unsigned char)( ( limit_yf3 >> 7 ) & 0x7f ) ;
parm[11] = (unsigned char)( ( limit_yf3 >> 14 ) & 0x7f ) ;
parm[12] = (unsigned char)( limit_yf4 & 0x7f ) ;
parm[13] = (unsigned char)( ( limit_yf4 >> 7 ) & 0x7f ) ;
parm[14] = (unsigned char)( ( limit_yf4 >> 14 ) & 0x7f ) ;
parm[15] = (unsigned char)( limit_yf5 & 0x7f ) ;
parm[16] = (unsigned char)( ( limit_yf5 >> 7 ) & 0x7f ) ;
parm[17] = (unsigned char)( ( limit_yf5 >> 14 ) & 0x7f ) ;
parm[18] = (unsigned char)( first_yf & 0x7f ) ;
parm[19] = (unsigned char)( ( first_yf >> 7 ) & 0x7f ) ;
parm[20] = (unsigned char)( second_yf & 0x7f ) ;
parm[21] = (unsigned char)( ( second_yf >> 7 ) & 0x7f ) ;
send_order( BOARD_IP , CMD_SENDYF ) ;
switch_music( VOX_WELCOME1 ) ;
time_welcome = 1 ;
time_boardcolor = 0 ;
result = NO_RESULT ;
break ;
case ZJ_BOARDCOLOR :
for( c1 = 0 ; c1 < COLOR_COUNT ; c1 ++ )
{
parm[c1*2] = (unsigned char)( color_pl[c1] & 0x7f ) ;
parm[c1*2+1] = (unsigned char)( color_pl[c1] >> 7 ) ;
}
send_order( BOARD_IP , CMD_SENDPL ) ; // 0,8
parm[0] = result ;
send_order( BOARD_IP , CMD_COLOR ) ; //0,2
check_send();
parm[0] = ( sw1_old & 0xe0 ) >> 5 ; //送爆机等级
send_order( BOARD_IP , CMD_SEND_MAXFEN ) ; // 0,12
time_boardcolor = 1 ;
check_send() ;
switch_music( music_color[color_order[result]-1] ) ;
if(++ bianma >= 127)
{
bianma = 0 ;
if(++ bianma1 >=255)
{
bianma1 = 0 ;
if(++ bianma2 >=10)
{
bianma2 = 0;
bianma1 = 0;
bianma = 0;
}
}
}
if ( print_count )
{
time_get_account = 1 ;
time_boardcolor = 0 ;
statue_sys = ZJ_GET_ACCOUNT ;
print_count = 0 ;
}
break ;
case ZJ_COUNTDOWN :
switch_music( VOX_BET ) ;
time_countdown = con_maxtime_countdown[sw2_old&0x3] ;
parm[0] = ( sw1_old & 0xe0 ) >> 5 ; //送爆机等级
send_order( BOARD_IP , CMD_SEND_MAXFEN ) ;
parm[0] = time_countdown ;
send_order( BOARD_IP , CMD_TIMER ) ;
time_1s = 0 ;
time_welcome = 0 ;
break ;
case ZJ_GETYF :
max_yz = 0 ;
time_voice = 0 ;
max_yz_player = 0 ;
send_order( 0x1 , CMD_GETYF ) ;
break ;
case ZJ_GETCOLOR : // 4
time_cmd = 0 ;
switch_music( music_player[max_yz_player] ) ;
break ;
case ZJ_TEST :
testmode = 2 ;
test_temp = 0 ;
keys_down = 0 ;
break ;
case ZJ_SET :
setmode = 1 ;
keys_down = 0 ;
break ;
default :
break ;
}
}
void check_pnt( void )
{
if ( pnt_in != pnt_read && ( keys_old & 0x4 ) == 0 )
{
write_pnt( pnt_buf[pnt_read] ) ;
if ( ++ pnt_read >= PNT_SIZE ) pnt_read = 0 ;
time_print = 1 ;
}
}
void print_char( unsigned char value )
{
pnt_buf[pnt_in] = value ;
if ( ++ pnt_in >= PNT_SIZE ) pnt_in = 0 ;
}
/*
void select_table( unsigned char no )
{
switch( no )
{
case 1 : //选择字符集1
print_char( 0x1b ) ;
print_char( 0x36 ) ;
break ;
case 2 : //选择12*12点阵汉字打印
print_char( 0x1b ) ;
print_char( 0x38 ) ;
break ;
case 3 :
print_char( 13 ) ; //
print_char( 10 ) ;
break ;
}
}
*/
void send_pnt_data( void )
{
while( pnt_in != pnt_read ) //等待打印完才继续
{
#asm("wdr") ;
if( printtype )
{
if ( time_print >= MAXTIME_PRINT )
{
time_print = 0 ;
time_get_account = 0 ;
no_printer = 1 ;
}
if ( no_printer && KEY1_CLICK )
{
no_printer = 0 ;
while(1) ;
}
}
}
}
void print_long( unsigned long int value , unsigned char fh )
{
unsigned char p1 , p3 , p5 ;
unsigned long int p2 ;
send_order( BOARD_IP , CMD_PRINT ) ;
for( p1 = 0 ; p1 < 3 ; p1 ++ )
{
print_char( 32 ) ;
}
if ( value == 0xffffffff )
{
for( p1 = 0 ; p1 < 11 ; p1 ++ )
{
print_char( '*' ) ;
}
}
else
{
for( p1 = 9 ; p1 < 10 ; p1 -- )
{
p2 = 1 ;
for( p3 = 0 ; p3 < p1 ; p3 ++ )
{
p2 = p2 * 10 ;
}
p5 = (unsigned char)( value / p2 ) ;
value = value % p2 ;
if ( p5 || fh >= 3 )
{
if ( p5 && fh < 3 )
{
if ( fh == 1 )
{
print_char( 32 ) ;
}
else
{
print_char( '-' ) ;
}
fh = 3 ;
}
print_char( p5 + 48 ) ;
}
else
{
if ( p1 == 0 )
{
print_char( 32 ) ;
print_char( 48 ) ;
}
else
{
print_char( 32 ) ;
}
}
}
}
}
void print_long1( unsigned long int value , unsigned char fh )
{
unsigned char p1 , p3 , p5 ;
unsigned long int p2 ;
send_order( BOARD_IP , CMD_PRINT ) ;
for( p1 = 4 ; p1 < 10 ; p1 -- )
{
p2 = 1 ;
for( p3 = 0 ; p3 < p1 ; p3 ++ )
{
p2 = p2 * 10 ;
}
p5 = (unsigned char)( value / p2 ) ;
value = value % p2 ;
if ( p5 || fh >= 3 )
{
if ( p5 && fh < 3 )
{
if ( fh == 1 )
{
print_char( 32 ) ;
}
else
{
print_char( '-' ) ;
}
fh = 3 ;
}
print_char( p5 + 48 ) ;
}
else
{
if ( p1 == 0 )
{
print_char( 32 ) ;
print_char( 48 ) ;
}
else
{
print_char( 32 ) ;
}
}
}
}
void print_end( void )
{
unsigned char p1 ;
send_order( BOARD_IP , CMD_PRINT ) ;
if( printtype )
{
for( p1 = 0 ; p1 < 24 ; p1 ++ )
print_char( '=' ) ;
}
else
{
for( p1 = 0 ; p1 < 16 ; p1 ++ )
print_char( '=' ) ;
}
print_char( 13 ) ;
print_char( 10 ) ;
send_pnt_data() ;
if( printtype ) ;
else
{
print_char( 0x1b ) ;
print_char( 0x38 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -