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.

One Wire Temperature sensor (DS1820) to PC interface.

Status
Not open for further replies.
Nice work Mike. I like it. I see how TRIS is setup for us during the first OwReset call. That's an excellent find for saving 2 words.

You can reclaim one word in the section between PutDigit and PutOnes in your example. Just change the skpnz to skpz and remove the goto PutIt instruction on the next line (just before the PutOnes label).

I reworked that Bin2packedBcd routine to make it a little more general purpose (below). It now works correctly for 8 bit input values of 0..255 using only 12 words and 2 variables. I should probably pass it along to James Newton over at PICLIST.

I setup my temperature variables a bit differently and saved about 4 words (the BinPrep code segment below). I didn't see the need to copy the four fraction bits in TempLo into a new variable. I don't clear the bits in the upper nybble because the AND 0x0F sequence in your FracDigit routine (called PutFraction in my program) does that for us. I use TempHi to hold the 7 bit temperature value (0..125). The AbsFunc code leaves zeros in TempHi bits 7 through 3 so we don't need to clear those bits before copying the low order temperature bits from TempLo into TempHi.

More later. Mike, K8LH

Code:
        Send232 " "             ; print <space>
AbsFunc
        movlw   " "             ;
        btfss   TempHi,7        ; negative?
        goto    PutSign         ; no, branch, else
        comf    TempLo,F        ; two's compliment it
        comf    TempHi,F        ;
        incf    TempLo,F        ;
        skpnz                   ;
        incf    TempHi,F        ;
        movlw   "-"             ;
PutSign
        call    Put232          ; print " " or "-"
[COLOR=Blue]BinPrep
        movlw   0xF0            ; W = 11110000
        andwf   TempLo,W        ; W = LLLL0000, F = LLLLFFFF
        iorwf   TempHi,F        ; F = LLLL0HHH
        swapf   TempHi,W        ; W = 0HHHLLLL, 0..127
[/COLOR][COLOR=DarkOrchid]Bin2Bcd
        clrf    tens            ; tens equates to 'OwByte'
        decf    tens,F          ; preset 'tens' to -1
div10   movwf   ones            ; ones equates to 'TempHi'
        incf    tens,F          ; bump 'tens', 0x00..0x25
        movlw   6               ; using "packed bcd" format
        addwf   tens,W          ; bcd "digit carry"?
        skpndc                  ; no, skip, else
        movwf   tens            ; adjust 'tens'
        movlw   10              ; ones = ones - 10
        subwf   ones,W          ; borrow (negative)?
        bc      div10           ; no, branch, else[/COLOR]
PrintIt
 
Last edited:
Thanks Mike, that got me the words I needed to implement the space before minus output. I also managed to reinstate the space between the ROMid and the scratchpad and turn the WDT back on. I decided the WDT was more important than printing °C (just noticed you dropped that). I did find one more word, moving clr GPIO to the reset routine got rid of the need to clear the data bit after the conversion.

That Bin2BCD has got to be the most efficient ever. You definitely should post it on the PicList.

Mike.
 
Hi Mike,

Moving the clrf GPIO instruction into OwReset actually seems very natural and intuitive and a perfect fit for the evolving program structure.

I decided to print the "-" minus sign in the hundreds column since there's no hundreds digit in the negative temperature range of -0.0625° to -55.0000°. I attached my version of the program below (242 words) just in case you or anyone else would like to take a peek.

On another subject, do you think the TMR0 register could be used as a GPR in a pinch on a future project by setting up Timer 0 in "counter" mode? On the 14 bit core devices you can continue to use the T0CKI pin as an output without affecting the TMR0 register but I'm not sure that the 12 bit core products function the same way.

Thank you for letting me participate (or should I say "butt in") on your very cool project. I had no idea there were so many challenges when working with a 12 bit core product (missing instructions, only 2 stack levels, etc.) with only 16 bytes RAM. It's been an extremely fun exercise and I learned a lot, as always, by studying your excellent code.

Regards, Mike

<added>

James added my Bin2Bcd routine to the PICLIST source code library. It can be found on the Base Conversions page in the Binary to BCD section.
 

Attachments

  • 10F200 1-Wire K8LH v2.ASM.txt
    16.2 KB · Views: 1,028
Last edited by a moderator:
Hi again Mike,

I started to prototype a board last weekend for my 10F206. Just need to add an ICSP header to it since I don't have a programming adapter for that particular PIC.

More later...
 
Thanks Mike, that got me the words I needed to implement the space before minus output. I also managed to reinstate the space between the ROMid and the scratchpad and turn the WDT back on. I decided the WDT was more important than printing °C (just noticed you dropped that). I did find one more word, moving clr GPIO to the reset routine got rid of the need to clear the data bit after the conversion.

That Bin2BCD has got to be the most efficient ever. You definitely should post it on the PicList.

Mike.
Interesting Pommie and Mike K8LH !
I seek help in porting the software into 12F510 as I have them ready. Is it possible?
 
It is definitely possible on the 12F510 as it has 1024 words for the program. We were trying to keep the code to 256 bytes and so it was a little tricky.

It's late here now and I don't have time to check if any additional code is required. Just try it and if you have any problems I'm sure we can solve them.

Mike.
 
Kind of a noob question, what program are you guys using to compile your assembly code to hex? For the PIC10. Better yet do you plan on posting some of the newer .hex files?
 
Mike,

For a sanity check I just reverted to the code from the first post and I'm getting the same results so I suspect my hardware is at fault.

<edit> one of the outer pins (DS1820) had shorted to the middle pin. No wonder I couldn't get any sense out of it. I'll try your code again and get let you know.</edit>
<edit2> You code works with the mod to OwScratch and the extra stop bit. Extremely nice piece of code. Now for the decimal bit!!</edit2>

Mike.
Perhaps it is parasite mode of powering a sensor. but it is with Vdd pin connected to ground. DQ pin should however be only for pull up and data.
 
Hi, Mike,
I am a begginner.
I just have one ds18b20, and want to read temp. from it. What should I do ?

Thanks a lot.
 
Dear,

I'm very happy with your system.
I would like to have 8 sensors on 1 bus. can we extend the wires? what is the maximum lenght between the IC's and the controller board? Can we use an external voltage? Do you have a small scheme with the modification of the external voltage?
 
You should be able to have 8 sensors on the bus. I've only tried it with 3 and the only reason it wouldn't work is the parasitic power supply, adding an external supply would solve any problems. To use an external supply, remove the diode and connect a 9VDC supply across C2. The cable length should be kept below 100M.

Mike.
 
pic program

Hi,

I have some 10F200 programmed to sell with the apllication above.

If someone interested i sell them for 2€ / piece programmed.
I have also 50x DS18S20 for 2.0€ /piece

I'm from Belgium Europe

Regards
Ben
 
Hi Ben,

Did you try putting 8 sensors on a parasitically powered module? Did you manage more? It would be useful to know how many can be added before problems appear. Also, did an external power supply work as described/expected above?

Mike.
 
Ascii output

sometimes i'm not getting a fully clearly ASCII output in Hyperterminal or in the VB program. I only connected 1 sensor right now to test.
Anyone else have this problem? I changed the baudrate but was unsuccesfull.
Any tip?

@Mike i will do it when i get a clear line. Everything is ready.
Maybe the voltage is to low that is also a reason maybe for the garbage output? Regards Ben
 
chinese

I changed the 10F200 and the other component but i'm still getting garbage in Hyperterminal and in VB.
It seems that there's a baudrate problem?

Anyone else have this porblem? under is the output of the one wire sensor in Hyper terminal...

￾￾”¢”†¦††¦￾¡‘￾¤˜￾Š“￾￾￾€˜￾‘“™—¡——‘￾€”—￾€”‚”–¦¦¦¦￾’￾￾•”￾Š“￾￾￾￾˜€‘“™—￾——‘€€”–￾￾”¢”–
¦†¦¦￾¢‘￾¡…￾Š“￾￾￾￾˜￾￾“™—¡——‘￾€”•￾€”‚”–¦¦¦¦￾”‘￾—˜￾Š“￾￾￾￾˜￾￾“‰—¡——‘￾€””￾￾”¢”–¦¦¦†€¢
‘￾’“￾Š“￾￾￾€˜￾‘“™—￾—‡‘￾€”“￾￾„¢”–¦¦¦¦￾“‘￾˜•￾Š“￾€￾￾˜￾‘“‰—¡——‘￾€”’￾￾”‚„–†¦¦¦￾¡‘￾—”￾Š
“￾€￾￾˜￾‘“™—¡——‘￾€”’￾￾„¢”–¦¦¦¦‘￾￾￾—¦￾Š“￾￾￾￾˜￾￾“™—¡——‘￾€”‘￾￾”‚„–¦¦¦¦￾†‘￾†£￾Š“￾€￾￾˜
￾‘“‰—¡——‘￾€”￾￾￾”‚„–†¦¦¦￾£‘￾…˜￾Š“￾￾￾￾ˆ￾‘“™—¡——‘￾€“¦￾￾”¢”–¦¦†¦￾“‘￾￾†￾Š“￾￾￾￾˜￾‘“™‡¡
——‘￾€“…€￾”¢”–¦¦¦†￾¢‘￾“¡￾Š“￾￾￾￾˜￾‘“™‡¡‡—‘￾€“…￾￾”¢”–¦†¦¦‘￾‘￾¦•￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘€€“
¤￾￾”¢”–¦¦¦¦￾–‘￾—–￾Š“￾€￾￾˜￾‘“‰—¡——‘￾€“£￾￾”‚„–†¦¦¦￾¢‘￾¢£￾Šƒ￾￾￾￾˜￾￾“™—¡——‘￾€“£￾￾”‚„
–†¦¦¦￾¦‘￾˜—￾Šƒ￾￾￾￾˜￾‘“™—¡——‘￾€“¢￾￾”‚„–†¦¦¦￾”‘￾‡”￾Š“￾￾￾￾˜￾￾“™—¡——‘￾€“¢￾￾”‚„–†¦¦¦￾
—‘￾’‘￾Šƒ￾￾￾￾˜￾￾“‰—¡——‘￾€“¡￾￾”‚”–¦¦¦¦￾‚￾￾’¦￾Šƒ￾￾￾￾˜￾￾“™—¡——‘￾€“¡￾￾”¢”–†¦¦¦￾¦‘€￾”￾
Š“￾￾￾€˜￾‘“™—￾—‡‘￾€“™￾€”‚”–†¦¦¦￾’‘￾…˜￾Š“￾￾￾￾ˆ￾‘“™—¡——‘￾€“™￾￾”¢”†¦††¦￾•‘￾“†￾Š“￾￾￾€
˜￾‘“™—¡——‘￾€“™￾€”‚”–¦¦¦¦￾ˆ‘￾‚¦￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘€€“ˆ￾￾”¢”–¦¦¦¦￾‚‘￾¡™￾Š“￾￾€￾˜￾‘“™—
¡——￾￾€“˜￾￾”¢”†¦††¦￾¥‘￾•†￾Š“￾￾￾￾ˆ￾‘“™—¡——‘￾€“—￾￾”¢”–¦¦†¦￾‘‘￾¢”￾Š“￾￾€￾˜￾‘“™—¡——￾￾€
“—￾￾”¢”–¦¦¦†￾“‘￾’•￾Š“￾￾￾￾˜￾‘“™—¡——￾￾€ƒ—￾￾”¢”–¦¦¦†€–‘￾¤¡￾Š“￾￾￾￾˜￾‘“™—￾——‘€€“†￾￾”¢
”–¦¦¦¦￾™‘￾˜‘￾Š“￾￾￾￾˜￾‘“™‡¡——‘￾€“–€￾”¢”–¦¦¦†￾¢‘￾‘￾￾Š“￾￾€￾˜￾‘“™—¡——￾￾€“–￾￾”¢”–¦¦¦†
€¥‘￾¥¦￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘￾€“–￾€”‚”–¦¦¦¦‘€‘￾„¦￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘€€“…￾￾”¢”–¦¦¦¦￾“￾￾￾“
￾Š“￾￾￾￾˜￾‘“™—¡——￾￾€“•￾￾”¢”–¦¦¦†€•‘￾￾™￾Š“￾￾￾￾˜€‘“™—￾—‡‘￾€“•￾€”‚”–†¦¦¦￾˜‘￾ˆ￾￾Š“￾￾￾
￾˜€‘“™—￾——‘￾€“”￾￾”‚„–†¦¦¦￾¡‘€•’￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘￾€“”￾￾„¢”–¦¦¦¦￾ƒ￾￾†˜￾Š“￾￾￾€˜￾‘“™
—¡—‡‘￾€“”￾￾„¢”–¦¦¦¦￾„￾￾“£￾Š“￾€￾￾˜￾‘“‰—¡——‘￾€“”￾￾”¢”–†¦¦¦‘￾‘￾•™￾Š“￾￾￾€˜￾‘“™—¡——‘￾
€““￾￾”¢”–¦¦†¦￾‘‘￾¡‘￾Š“￾￾￾￾˜￾￾“™—¡——‘￾€““￾￾”¢”–¦¦¦†￾“‘￾“￾￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘￾€““￾￾”
‚”–¦¦¦¦￾•‘￾‰¡￾Š“￾￾￾￾˜€‘“™—¡——‘￾€““￾￾”¢”–¦¦†¦￾—‘￾￾¢￾Š“￾￾€￾˜￾‘“™—¡——￾￾€““￾￾”¢”–¦¦¦
†￾˜‘￾‘“￾Š“€￾￾￾˜￾‘“™—¡‡—‘￾€“’€￾”¢”–¦¦¦¦￾￾‘￾ƒ‘￾Š“￾￾€￾˜￾‘“™—¡‡—‘￾€“’￾￾„¢”–¦¦¦¦￾¢‘￾￾
•￾Š“￾￾€￾˜￾‘“™—¡——￾￾€“’€￾”¢”–¦¦¦¦￾„￾￾￾¦￾Š“￾￾￾￾˜￾‘ƒ™—￾——‘￾€“’￾￾”‚„–†¦¦¦￾¥‘￾¦￾￾Š“￾￾
￾￾˜￾‘“™—¡——‘￾€“’￾￾”¢”†¦†¦¦￾¦‘￾“¥￾Š“￾￾￾￾˜€‘“™—¡——‘￾€“’￾￾”¢”–¦¦†¦‘￾‘￾£￾￾Šƒ￾￾￾￾ˆ￾‘“
™—¡——‘￾€“‘￾￾”¢”–¦¦¦¦￾‘‘￾’—￾Šƒ￾￾￾￾˜￾‘“™—¡——‘￾€ƒ‘￾￾”¢”–¦¦¦†￾“‘￾¢–￾Šƒ￾￾￾￾˜￾‘“™—¡——‘
￾€“‘￾￾”¢”–¦¦¦¦￾”‘￾„˜￾Š“€￾￾￾˜￾‘“™‡¡——‘€€“‘￾￾”‚”–†¦†¦￾•‘￾‘£￾Š
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top