[an error occurred while processing this directive]
|
inline void DS1820Output()
{
IO0DIR |= (1 << DS_PIN);
}
//
inline void DS_0()
{
DS1820Output();
IO0CLR = (1 << DS_PIN);
}
//
inline void DS_1()
{
DS1820Output();
IO0SET = (1 << DS_PIN);
}
//
inline void StartSlotDelay() // 4mks
{
for (int i = 0; i < 25; i++)
__asm ("nop");
}
//
void DS_WriteByte (unsigned char data)
{
for (int i = 0; i < 8; i++)
{
DS_WriteBit(data & 1);
data >>= 1;
}
}
int DS_Read (int bits)
{int data = 0;
for (int i = 0; i < 8; i++)
{
data >>= 1;
DS_0();
StartSlotDelay();
DS1820Input();
DS30mksDelay();
if (DSGetState())
data |= 0x80;
DS30mksDelay();
DS30mksDelay();
}
return data;
}