/Modules/TDC/GP201A/SW/PICinterface/1wire.c
0,0 → 1,48
#define ONE_WIRE_PIN PIN_A1
 
void onewire_reset()
 
 
 
{
output_low(ONE_WIRE_PIN);
delay_us(500);
output_float(ONE_WIRE_PIN);
delay_us(500);
output_float(ONE_WIRE_PIN);
}
 
 
void onewire_write(int data)
{
int count;
 
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 );
output_bit(ONE_WIRE_PIN, shift_right(&data,1,1));
 
delay_us( 60 );
output_float(ONE_WIRE_PIN);
delay_us( 2 );
}
}
 
 
int onewire_read()
{
int count, data;
 
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 );
output_float(ONE_WIRE_PIN);
delay_us( 8 );
shift_right(&data,1,input(ONE_WIRE_PIN));
delay_us( 120 );
}
 
return( data );
}
/Modules/TDC/GP201A/SW/PICinterface/ds1820.c
0,0 → 1,28
 
float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;
 
onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
 
while (busy == 0)
busy = onewire_read();
 
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
temp3 = make16(temp2, temp1);
 
result = (float) temp3 / 16.0; //calculation pro DS18B20 with 0.1 deg C
 
 
delay_ms(200);
return(result);
 
}