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.

Unicorn + Swordfish + DS1820

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
After playing around with Bills Junebug demo, I thought I'd have a go at getting a DS1820 working on the Unicorn with an LCD.

It worked almost straight away and I would put that down to Swordfish basic. I had not really played with it but, now I have, it is amazingly good.

Anyway, here's the code,
Code:
// Unicorn 1-Wire test
Device = 18F4550
Clock = 48
Config
   PLLDIV = 5,
   CPUDIV = OSC1_PLL2,
   USBDIV = 2,
   FOSC = HSPLL_HS,
   VREGEN = OFF

// tell the LCD module where it's connected
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTE.0
#option LCD_RW = PORTE.1
#option LCD_EN = PORTE.2

Include "ow.bas"
Include "convert.bas"
Include "LCD.bas"           

// working variables...
Dim Temperature As Word   
Dim i As Byte
Dim TempString As String
// program start...
ADCON1 = $0F                //All digital
CMCON = $07                 //No comparators
High(PORTA.2)               //power DS18S20
OW.SetPin(PORTA.3)          //One Wire is on A3 - needs pullup
LCD.Cls
If(Reset)Then               //returns true if device found
    WriteByte(owSkipROM)    //Skip ROM
    WriteByte($44)          //Convert
    WaitForHigh()           //Wait for conversion to complete
    Reset()
    WriteByte(owSkipROM)    //Skip Rom
    WriteByte($be)          //Read Scratch Pad
    Temperature=ReadByte()
    Temperature=Temperature+ReadByte()*256
    TempString = DecToStr(Temperature*5)   // get temperature * 10
//this is a bodge to display temperature with one decimal place    
    LCD.WriteAt(1,1,"Temp=",TempString(0),TempString(1),".",TempString(2)," Deg C")
//to just display it normal use this next line
//    LCD.WriteAt(1,1,"Temp = ",dectostr(Temperature/2)," Deg C")
    Reset()
    WriteByte(owReadROM)    //read rom
    For i=0 To 7
        LCD.WriteAt(2,(7-i)*2,HexToStr(ReadByte,2))
    Next
Else
    LCD.WriteAt(1,1,"No Device Found!")
EndIf
End

And this is what it displays and how the DS is wired. The DS is in the bottom three holes of the user connector with a 4k7 resistor from RA3 to 5V. The second row is the DS's ROM id.

**broken link removed**

Mike.
 
Last edited:
Thanks Mike, I've been tinkering with modding the 18B20 module to get it working with the 18S20.
Are you using the Swordfish IDE or did you integrate with MPLAB?
PS CON1 is wired with the 4K7 pullup for a DS18S20, I usually put a machine socket there so I can plug one wire devices in.
 
blueroomelectronics said:
Thanks Mike, I've been tinkering with modding the 18B20 module to get it working with the 18S20.
Are you using the Swordfish IDE or did you integrate with MPLAB?
I used the Swordfish IDE and found it very easy to use. I haven't got a 18B20, but it should be just a matter of reading one more byte if the ID indicates it's a B20.
PS CON1 is wired with the 4K7 pullup for a DS18S20, I usually put a machine socket there so I can plug one wire devices in.
Isn't that the Junebug?

Mike.
 
The Junebug, Firefly, Unicorn, Dragonfly all have a 1-wire with 4K7 connector :) I think iButtons and 1-wire devices are the bees knees.

Have you tried installing any Swordfish IDE plugings? The LCD one is really nice.
 
blueroomelectronics said:
The Junebug, Firefly, Unicorn, Dragonfly all have a 1-wire with 4K7 connector :) I think iButtons and 1-wire devices are the bees knees.
I looked at the circuit diagram and got con1 and J1 confused. As luck (or lack of) would have it I fitted the wrong connector. I also like the 1 wire devices, they work really well.
Have you tried installing any Swordfish IDE plugings? The LCD one is really nice.
I haven't. Guess I'll have to look into these.

Mike.
 
I understand now why Gramo would soapbox Swordfish BASIC, it's a really well thought out modular & structured BASIC compiler. And it works. I can't fathom why all the BASIC Stamp & PICAxe users haven't made a go of it. Its free SE edition easily outperforms any p-code interpreter.
 
I'm so impressed that I'm thinking of buying a copy. Don't tell Gramo.:D

I particularly like the way the modules are written. Very simple and yet powerful.

Mike.
 
Me too, the only thing I HATE is the USB dongle for copy protection. I've only got two free ones on my laptop.
I've never seen a copy protection method that couldn't be defeated so IMHO USB dongles do nothing but add cost and inconvenience to a product.
 
Well it was an trivial change but here's the code to enable the backlight and use CON1 with the S18S20
Code:
High(PORTB.3)               // enable LCD backlight
DelayMS(200)                // LCD initialize delay
OW.SetPin(PORTC.2)          // DS18S20 on C.2 - has 4K7 pullup
**broken link removed**
 
blueroomelectronics said:
I understand now why Gramo would soapbox Swordfish BASIC, it's a really well thought out modular & structured BASIC compiler. And it works. I can't fathom why all the BASIC Stamp & PICAxe users haven't made a go of it. Its free SE edition easily outperforms any p-code interpreter.

I love Swordfish BASIC and feel Microchip should purchase it and turn it into their B18 product. Their endorsement would certainly go a long way toward legitimizing BASIC as a "professional" development language.

As for Gramo, I'm afraid he crossed the line on more than one occasion by suggesting that anyone using a development language other than Swordfish BASIC was stupid. I personally find those types of comments and suggestions offensive. There are strengths and weaknesses across all the major development languages and no one should have to tolerate someone suggesting you're an idiot because you're not writing code with his preferred language.

Mike
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top