unsigned char ds_present(){

	//ds_pin_get();
   // give the device time to get back to the 'rest' state
   ds_pin_set( 1 );
   delay( 2000 );

   // test for stuck-at-0
   if( ! ds_pin_get() ){ 
   uart_put_string("\ntest stuck at 0");
	return 0; 
   }
   
   // request a presence pulse
   ds_pin_pulse( 1000 );   
   
   // test for the presence pulse 
   delay( 30 );
   if( ds_pin_get() ){ 
	uart_put_string("\npresent pulse");
	return 0; 
   }
   
   // test whether the presence pulse ends
   delay( 1000 );
   if( ! ds_pin_get() ){
	   uart_put_string("\npresence pulse doesn't end.");
	   return 0; 
		
	}
   
   // all tests succeeded
   return 1;   
}
unsigned char ds_receive_bit( void ){
   unsigned char x;
   ds_pin_set(0);
    
    
   x = ds_pin_get();
   delay( 100 );
   return x;
}
Esempio n. 3
0
unsigned char ds_present(){

   // give the device time to get back to the 'rest' state
   ds_pin_set( 1 );
   delay( 2000 );
   
   // test for stuck-at-0
   if( ! ds_pin_get() ){ return 0; }
   
   // request a presence pulse
   ds_pin_pulse( 1000 );   
   
   // test for the presence pulse 
   delay( 30 );
   if( ds_pin_get() ){ return 0; }
   
   // test whether the presence pulse ends
   delay( 1000 );
   if( ! ds_pin_get() ){ return 0; }
   
   // all tests succeeded
   return 1;   
}
void ds_pin_pulse( unsigned long long int t ){
   ds_pin_set( 0 );
   delay( t );
   ds_pin_set( 1 );
}