short int initialise1_wire_with_error_check()
{

	output_low( PIN_B0 );
	delay_us( 720 ); // pull 1-wire low for 720us reset pulse
	output_float( PIN_B0 ); // float 1-wire high
	if (!input( PIN_B0 )) 
		return ( FALSE ); // error (1-wire leads shorted)
	delay_us( 67 ); // wait for presence pulse, allowing for device variation
	if (input( PIN_B0 ))
		return ( FALSE ); // error (no 1-wire devices present)
	delay_us( 450 ); // wait-out remaining initialisation window.
	output_float( PIN_B0 );		
	return ( TRUE ); // device(s) present and initialised.

}


initialise1_wire_without_error_check() // OK if just using a single permanently connected device
{

	output_low( PIN_B0 );
	delay_us( 720 ); // pull 1-wire low for 720us reset pulse
	output_float( PIN_B0 ); // float 1-wire high
	delay_us( 67 ); // wait for presence pulse, allowing for device variation
	delay_us( 450 ); // wait-out remaining initialisation window.
	output_float( PIN_B0 );		

}


send1_wire(int data)
{

	int count;
	for (count=0; count<8; ++count) 
	{
		output_low( PIN_B0 );
		delay_us( 10 ); // pull 1-wire low to initiate write time-slot.
		output_bit(PIN_B0, shift_right(&data,1,0)); // set output bit on 1-wire
		delay_us( 50 ); // wait until end of write slot.
		output_float( PIN_B0 ); // set 1-wire high again,
		delay_us( 2 ); // for more than 1us minimum.
	}
}

int read1_wire()
{
	int count, data;
	for (count=0; count<8; ++count)
	{
		output_low( PIN_B0 );
		delay_us( 3 ); // pull 1-wire low to initiate read time-slot.
		output_float( PIN_B0 ); // now let 1-wire float high,
		delay_us( 11 ); // let device state stabilise,
		shift_right(&data,1,input( PIN_B0 )); // and load result.
		delay_us( 50 ); // wait until end of read slot.
		output_float( PIN_B0 ); // set 1-wire high again,
		delay_us( 2 ); // for more than 1us minimum.
	}
	return( data );
}
