Hi!
I am using samples from the maxim DS18S20+PAR and does not work, with DS18S20+ works well, the file I'm using is one_wire_ds18x20.abas for the compiler MikroBasic for AVR.
problem with DS18S20
I use my library for parasite power mode, unfortunately is written for PIC MCU.
I don't have time to translate this for AVR.
Code: Select all
module OneWire_base1
implements
Sub Function Ow_Reset_(Dim Byref pp_port as Byte, Dim pin as Byte) as Boolean
Dim Save_INTCON, Save_PRODH, Save_PRODL as Byte
Save_INTCON = INTCON And $C0
INTCON = INTCON and $3F
Save_PRODH = PRODH
Save_PRODL = PRODL
FSR2Ptr = @pp_port
FSR1Ptr = @pp_port + 18
PRODH = 1 << pin
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
result = false
Delay_uS(2)
ASM ' OW_LO
comf PRODH,w
andwf INDF1,f
comf PRODH,w
andwf INDF2,f
End ASM
Delay_uS(500)
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
Delay_uS(70)
If (INDF2 And PRODH) = 0 Then result = true End If
Delay_uS(430)
PRODH = Save_PRODH
PRODL = Save_PRODL
INTCON = INTCON Or Save_INTCON
End Sub
Sub Procedure Ow_Write_(Dim Byref pp_port as Byte, Dim pin, data as Byte)
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
Save_INTCON = INTCON And $C0
INTCON = INTCON and $3F
Save_PRODH = PRODH
Save_PRODL = PRODL
FSR2Ptr = @pp_port
FSR1Ptr = @pp_port + 18
PRODH = 1 << pin
PRODL = data
i = 0
While i < 8
ASM ' OW_LO
comf PRODH,w
andwf INDF1,f
comf PRODH,w
andwf INDF2,f
End ASM
Delay_uS(3)
If PRODL.0 = 1 Then
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
End If
ASM
rrncf PRODL,f
End ASM
Delay_uS(60)
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
Delay_uS(2)
Inc(i)
Wend
PRODH = Save_PRODH
PRODL = Save_PRODL
INTCON = INTCON Or Save_INTCON
End Sub
Sub Procedure Ow_Write_PullUp_(Dim Byref pp_port as Byte, Dim pin, data as Byte)
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
Save_INTCON = INTCON And $C0
INTCON = INTCON and $3F
Save_PRODH = PRODH
Save_PRODL = PRODL
FSR2Ptr = @pp_port
FSR1Ptr = @pp_port + 18
PRODH = 1 << pin
PRODL = data
i = 0
While i < 8
ASM ' OW_LO
comf PRODH,w
andwf INDF1,f
comf PRODH,w
andwf INDF2,f
End ASM
Delay_uS(3)
If PRODL.0 = 1 Then
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
End If
ASM
rrncf PRODL,f
End ASM
Delay_uS(60)
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
Delay_uS(2)
Inc(i)
Wend
ASM ' OW_HI and output, Strong PullUp
movf PRODH,w
iorwf INDF2,f
comf PRODH,w
andwf INDF1,f
End ASM
PRODH = Save_PRODH
PRODL = Save_PRODL
INTCON = INTCON Or Save_INTCON
End Sub
Sub Function Ow_Read_(Dim Byref pp_port as Byte, Dim pin as Byte) as Byte
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
Save_INTCON = INTCON And $C0
INTCON = INTCON and $3F
Save_PRODH = PRODH
Save_PRODL = PRODL
FSR2Ptr = @pp_port
FSR1Ptr = @pp_port + 18
PRODH = 1 << pin
PRODL = 0
i = 0
While i < 8
ASM ' OW_LO
comf PRODH,w
andwf INDF1,f
comf PRODH,w
andwf INDF2,f
End ASM
Delay_uS(2)
ASM ' OW_HIZ
movf PRODH,w
iorwf INDF1,f
End ASM
Delay_uS(5)
If (INDF2 And PRODH) <> 0 Then PRODL.0 = 1 End If
ASM
rrncf PRODL,f
End ASM
Delay_uS(60)
Inc(i)
Wend
result = PRODL
PRODH = Save_PRODH
PRODL = Save_PRODL
INTCON = INTCON Or Save_INTCON
End Sub
end.
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro