Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Junebug bug w/ USART?

Status
Not open for further replies.

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
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
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.
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
 
why did you reduce delay ms to 100?
Junebug is almost like pickit2 check the changes you made and try to ensure
whether portA.3 is ok for OG
etc
do you have these
Include "OW.bas"
Include "USART.bas"
Include "DS18B20.bas"
Include "CONVERT.bas"

in the folder that you used for compiling?
 
Last edited:
Add
OSCCON = $72 // select 8MHz internal clock
ADCON1 = $7f //all digital

and then it should work
 
I tried that on the first code that came from you know where?
It should work?? but it don't
 
The Junebug has a pullup on pin RA4 to VDD a 4.7k If you add 1 like the DS18B20 shows you maybe holding the line high.
 
According to the DS18B20 data sheet it requires a pull-up resistor. Will look at that closer but if the second code works?
Going to look at the OW.bas module. Maybe an answer?
 
According to the DS18B20 data sheet it requires a pull-up resistor. Will look at that closer but if the second code works?
Going to look at the OW.bas module. Maybe an answer?

MrDeb there one built into the june bug it's on RA4 if you added one I would almost stay it not let the line go low
 
I know this may sound like a silly question but why don't you use the code that works?

AND, please stop removing the indenting from my code. It's really important to show how the code flows.

How it should be,
Code:
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
 
include "OW.bas"
Include "USART.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)    //Read 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()*256)/2
        USART.Write(" Temperature = ",DecToStr(Temperature),"C.",13,10)
    else
        USART.Write("No device found", 13, 10)
    endif
    DelayMS (100)
wend
End

Edit, have you really not learned how to use code tags yet?

Mike.
 
Last edited:
He was having a problem using it on the June bug I think he adding a resistor to the one that's built in to the June bug
**broken link removed**

If you parallel 2 4.7 k that drops it to 2.4k = 2 .0 mA the chip can only pull low 1.5 mA which is what the data sheet said and the data sheet said to use a 4.7 or 5k so if MrDeb added one that may be it .
 
Last edited:
Sorry Pommie if I moved the indenting. Trying to figure out how to get the working code (thanks to you) to display on an LCD instead of the USART. Things get moved, bad habit
In the mean time, trying for some demented reason, to get the first code example working.
Excuse me for my ignorance, but the term CODE TAGS?
Am assuming you are referring to the comments? Don't recall seeing the term code tags.
 
GOOD FIND BeBe
RA3 is a voltage ref so it needs to be pulled high
The 4.7k is required between V= and RA4
 
It like this here where and how to use code tags
like-this-jpg.54506
 

Attachments

  • like this.jpg
    like this.jpg
    42.6 KB · Views: 223
Last edited:
First I have to say up front I am a bit cranky just now.

But MrDeb! I would bet dollars to donuts we showed you how to use code tags back when you first started work on the deer repellent project for the boy scouts.

But then again we all forget sooner or ...what was that word ?
 
If I did this every day then yes its unforgivable but I havn't done ANY pic programmin from about Jan to about mid April. I almost didn't remember how to display the USART tool.
Trying to decipher the bit code from the DS18B20 data sheet. The digital output is binary but bit 0-3 are kinda ignord except for doing down to .125c
Reading the Convert module to decipher what and how to use the 12 bit code. I want to understand the inner workings. And yes I know how to decipher binary.
Am contemplating if it would be beneficial and more accurate to use the 16 bit binary directly?
A whole other can of worms?
 
Mrdeb This code should work as is I tried it with PIC18 Simulator IDE OshonSoft.com Great tool by the way.

It sets the chip right and it even sets OSCCON up for you

Code:
// 18F1320 @ 8MHz - they are just used here for clarity...
Device = 18F1320
Clock = 8

// import modules...
Include "INTOSC8"
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"
Include "Utils"
// working variables...
Dim 
   TempA As ShortInt,
   TempB As Word
   
// program start...

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 Not Find Then
   USART.Write("No device found", 13, 10)
Else
   While true
      Convert
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C", 13, 10)
      DelayMS(1000)
   Wend
EndIf
 
Nice try but no it won't display on the USART.
I even tried it by making portA.3 = 1
That code looks very similar to the example code from another site.
 
If that code doesn't work you have a hardware problem You don't need to do any thing to the code but get your hardware set right

Try this I made a mistake I forgot this Config OSC=INTIO2 sorry i been setting them in MPlab

Code:
// 18F1320 @ 8MHz - they are just used here for clarity...
Device = 18F1320
Clock = 8
Config OSC=INTIO2
// import modules...
Include "INTOSC8"
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"
Include "Utils"
// working variables...
Dim 
   TempA As ShortInt,
   TempB As Word
   
// program start...
osccon =$72
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 Not Find Then
   USART.Write("No device found", 13, 10)
Else
   While true
      Convert
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), $BA, "C", 13, 10)
      DelayMS(1000)
   Wend
EndIf
 
Last edited:
That code looks very similar to the example code from another site

That's funny LOL I a sure you that didn't come from any another site there's a sample in the swordfish library it's that sample and the changes you need to make it work

A+B=C some just use A lol
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top