;1-Wire port support:
;Send reset pulse and receive presence pulse:
TRes1: Port_OWP1_0 ;OWP1 <- 0
ldi Cnt,250
rcall Delay ;delay 250 uS
ldi Cnt,250
rcall Delay ;delay 250 uS
cli ;interrupts disable
Port_OWP1_Z ;OWP1 <- 1
ldi Cnt,14
rcall Delay ;delay 14 uS
Skip_if_Port_OWP1_1
rjmp RFail1
ldi Cnt,52
rcall Delay ;delay 52 uS
Skip_if_Port_OWP1_0
rjmp RFail1
sei ;interrupts enable
ldi Cnt,250
rcall Delay ;delay 250 uS
Skip_if_Port_OWP1_1
rjmp RFail1
rcall SetPr1 ;set present
rjmp Rret1
RFail1: sei ;interrupts enable
rcall ClrPr1 ;present flag clear
rcall ClrTv1 ;clear T valid flag
Rret1: ret
;R/W byte via 1-wire port:
;temp - data byte
TByte1: push Cnt
ldi Cnt,8 ;bit counter
tb1: ror temp ;shift data byte
rcall TBit1 ;send bit
dec Cnt
brne tb1
ror temp ;shift last bit
pop Cnt
ret
;R/W one bit via 1-wire port:
TBit1: push Cnt
push temp
cli ;interrupts disable
Port_OWP1_0 ;OWP1 <- 0
ldi Cnt,2
rcall Delay ;delay 2 uS
brcc bit01
Port_OWP1_Z ;OWP1 <- 1 if C == 1
bit01: ldi Cnt,13
rcall Delay ;delay 13 uS
clc
Skip_if_Port_OWP1_0
sec
ldi Cnt,45
rcall Delay ;delay 45 uS
Port_OWP1_Z ;OWP1 <- 1
sei ;interrupts enable
ldi Cnt,2
rcall Delay ;delay 2 uS
rcall Do_CRC ;update CRC
pop temp
pop Cnt
ret
;----------------------------------------------------------------------------
;Update CRC:
;In: CRC, C - data bit
;Out: new CRC
Do_CRC: in temp,SREG ;save C
push temp
rol temp ;temp.0 <- C
eor temp,CRC ;temp.0 eor CRC.0
ror temp ;temp.0 -> C
brcc ZERO1
ldi temp,0x18
eor CRC,temp ;update the CRC value
ZERO1: ror CRC ;position the new CRC
pop temp
out SREG,temp ;restore C
ret
;----------------------------------------------------------------------------
;Delay:
;Cnt - delay value, uS (2uS min)
;CAUTION! Code is timed for 11.059 MHz
Delay: dec Cnt
nop
nop
nop
nop
De: dec Cnt
nop
nop
nop
nop
nop
nop
nop
nop
brne De
ret