//ReadRom
/*unsigned char DS18B20_ReadRom(void)
{
int i,j;
DS18B20_WriteByte(ReadRom);
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
rom[i][j]=DS18B20_ReadByte();
}
}
}*/
//*******************************************************
//18B20
unsigned char DS18B20_Init(void)
{
unsigned char result;
DS18B20_DIR |= DS18B20_DQ; // ow output
DS18B20_OUT &= ~DS18B20_DQ; // DS18B20_DQ=0;
DelayX10us(48); // Bus master pulling low 480us minimum;
DS18B20_OUT |= DS18B20_DQ; // DS18B20_DQ=1;
DelayX10us(5); // Resister pull up 15-60us;
DS18B20_DIR &= ~DS18B20_DQ; // ow input
result = DS18B20_IN & DS18B20_DQ;
DS18B20_DIR |= DS18B20_DQ; // ow output
DelayX10us(48); // End of timeslot total 480us;
return(result); // any 1 wire device ?result:=1 no devide; ?result:=0 have device;
}
//Intialization the 1-wire devices;
unsigned char DS18B20_ReadBit(void)
{
unsigned char result;
DS18B20_DIR |= DS18B20_DQ; // ow output
DS18B20_OUT &= ~DS18B20_DQ; // DS18B20_DQ=0;
_NOP(); _NOP(); // Start of timeslot;
DS18B20_OUT |= DS18B20_DQ; // DS18B20_DQ=1;
_NOP();_NOP();_NOP();_NOP(); _NOP();_NOP();
// Wait from the start;
DS18B20_DIR &= ~DS18B20_DQ; // ow input
result = DS18B20_IN & DS18B20_DQ;
DS18B20_DIR |= DS18B20_DQ; // ow output
return(result); // return the result of the 1-wire devide;
}//Read a bit on the 1-wire bus;
void DS18B20_WriteBit(unsigned char oww_dat){
DS18B20_DIR |= DS18B20_DQ; // ow output
DS18B20_OUT &= ~DS18B20_DQ; // DS18B20_DQ=0;
if (1 == oww_dat)
DS18B20_OUT |= DS18B20_DQ; // DS18B20_DQ=1;
DelayX10us(10); // Remain the state for 100us;
DS18B20_OUT |= DS18B20_DQ; // DS18B20_DQ=1;
}//Write a bit to the 1-wire bus;
unsigned char DS18B20_ReadByte(void)
{
unsigned char i;
unsigned char result=0;
for(i = 0; i < 8; i++){
if(DS18B20_ReadBit())
result |= 0x01 << i;
DelayX10us(12); // ??
}
return(result); // return the result of the 1-wire device;
}//Read a byte from the 1-wire bus;
void DS18B20_WriteByte(unsigned char oww_dat){
unsigned char i,temp;
for(i = 0; i < 8; i++){
temp = oww_dat >> i;
temp &= 0x01;
DS18B20_WriteBit(temp);
}
DelayX10us(7); // ??
}//Write a byte to the 1-wire bus;