#define input(pin) input_func() // <----this func is defined in previous post
#define output_low(pin) TRISBbits.TRISB3 = 0;PORTBbits.RB3 = 0
main(){
while(1)
DS1820_DelayMs(1000);
serialSendRst(input(pin));
DS1820_DelayMs(1000);
serialSendRst(resetTx());
}
}
/***************************************************/
/*
The bus master transmits (TX) a reset pulse (a low signal
for a minimum of 480 usec). The bus master then
releases the line and goes into a receive mode (RX).
The 1–Wire bus is pulled to a high state via the 5K
pull–up resistor . After detecting the rising edge on the
I/O pin, the DS1820 waits 15–60 usec and then transmits
the presence pulse (a low signal for 60–240 usec).
*/
bool resetTx()
{
bool bPresPulse;
output_low(pin);
DS1820_DelayUs(24); //24*20usec = 480
bPresPulse = input(pin);
// uses 15 + serTx baudrate delay
DS1820_DelayUs(5);
/* get presence pulse */
bPresPulse = input(pin);
return bPresPulse;
}
/****************************************************/
// 12Mhz = > ( 1/12M) sec per clock cycle.
// 1 inst = 4 clock cycle = 4*1/12M = 0.333 usec
// 1usec delay = 1/.333 = 3
// As per Modified-Delay :- 1 delayUs = 6.66usec *3 Inst = 20 useconds.
void DS1820_DelayUs(long delayUs)
{
int i,j;
for (i=0;i<delayUs;i++)
for (j=0;j<3;j++);
}
/****************************************************/