Need guidence for programming a DS1821C+


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    31

    Default Need guidence for programming a DS1821C+

    I've been away from PICs for a while but a project has me digging out my old PBP 2.5a (see other thread about Windows 7). Once I get in up and running I'll likely need a bit of help.
    I need to program a few DS1821 thermometer/thermostat to operate in thermostat mode. If I'm figuring it correctly I can use OWIN, OWOUT to program a PIC to then program the DS1821C+. I have both an EasyPIC3 dev. board (also not working yet, Windows 7 issue?) and melabs U2 programmer. I bought all this stuff years ago, including PBP but only used it for a few weeks before being pulled away. I fear I've wasted a bunch of $$ as this stuff is all too outdated.
    Anyway, am I on the right track for programming the DS1821?
    TIA
    Neo

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    http://www.picbasic.co.uk/forum/cont...r-nine-of-themhttp://www.picbasic.co.uk/forum/cont...r-nine-of-themHi neo,

    Below is a code snippet from my WIKI article on reading the DS18b20 temperature sensor...

    you may find something usefull if you go look at that article.
    NOTE: most of the code I borrowed from others and simply wrote the article for the WIKI.


    Code:
    ReadSensor:
        OWOUT DQ, 1, [$55,str id\8,$44] 'instructs sensors to match[$55] this[ID] rom code and
                                        'initiates[$44] temperature conversion on matching sensor
    CkAgn:
        OWIN DQ, 4, [busy]      ' Check for still busy converting
        IF busy = 0 THEN ckagn  ' Still busy?, then loop
        owout dq,1,[$55,str id\8,$BE]   'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE] 
        OWIN DQ, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]' Read two temperature bytes, then end communications
        return
    here is a link to the article...

    http://www.picbasic.co.uk/forum/cont...r-nine-of-them

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Heckler,
    Thanks for the quick reply. I'll have a look at that.
    Still haven't been able to get my version of PBP running yet though.
    Neo

  4. #4
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Well things are looking up! I've PBP up and running as well as my U2 programmer. Haven't made the EasyPIC3 programmer work though, USB driver issue I think, but the board is useful for running the PIC after prog in the U2. I tried working with the code mentioned above from over at rentron.com but I don't have a serial LCD so went looking again. I found this "PicBasic Experiments With The PIC16F877" over at rentron.com also which fit better with the EasyPIC3 board and it's LCD in 4-bit mode.
    I'm using a 16F88 because it's what's on hand. So I edited the code to work with just a PORTA and PORTB and the LCD of the EasyPIC3 hardwired to PORTB 4-7 etc.
    I had a few problems getting it working... funny story (well not so much)... The DS1820 has it's own home on the EasyPIC3 (EP3 for short) board, a 3-pin socket labeled DS1820 with a pull-up resistor (10k). I pulled the DS1820 out of the breadboard I stuck it into for safe keeping a couple days earlier and observing polarity plugged it into the EasyPIC3. Loaded up the code from PBP to the 16F88 and dropped it into the EP3, powered up and... LCD displays "Temp in degrees" then "0.0 degrees C". Troubleshooting commenced.
    To make a long story shorter I double checked the part number of the DS1820 thinking there may be changes that were not backward compatible to the older code. What I found was a 2N2222 in the socket where the DS1820 should have been. A quick glance at the breadboard showed another TO-92 device with a dozen other resistors, capacitors, chips etc... the DS1820. Maybe not such a great place to store it.
    Anyway, swapping in the right part didn't help. Still 0.0 degrees C. Back to the code. What I found was the setting of the ADCs to digital was required. Changing the ADCON1=7 to ANSEL = 0 got me 26.5 degrees C on the LCD. I found the ANSEL=0 in an older thread here http://www.picbasic.co.uk/forum/showthread.php?t=2996. Thanks Darrel.
    I read a bit more about setting the ADCs but don't quite understand ADCON1 vs ANSEL are they chip specific? I'm looking for someone to point me to something I can read for a better understanding.
    Neo

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Need guidence for programming a DS1821C+

    Yes those register names are VERY chip specific. Although you may find similarities between chips I would always check the data sheet for the chip you are using.

    That is probably the one thing that took me a while to realize. You simply can not work with these PIC microcontrollers (or other micro's for that matter) without having the data sheet available for reference. .pdf file works great.

    Just google your PIC part number and "datasheet" and find the link to Microchips web site for the datasheet.
    Now reading the data sheet is an "aquired talent" There is a LOT of information there and you have to figure out what is importaint at the moment for what you are trying to do.

    Not sure how to tell you how to go about digesting the data sheet, other than to say KEEP AT IT. Start by finding the section on the Port Pins as there you will find all the registers that are pertinant for that given Port Pin. You will have to do quite a bit of jumping around in the document as you look at each of the various registers.

    I also try and start my projects by loading a previos file that uses the same chip I am working with at the time. That way I know it worked for that previous project and I can delete most of the code and start witht the begging register configuration section.

    Dont forget the Configuration "fuses" that are set at the time the chip is flashed. This configuration register is usually what sets the watch dog timer, brown out detect, int/ext type of oscillator, how the MCLR pin behaves (as an mclr or as an INPUT) etc., etc,

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    May 2008
    Posts
    31


    Did you find this post helpful? Yes | No

    Question Re: Need guidence for programming a DS1821C+

    Thanks for the tips. I've been pouring over data sheets, web pages, and PBP manual for days getting myself up to speed as best I can. I came across some code that I don't understand because of the assembly mixed in with the PBP. Why use PBP PAUSEUS 60 to pause for 60 microseconds and then @ nop to delay for 1 microsecond? (4 MHZ OSC) Is it because of the minimum resolution at 4 MHZ with PBP (guessing)? I know why the DS1821 need the timing, just not why the assembly is mixed in with the PBP. If I'm running at 20 MHZ and the resolution is higher (.2 uSec if memory serves) then would the assembly not be needed?
    TIA

    Code:
    write0:
            Low DQ
            Pauseus 60              ' Low for > 60us for 0
            DQ_DIR = 1         ' Release data pin (set to input for high)
            Return
    
    ' Write a 1 bit to the DS1820
    write1:
            Low DQ                  ' Low for < 15us for 1
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1        ' Release data pin (set to input for high)
            Pauseus 60             ' Use up rest of time slot
            Return

Similar Threads

  1. need help programming
    By chris000 in forum General
    Replies: 1
    Last Post: - 20th May 2009, 05:18
  2. new to PIC programming could really do with some help
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2008, 14:03
  3. I2C programming
    By goku24m in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th October 2007, 03:12
  4. gps programming
    By chuckad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th June 2006, 01:02
  5. New to PIC Programming
    By Keiou in forum General
    Replies: 3
    Last Post: - 29th October 2003, 19:13

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts