📄 level4.c
字号:
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
weigan26_even_data = parity_bit ;
parity_bit = 1; //If use odd parity check , this bit must be 1 ;
for ( i = 20 ; i < 32 ; i++ )
{
bit_cnt = i % 8;
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
weigan26_odd_data = parity_bit;
if ( weigan26_even_data ) //Send E bit;
Send_Weigan1();
else
Send_Weigan0();
for ( i = 8 ; i < 32 ; i++ ) //Send CCCC CCCC CCCC CCCC CCCC CCCC;
{
bit_cnt = i % 8 ;
if ( ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01 ) //MSBit is sent first;
Send_Weigan1();
else
Send_Weigan0();
}
if ( weigan26_odd_data ) //Send O bit;
Send_Weigan1();
else
Send_Weigan0();
}
// ********************************************************************************************
// Description : Send weigan34 model and encode according to weigan34 protocol.
// Return value: None.
// parameter : * data -- the point of the data to be encoded.
// ********************************************************************************************
void Send_Weigan34( uint8_t * data )
{
uint8_t i , weigan34_even_data , weigan34_odd_data , parity_bit , bit_cnt;
parity_bit = 0; //If use even parity check , this bit must be 0;
for ( i = 0 ; i < 16 ; i++ )
{
bit_cnt = i % 8 ;
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
weigan34_even_data = parity_bit ;
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
parity_bit = 1; //If use odd parity check , this bit must be 1 ;
for ( i = 16 ; i < 32 ; i++ )
{
bit_cnt = i % 8;
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
weigan34_odd_data = parity_bit;
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
if ( weigan34_even_data ) //Send E bit;
Send_Weigan1();
else
Send_Weigan0();
for ( i = 0 ; i < 32 ; i++ ) //Send CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC;
{
bit_cnt = i % 8 ;
if ( ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01 ) //MSBit is send first;
Send_Weigan1();
else
Send_Weigan0();
}
if ( weigan34_odd_data ) //Send O bit;
Send_Weigan1();
else
Send_Weigan0();
}
// ********************************************************************************************
// Description : Send weigan36 model and encode according to weigan36 protocol.
// Return value: None.
// parameter : * data -- the point of the data to be encoded.
// ********************************************************************************************
void Send_Weigan36( uint8_t * data )
{
uint8_t i , weigan36_even_data , weigan36_odd_data , parity_bit , bit_cnt;
parity_bit = 1; //If use odd parity check , this bit must be 1 ;
for ( i = 0 ; i < 17 ; i++ )
{
bit_cnt = i % 8 ;
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
weigan36_odd_data = parity_bit ;
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
parity_bit = 0; //If use even parity check , this bit must be 0;
for ( i = 17 ; i < 32 ; i++ )
{
bit_cnt = i % 8;
parity_bit ^= ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01;
}
weigan36_even_data = parity_bit;
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
if ( weigan36_odd_data ) //Send O bit;
Send_Weigan1();
else
Send_Weigan0();
for ( i = 0 ; i < 32 ; i++ ) //Send CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC;
{
bit_cnt = i % 8 ;
if ( ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01 ) // MSBit is sent first;
Send_Weigan1();
else
Send_Weigan0();
}
Send_Weigan0(); //Send I bit;
Send_Weigan0(); //Send I bit;
if ( weigan36_even_data ) //Send E bit;
Send_Weigan1();
else
Send_Weigan0();
}
// ********************************************************************************************
// Description : Send weigan44 model and encode according to weigan44 protocol.
// Return value: None.
// parameter : * data -- the point of the data to be encoded.
// ********************************************************************************************
void Send_Weigan44( uint8_t * data )
{
uint8_t i , bit_cnt , weigan44_low_byte = 0;
for ( i = 0 ; i < 5 ; i++ )
weigan44_low_byte ^= weigan_data[ i ];
weigan44_low_byte = ( weigan44_low_byte >> 4 ) ^ ( weigan44_low_byte & 0x0F );
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
for( i = 0 ; i < 40 ; i++ ) //Send CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC;
{
bit_cnt = i % 8;
if ( ( data[ i / 8 ] >> ( 7 - bit_cnt ) ) & 0x01 )
Send_Weigan1();
else
Send_Weigan0();
}
for( i = 4 ; i > 0 ; i-- ) //Send XXXX ;
{
if ( ( weigan44_low_byte >> ( i - 1 ) ) & 0x01 )
Send_Weigan1( );
else
Send_Weigan0( );
}
}
void Send_Weigan1( void )
{
sbi( PORTB , WEIGAN_1 );
Delayus( 100 );
cbi( PORTB , WEIGAN_1 );
Delayus( 1500 );
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
}
void Send_Weigan0( void )
{
sbi( PORTB , WEIGAN_0 );
Delayus( 100 );
cbi( PORTB , WEIGAN_0 );
Delayus( 1500 );
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
}
void Send_9600( uint8_t * data )
{
uint8_t i , temp;
SendByte( 0x7E ); //SOF;
// SendByte( 0x30 ); //address always is 0x01;
// SendByte( 0x31 );
// check_data = 0x01;
SendByte( 0x30 );
SendByte( 0x30 );
SendByte( 0x30 );
SendByte( 0x30 );
for ( i = 0 ; i < 5 ; i++ )
{
// check_data ^= weigan_data[ i ];
temp = weigan_data[ i ] >> 4 ;
if ( temp <= 0x09 )
SendByte( 0x30 + temp );
else if ( temp <= 0x0F )
SendByte( 0x37 + temp );
temp = weigan_data[ i ] & 0x0F ;
if ( ( temp <= 0x09 ) )
SendByte( 0x30 + temp );
else if ( temp <= 0x0F )
SendByte( 0x37 + temp );
}
SendByte( 0x0D ); //EOF;
SendByte( 0x0A ); //EOF;
}
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -