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 1-wire DS18S20 test using Swordfish BASIC

Status
Not open for further replies.

blueroomelectronics

Well-Known Member
Here's the code in Swordfish BASIC, it's basically the example that's found in the help file. I've adapted to work using the Junebugs CON4 connector (designed for 1-wire devices and more)
After programming you have to disable the programmer and enable the UART tool in the PICkit2 software. DIP switchs 1-3 off and 4,5 on.

Code:
// Junebug 1-Wire test (using example found in Swordfish help menu)
Device = 18F1320
Clock = 8
Config OSC = INTIO2, WDT = OFF            // Use the Internal Oscillator
Include "ow.bas"
Include "convert.bas"
Include "usart.bas"
// on find event handler...
Event OnFind()
   Dim Index As Byte
   USART.Write("FAMILY $", HexToStr(SearchFamily,2))
   USART.Write(" ($",HexToStr(SearchID(7),2),")")
   USART.Write(" ($")
   For Index = 6 to 0 step -1
     USART.Write(HexToStr(SearchID(Index),2))
   Next
   USART.Write(")",13,10)
End Event 
// working variables...
Dim DeviceCount As Byte   
// program start...
osccon = $72
high(porta.3)       // power DS18S20
SetBaudrate(br9600)
SetPin(PORTA.4)
DeviceCount = Search(owSearchROM, OnFind)
USART.Write(DecToStr(DeviceCount), " device(s) found", 13, 10)
end

Hook up a DS18S20 to CON4 (the flat side faces the reset button) and pressing reset displays this in the UART tool.
FAMILY $10 ($90) ($0008016029C610)
1 device(s) found
 
Here's some pics:
18b20sm.jpg
Since I didn't build my Junebug from a kit I didn't have the fancy 3 pin socket for CON4. Instead I cut up an 8-pin machine pin IC socket and soldered 3 pins of it in there. In the end it's the exact same thing, only less finished looking on one end. :)
pickit.JPG
 
The "fancy 3 pin socket" is just an inline machine connector cut down. Same as yours :)

You can control RA3 depending on VDD, GND, float or even analog VR2 can be switched in.

I like the rocker switch :) I'll have to find some.
 
Ok, I'm trying to read my 18B20 with Gramo's code that I modified a bit for Junebug, and I'm getting nothing happening. Any ideas what I'm doing wrong?
Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2, WDT = OFF            // Use the Internal Oscillator
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"

Dim 
   TempA As ShortInt,
   TempB As Word

OSCCON = $72
High(PORTA.3)       // power DS18S20
SetBaudrate(br9600)
SetPin(PORTA.4)

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

End
 
Same here, the DS18B20 must be different enough from the DS18S20. Might be fun just to fix the module and make an 18S20 module. Their GLCD KS0107 module is also disfunctional, doesn't work with my KS0107 or Oshonsofts simulated KS0107. Text modes work but graphics functions don't.
 
blueroomelectronics said:
Same here, the DS18B20 must be different enough from the DS18S20. Might be fun just to fix the module and make an 18S20 module.
The DS18B20 module works fine. I just didn't understand how to use it. David Barker (Swordfish Developer) has posted an article on the Wiki that explains it very nicely.

Here's working code for Junebug and DS18B20 :D You will have to modify the sensor address data to suit your own 18B20:
Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2, WDT = OFF
Include "DS18B20.bas"
include	"convert.bas"
Include "USART.bas"

const Sensor_A(8) as byte = ($28, $00, $7c, $46, $01, $00, $00, $10)

// display a sensor value...
sub DisplaySensor(byrefconst pID() as byte)
   dim TempA as shortint
   dim TempB as word
   RomID = pID
   Convert
   GetTemp(TempA, TempB)
   USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), "C",13,10)
end sub

// program start...
osccon = $72
high(PORTA.3)
SetBaudrate(br9600)
SetPin(PORTA.4)
while true
   DisplaySensor(Sensor_A)
   delayms(1000)
wend

END
 
The 18B20 module has a hardcoded $28 device ID, but I'll try your code with my 18S20 ($10)
Puddles of fun. What do you think of Swordfish? Have you seen my posting about getting it to program and run the Junebug directly using PK2CMD.exe?
 
blueroomelectronics said:
After programming you have to disable the programmer and enable the UART tool in the PICkit2 software. DIP switchs 1-3 off and 4,5 on.
I just leave switches 1-3 on and it works fine. Got tired of constantly switching em back and forth and just tried it with them in tutor position.

When I flip back to MPLAB I have to get the programmer to reconnect. It re-downloads the OS every time (have no idea why). Then I can reprogram as usual.

When I flip from MPLAB back to the PICkit2 program I have to (if I didn't remember to before) shut off the UART Tool and Check Communication once before turning the UART Tool back on.
 
blueroomelectronics said:
What do you think of Swordfish?
I like it. It needs to have better error reporting though. The error messages often don't even give you a vague idea of what the actual problem is. Those niceties will come as it improves though.

Have you seen my posting about getting it to program and run the Junebug directly using PK2CMD.exe?
Ya, I've got that set up but I'm comfy using MPLAB still. Does the SF editor have any really awesome advantages?
 
Ok then try trick #2 use the PICkit2 standalone software, select program on button press, open the hex file with Autoload / burn. It will automatically reload the hexfile and burn the pic when you press the button.

And yes the SF editor is the bees knees. One button or <F10> compile, burn & run... The module browser is excellent and it will correct the case as you type.

Your program appear to see my 18S20 but it reports -1.28C it's not that cold, so I'll have to fix the conversions as the 18S20 is a nine bit only temperature sensor.
 
blueroomelectronics said:
Your program appear to see my 18S20 but it reports -1.28C it's not that cold, so I'll have to fix the conversions as the 18S20 is a nine bit only temperature sensor.
Mine was doing that (negative bullcrap numbers) until I discovered the i2c ID part of the code. Fixed that and it worked great.
 
i2c ID? you mean 1wire ID?
PS your switches 1-5 on works fine for this...

I've got an old side lever DIP I might try, easy on the fingers.
 
blueroomelectronics said:
And yes the SF editor is the bees knees. One button or <F10> compile, burn & run... The module browser is excellent and it will correct the case as you type.
I just fixed my one button compile setup (did it wrong first try) and tried it some more. That IS nice. :D
 
blueroomelectronics said:
Your program appear to see my 18S20 but it reports -1.28C it's not that cold, so I'll have to fix the conversions as the 18S20 is a nine bit only temperature sensor.
There's 12 bits of of temperature data there (0.0625° resolution), just like the DS18B20, but the 4 bit fractional part of the data is in a different byte when you read the DS18S20 scratchpad memory.

You could probably modify David's DS18B20.BAS module to work with either sensor without too much trouble.

Have fun.
 
Yep, that's what I'm talking about. I'm adding that capability to my 12F675 assembly language demo. It'll test the family ID byte and convert 9 bit (0.5° resolution) DS16S20 temperature data into the 12 bit (0.625° resolution) DS16B20 format.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top