MrDEB
Well-Known Member
been trying different versions of code to read a DS18B20. The orginal code was using an example from DIY ELECTRONICS. It works w/ a Pickit2 but dang if I can get it working using the Junebug. Is there something I need to do to get it to work?
Here is the code I am trying to use as well as a code that Pommie posted eons ago that does work on the Junebug.
Got to be a reason why one works and the other does not.??
first code is set for an 18F1320 but does not work
The programmer device shouldn't make a difference but??
And yes I doubled checked the baud rate = 9600 in code and USART tool.
Perhaps the clock rate?
Here is the code I am trying to use as well as a code that Pommie posted eons ago that does work on the Junebug.
Got to be a reason why one works and the other does not.??
first code is set for an 18F1320 but does not work
This code was posted by Pommie eons ago and it works. BUT why does one that works using an 18F452/Pickit2 but changed to a 18F1320/Junebug.Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
//Include "OW.bas"
Include "USART.bas"
Include "DS18B20.bas"
Include "CONVERT.bas"
// import modules...
//Include "DS18B20.bas"
//Include "convert.bas"
//Include "usart.bas"
Include "utils.bas"
// working variables...
Dim
TempA As ShortInt,
TempB As Word
// Start Of Program...
SetBaudrate(br9600)
SetPin(PORTA.4)
// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...
If DS18B20.Find Then
While true
Convert
GetTemp(TempA, TempB)
USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
DelayMS(1000)
Wend
Else
USART.Write("No device found", 13, 10)
EndIf
The programmer device shouldn't make a difference but??
And yes I doubled checked the baud rate = 9600 in code and USART tool.
Perhaps the clock rate?
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "OW.bas"
Include "USART.bas"
Include "DS18B20.bas"
Include "CONVERT.bas"
Dim Temperature As Word
Dim i As Byte
OSCCON = $72 // select 8MHz internal clock
ADCON1 = $7f //all digital
TRISA.3=0 //A3 output
PORTA.3=1 //and high
SetBaudrate(br9600)
OW.SetPin(PORTA.4)
While true
If OW.Reset Then
OW.WriteByte(owReadROM) //Skip ROM
USART.Write("Rom = ")
For i = 0 To 7
USART.Write(HexToStr(OW.ReadByte()))
Next
OW.Reset
OW.WriteByte(owSkipROM) //Skip ROM
OW.WriteByte($44) //Convert
OW.Reset
OW.WaitForHigh //wait for convert to finish
OW.Reset
OW.WriteByte(owSkipROM) //Skip Rom
OW.WriteByte($be) //Read Scratch Pad
Temperature=OW.ReadByte()
Temperature=(Temperature+OW.ReadByte()*128)
USART.Write(" Temperature = ",DecToStr(Temperature/4))
If (Temperature And 1) = 1 Then
USART.Write(".5")
EndIf
USART.Write("C",13,10)
Else
USART.Write("No device found", 13, 10)
EndIf
DelayMS (100)
Wend
End