//the calling code is,
OWinit();
uint8_t presence=OWreset();
OWwriteByte(0x33);
uint8_t ROM[8];
for(uint8_t i=0;i<8;i++){
ROM[i]=OWreadByte();
}
//and the One Wire code,
#include "OW.h"
inline void assertLow(){
OWpin_W=0; //ensure low
OWtris=0; //make output
}
inline void release(){
OWtris=1; //make input
}
void OWinit(void){
OWtris=1; //shouldn't be needed
}
//Send byte LSBit first
void OWwriteByte(uint8_t dat){
for(uint8_t i=0;i<8;i++){
OWwriteBit(dat&1);
dat>>=1;
}
}
//read byte LSBit first
uint8_t OWreadByte(){
uint8_t dat=1;
for(uint8_t i=0;i<8;i++){
dat>>=1;
if(OWreadBit())
dat|=0x80;
}
return(dat);
}
uint8_t OWreset(void){
assertLow();
__delay_us(560);
release();
__delay_us(67);
uint8_t temp=OWpin_R;
__delay_us(60);
return(temp);
}
void OWwriteBit(uint8_t dat){
assertLow();
if(dat)
__delay_us(6);
else
__delay_us(58);
release();
if(dat)
__delay_us(58);
else
__delay_us(6);
}
uint8_t OWreadBit(){
assertLow();
__delay_us(5);
release();
__delay_us(7);
uint8_t temp=OWpin_R;
__delay_us(52);
return(temp);
}