📄 main.c
字号:
{
watchdog_feed_flag = 0x55;
sbi( PORTC , WATCHDOG );
}
else
{
watchdog_feed_flag = 0;
cbi( PORTC , WATCHDOG );
}
}
void Send_Card_ID( uint8_t format , uint8_t *data )
{
switch( format )
{
case 1 :
Send_Weigan26( data );
break;
case 2 :
Send_Weigan34( data );
break;
case 3 :
Send_Weigan36( data );
break;
case 4 :
Send_Weigan44( data );
break;
case 5 :
Send_9600( data );
break;
default :
break;
}
}
void Parse_Command( uint8_t cmd , uint8_t param )
{
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
switch ( cmd )
{
case 0x01 : //Modify ID number;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ID , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ID_CHK , param );
break;
case 0x02 : //Modify serial number;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &SERIAL_NUMBER , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &SERIAL_NUMBER_CHK , param );
break;
case 0x03 : //Modify format of weigan output,( 1 -- 26, 2 -- 34, 3 -- 36, 4 -- 44 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &WEIGAN_FORMAT , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &WEIGAN_FORMAT_CHK , param );
weigan_format = param;
break;
case 0x04 : //Modify authentication code;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &AUTH_CODE , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &AUTH_CODE_CHK , param );
break;
case 0x05 : //Modify EEPROM check enable;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &EEPROM_CHECK , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &EEPROM_CHECK_CHK , param );
if ( param )
{
if ( Check_EEPROM( ) )
{
SendByte( 'O' );
SendByte( 'K' );
}
else
{
SendByte( 'E' );
}
}
break;
case 0x06 : //Recovery default value, 0 --not , 1 -- reset to default value;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &RESET_DEFAULT , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &RESET_DEFAULT_CHK , param );
if ( param )
Reset_To_Default( );
break;
case 0x07 : //Modify alarm level;
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_LEVEL , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_LEVEL_CHK , param );
alarm_level = param;
break;
case 0x08 :
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_TIME , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_TIME_CHK , param );
alarm_time = param;
break;
case 0x09 :
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_ENABLE , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_ENABLE_CHK , param );
alarm_enable = param;
break;
case 0x0A :
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &TYPE_B_SETTING , param );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &TYPE_B_SETTING_CHK , param );
type_b_setting = param;
break;
default :
break;
}
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
}
uint8_t Check_EEPROM( void )
{
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
if( eeprom_rb( &ID ) != eeprom_rb( &ID_CHK ) )
return 0;
if( eeprom_rb( &SERIAL_NUMBER ) != eeprom_rb( &SERIAL_NUMBER_CHK ) )
return 0;
if( eeprom_rb( &WEIGAN_FORMAT ) != eeprom_rb( &WEIGAN_FORMAT_CHK ) )
return 0;
if( eeprom_rb( &AUTH_CODE ) != eeprom_rb( &AUTH_CODE_CHK ) )
return 0;
if( eeprom_rb( &EEPROM_CHECK ) != eeprom_rb( &EEPROM_CHECK_CHK ) )
return 0;
if( eeprom_rb( &RESET_DEFAULT ) != eeprom_rb( &RESET_DEFAULT_CHK ) )
return 0;
if( eeprom_rb( &ALARM_LEVEL ) != eeprom_rb( &ALARM_LEVEL_CHK ) )
return 0;
if( eeprom_rb( &ALARM_TIME ) != eeprom_rb( &ALARM_TIME_CHK ) )
return 0;
if( eeprom_rb( &ALARM_ENABLE ) != eeprom_rb( &ALARM_ENABLE_CHK ) )
return 0;
if( eeprom_rb( &TYPE_B_SETTING ) != eeprom_rb( &TYPE_B_SETTING_CHK ) )
return 0;
return 1;
}
void Reset_To_Default( void )
{
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ID , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ID_CHK , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &SERIAL_NUMBER , 0xFF );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &SERIAL_NUMBER_CHK , 0xFF );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &WEIGAN_FORMAT , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &WEIGAN_FORMAT_CHK , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &AUTH_CODE , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &AUTH_CODE_CHK , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &EEPROM_CHECK , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &EEPROM_CHECK_CHK , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &RESET_DEFAULT , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &RESET_DEFAULT_CHK , 0x00 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_LEVEL , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_LEVEL_CHK , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_TIME , 0x05 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_TIME_CHK , 0x05 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_ENABLE , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &ALARM_ENABLE_CHK , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &TYPE_B_SETTING , 0x01 );
while ( !eeprom_is_ready( ) ){};
eeprom_wb( &TYPE_B_SETTING_CHK , 0x01 );
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
}
void Delayms( uint16_t count )
{
while( count-- > 0 )
{
Delayus( 1000 );
}
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
}
void Delayus( uint16_t count )
{
while( count-- > 0 )
{
asm ("nop");asm ("nop");asm ("nop");asm ("nop");
asm ("nop");asm ("nop");asm ("nop");asm ("nop");
asm ("nop");asm ("nop");asm ("nop");asm ("nop");
asm ("nop");asm ("nop");asm ("nop");asm ("nop");
}
}
void Beep_Long( void )
{
cbi( PORTD , BEEP_PIN );
Delayms( 90 );
sbi( PORTD , BEEP_PIN );
// Delayms( 1 );
}
void Beep( uint8_t times )
{
if ( times == 0x01 )
Beep_Long( );
else
{
while( times-- > 1 )
{
cbi( PORTD , BEEP_PIN );
Delayms( 50 );
sbi( PORTD , BEEP_PIN );
Delayms( 40 );
}
cbi( PORTD , BEEP_PIN );
Delayms( 50 );
sbi( PORTD , BEEP_PIN );
}
}
void Alarm_Check_And_Process( void )
{
if ( alarm_level == 0 )
{
if ( PINC & ( 1 << ALARM_IN ) )
{
sbi( PORTC , ALARM_OUT );
cbi( PORTD , BEEP_PIN );
}
else
{
cbi( PORTC , ALARM_OUT );
sbi( PORTD , BEEP_PIN );
}
}
else if ( alarm_level == 1 )
{
if ( PINC & ( 1 << ALARM_IN ) )
{
sbi( PORTD , BEEP_PIN );
cbi( PORTC , ALARM_OUT );
}
else
{
sbi( PORTC , ALARM_OUT );
cbi( PORTD , BEEP_PIN );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -