Me again, but need REAL help now


Closed Thread
Results 1 to 34 of 34
  1. #1

    Angry Me again, but need REAL help now

    O.K. I Searched, found the code for the SHT71, thought I understood it, and am now more confused than a porcupine in a brush factory. I am trying to make a 16F877A have a generally good conversation with the SHT-71, and display the results on an LCD. I have mastered the LCD bit (really easy with picBasicPro), had an LM35 read an analogue temperature, but I just can't get my head around this SHT-71. is there anyone out there who has a few minutes to write an idiots guide??? Or has anyone got a finished full code so that I might learn from it??

    Thanks in advance,

    Gringo

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    What else have you built so far? Anything?

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Ski,

    Yes, I built a temp/humidity regulator, using the PIC16F877A, an LM35 temp sensor, and a non linear resistive humidity sensor, with 2X16 LCD, and a user menu to set the paramaters. Once the temp or humidity goes outside these paramaters, a relay is triggered (Through a ULN2003A) which will switch on either a humidifier, dehumidifier, heater, cooler. But the analogue stuff isn't very accurate which is why I'm searching like a maniac for help with this digital stuff.

    Apart from that, various LED strobe kits for volunteer firefighters, again using the darlington pair chip, which can give you current output of 500mA per leg, or more if you run them in parallel.

    But I'm still a newbie

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Post

    Hi,

    Some ideas ( in english ! ) There :

    http://www.mikroe.com/forum/viewtopi...ighlight=sht11

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Yes, I built a temp/humidity regulator, using the PIC16F877A, an LM35 temp sensor, and a non linear resistive humidity sensor, with 2X16 LCD, and a user menu to set the paramaters. Once the temp or humidity goes outside these paramaters, a relay is triggered (Through a ULN2003A) which will switch on either a humidifier, dehumidifier, heater, cooler. But the analogue stuff isn't very accurate which is why I'm searching like a maniac for help with this digital stuff.
    Apart from that, various LED strobe kits for volunteer firefighters, again using the darlington pair chip, which can give you current output of 500mA per leg, or more if you run them in parallel.
    But I'm still a newbie
    Well, all that being said, that link posted above should give you one heck of a head start at getting that SHT71 working without much problem.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Excellent guys, thanks. The conversion to PicBasic doesn't look too hard, so thats my project for tonight. Wish me luck!!!!!!

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Excellent guys, thanks. The conversion to PicBasic doesn't look too hard, so thats my project for tonight. Wish me luck!!!!!!
    Actually, I had my mind in another thread with that last comment.
    The link above to mikro is good, but if you search HERE, on these forums, you'll find some code practically already done, waiting for your modifications.
    Ya know...that search button, towards the top of the page, offset to the right a bit, little down arrow next to it, white letters, blue background...

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Done that a few days ago, and was lead to the SHT-71 code by cocacolaKid. the thing is, I don't understand the code well enough to make the correct mods. Unfortunately, maybe I'm not as well up on PicBasic as I could be, so I don't fully understand "shiftout DataPin,clk,1,[SensorCmd\8]" DataPin and CLK are pins on the SHT, so I define them, but SensorCMD/8????? No idea. Some hand-holding seems to be the only answer......

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    but SensorCMD/8????? No idea. Some hand-holding seems to be the only answer......
    "SensorCMD\8" isn't in the book, but the definition of what those positions in the command "SHIFTOUT" are fully explained in the manual.

  10. #10


    Did you find this post helpful? Yes | No

    Default

    RTFM springs to mind...lol. OK, so I'm closer, but now I have a question. What is the purpose of using this : "result.byte0"? It doesn't seemed to be liked by PB

  11. #11


    Did you find this post helpful? Yes | No

    Default

    O.K., I worked that one out. Stay tuned, I may have this licked.......

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Stay tuned, I may have this licked.......
    Well, that might just be a good test
    Lick it and the humidity and temp should go up

  13. #13


    Did you find this post helpful? Yes | No

    Default

    Can't seem to find the subroutine "ReceiveData" anywhere, so my program just does some kind of permanent loop. There must be a wall nearby I can bang my head off a few times....................

  14. #14


    Did you find this post helpful? Yes | No

    Default Help!!!!!!!!!!!

    This is the code I'm using, but it gets stuck at the WHILE/WEND bits in the ReadSensor subroutine. HELP!!!!!!!!!!!

    INCLUDE "modedefs.bas"
    CRC VAR word
    tempc var word
    signc var word
    result var word
    readhumidity var word
    sensorcmd var word
    readtemp var word
    w var word
    x var word
    temp var word
    rhtempcomp var word
    rhlinear var word
    byte0 var word
    byte1 var word
    databyte var word
    databit var word
    i var word

    'include "16F877A"
    ' Define LCD pins
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 1
    Define LCD_EREG PORTB
    Define LCD_EBIT 3
    Low PORTB.2 ' LCD R/W line low (W)


    Pause 100 ' Wait for LCD to start
    lcdout $fe,1, "Temperature and" ' show on LCD
    lcdout $fe, $c0 ,"Humidity sensor." ' show on LCD
    pause 2000 ' Wait 2 seconds
    lcdout $fe,1 ' Clear screen
    Goto mainloop ' Skip subroutines, start main program


    mainloop:
    lcdout $fe,1,"Temp ", # tempc

    lcdout $fe,$c0,"Humidity ",#RHTempComp
    gosub ReadSHT71
    pause 100
    goto mainloop
    end




    'read the sensor thingie
    ReadSHT71:
    Sensorcmd = ReadTemp
    gosub readsensor
    if result => 4000 then
    tempC = result - 4000
    SignC = 160
    else
    tempC = 4000 - result
    SignC = "-"
    endif
    gosub Initialize
    Sensorcmd = ReadHumidity
    gosub readsensor

    '--------------------- Calculate Relative Humidity -----------------------------

    w = result * 405
    w = div32 100
    x = result * result
    x = div32 1000
    x = x * 28
    x = div32 100
    RHLinear = w - x - 400

    '---------- Calculate Relative Humidity with Temperature Compensation ----------

    w = (8 * result + 1000) / 10
    if SignC = 160 then
    if tempC > 2500 then
    x = (tempC - 2500) * w
    x = div32 100
    RHTempComp = RHLinear + x / 100
    else
    x = (2500 - temp) * w
    x = div32 100
    RHTempComp = RHLinear - x / 100
    endif
    else
    x = (2500 + tempC) * w
    x = div32 10000
    RHTempComp = RHLinear - x
    endif
    sleep 1
    return

    '---------------------------- Initialize the Sensor ----------------------------

    Initialize:
    high PORTD.0
    low PORTD.1
    for i = 1 to 10
    high PORTD.1
    pause 1
    low PORTD.1
    pause 1
    next i
    call TransferStart
    return

    '---------------------------- Get Data from Sensor -----------------------------

    ReadSensor:
    gosub TransferStart
    gosub WaitSensor
    shiftout PORTD.0,PORTD.1,1,[Sensorcmd\8] ' Send command byte
    input PORTD.0 ' Wait for acknowledge
    low PORTD.1
    while PORTD.0 = 1
    wend
    pulsout PORTD.1,10 ' Send acknowledge
    while PORTD.0 = 0
    wend
    while PORTD.0 = 1 ' Wait for conversion to complete
    wend
    low PORTD.1
    shiftin PORTD.0,PORTD.1,0,[result.byte1\8] ' Get the first byte, 8 bits
    low PORTD.0
    pulsout PORTD.1,10 ' Send acknowledge
    shiftin PORTD.0,PORTD.1,0,[result.byte0\8] ' Get the second byte, 8 bits
    low PORTD.0
    pulsout PORTD.1,10 ' Send acknowledge
    shiftin PORTD.0,PORTD.1,0,[crc\8] ' Get third byte, 8 bits, CRC
    high PORTD.0
    pulsout PORTD.1,10 ' Send acknowledge
    input PORTD.0 ' End of Transmission
    input PORTD.1
    return

    '---------------------------- Start Transfer -----------------------------------

    TransferStart:
    high PORTD.1
    pause 1
    low PORTD.0
    pause 1
    low PORTD.1
    pause 1
    high PORTD.1
    pause 1
    high PORTD.0
    pause 1
    low PORTD.1
    return

    '---------------------------- Wait for Sensor ----------------------------------

    WaitSensor:
    result = 4096

    Loop:
    result = result - 1
    if PORTD.0 && result.bit11 then Loop
    return

  15. #15
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello gringobomba14,
    If you have any extra ports available you could put some code in those empty While Wend loops to light leds to tell you which loop is stalled, or add some serout commands to do the same. or put in an escape counter in the loops.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this:
    Code:
    Define  LCD_DREG        PORTB
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTB
    Define  LCD_RSBIT       1
    Define  LCD_EREG        PORTB
    Define  LCD_EBIT        3
    INCLUDE "modedefs.bas"
    crc var word:tempc var word:signc var word:result var word
    readhumidity var word:sensorcmd var word:readtemp var word:w var word
    x var word:temp var word:rhtempcomp var word:rhlinear var word:byte0 var byte
    byte1 var byte:databyte var byte:databit var bit:i var word:dpin var portd.0
    cpin var portd.1:portb.2=0:output portb.2:Pause 1000
    lcdout $fe,1, "Temperature and",$fe, $c0 ,"Humidity sensor.":pause 2000
    lcdout $fe,1:Goto mainloop        ' Skip subroutines, start main program
    mainloop: lcdout $fe,1,"Temp ", #tempc,$fe,$c0,"Humidity ",#RHTempComp
    gosub ReadSHT71:pause 100:goto mainloop
    ReadSHT71: Sensorcmd = ReadTemp : gosub readsensor
            if result => 4000 then
            tempC = result - 4000 : SignC = 160
            else
            tempC = 4000 - result : SignC = "-"
        endif
    gosub Initialize : Sensorcmd = ReadHumidity : gosub readsensor
     w = result * 405 : w = div32 100 : x = result * result : x = div32 1000
     x = x * 28 : x = div32 100 : RHLinear = w - x - 400
     w = ( (8 * result ) + 1000) / 10
        if SignC = 160 then
           if tempC > 2500 then
              x = (tempC - 2500) * w : x = div32 100
               RHTempComp = ( RHLinear + x ) / 100
                else
                x = (2500 - temp) * w : x = div32 100
               RHTempComp = ( RHLinear - x ) / 100
            endif
            else
            x = (2500 + tempC) * w : x = div32 10000
               RHTempComp = RHLinear - x
        endif
        sleep 1 : return
    Initialize: dpin=1:cpin=0:for i=1 to 10:cpin=1:pause 1:cpin=0:pause 1:next i
                 gosub TransferStart : return
    ReadSensor: gosub TransferStart : gosub WaitSensor
        shiftout dpin,cpin,0,[Sensorcmd\8]
        input dpin : cpin = 0
        while dpin = 1 : wend
        cpin = 1 : pause 1 : cpin = 0
        while dpin = 0 : wend
        while dpin = 1 : wend
        cpin = 0 : shiftin dpin,cpin,0,[result.byte1\8] : dpin = 0 : cpin = 1
        pause 1 : cpin = 0 : shiftin dpin,cpin,0,[result.byte0\8] : dpin = 0
        cpin = 1 : pause 1 : cpin = 0 : shiftin dpin,cpin,0,[crc\8] : dpin = 1
        cpin = 1 : pause 1 : cpin = 0 : input dpin : input cpin : return
    TransferStart: cpin = 1 : pause 1 : dpin = 0 : pause 1 : cpin = 0
    pause 1 : cpin = 1 : pause 1 : dpin = 1 : pause 1 : cpin = 0 : pause 1
    return
    WaitSensor: result = 4096
    Loop: result = result - 1 : if PORTD.0 & result.bit11 then Loop
        return
    END
    Had a couple of subtle math errors, parenthesis type things..
    Looks like the mode might've been wrong in a couple of places.
    The END wasn't at the bottom...not that it makes much of a difference.
    And it's been COLON-IZED!
    Last edited by skimask; - 19th June 2008 at 06:02.

  17. #17


    Did you find this post helpful? Yes | No

    Default almost there

    Cheers Ski, looks more compact, and forgot about those colon type things to seperate code. AM I missing something else, because now I get this
    ERROR: Macro AND?TTL not found in macro file.
    I recall some kind of Math Macro...........
    Last edited by gringobomba14; - 19th June 2008 at 07:54. Reason: bad grammer, misspelled words, and it was raining

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Cheers Ski, looks more compact, and forgot about those colon type things to seperate code. AM I missing something else, because now I get this
    ERROR: Macro AND?TTL not found in macro file.
    I recall some kind of Math Macro...........
    Woof...sweet! Nice error!
    What version of PBP are you running? And/Or do you have the patches installed?
    And what is the 'full' verbage of the error? Can you track it down to which line is causing it?

  19. #19
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink a hole in the somewhere ???

    Hi, Ski

    Here it is :


    Executing: "C:\Program Files\Microchip\MPLAB IDE\PBP\PBPW.EXE" -ampasmwin -oq -z -v -p16F877 "Ski.bas"
    PICBASIC PRO(TM) Compiler 2.50a, (c) 1998, 2007 microEngineering Labs, Inc.
    All Rights Reserved.
    Pass 1:
    Pass 2:
    Code Gen:
    Macro Pass:
    ERROR: Macro AND?TTL not found in macro file.
    Halting build on first failure as requested.
    BUILD FAILED: Thu Jun 19 14:33:50 2008
    got that with all the very last releases ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Here it is :
    got that with all the very last releases ...
    Alain
    Let me re-phrase that last comment
    Ya gotta page thru the resulting .asm and possibly .lst file to figure out where the problem is. Then trace it back to the source code lines.

  21. #21
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    May be

    Code:
    Loop:result = result - 1 :if PORTD.0 && result.11 then Loop'
    instead of

    Code:
    Loop: result = result - 1 : if PORTD.0 & result.bit11 then Loop
    ... here it compiles !

    may be you're not LOGICAL enough ... LoL !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  22. #22
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    ... here it compiles !
    may be you're not LOGICAL enough ... LoL !
    Good one!

    Yep, I finger-flubbed that one apparently...

  23. #23


    Did you find this post helpful? Yes | No

    Default

    Excellent help guys. Compiled with the && so I learned something new today....... but now I just get 16 on Humidity and Temp. I have a 10K pull up resistor on the DATA pin of the SHT71, and the leads are about 5cm long. I found that the program stops here:

    ReadSensor: gosub TransferStart : gosub WaitSensor
    shiftout dpin,cpin,0,[Sensorcmd\8]
    input dpin : cpin = 0
    while dpin = 1 : wend
    cpin = 1 : pause 1 : cpin = 0
    while dpin = 0 : wend '<-----------------program stops here
    so obviously the Data pin is not doing what its told to. Any more ideas out there???

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    I found that the program stops here:
    ReadSensor: gosub TransferStart : gosub WaitSensor
    shiftout dpin,cpin,0,[Sensorcmd\8]
    input dpin : cpin = 0
    while dpin = 1 : wend
    cpin = 1 : pause 1 : cpin = 0
    while dpin = 0 : wend '<-----------------program stops here
    so obviously the Data pin is not doing what its told to. Any more ideas out there???
    How do you know the data pin isn't doing what it's told to do?
    How do you know that the sensor received the Sensorcmd correctly in the first place to trigger it to kick back some data at you? Do you even have to wait for the dpin to go low and/or high? How about just pausing for a bit longer and see what happens?

  25. #25


    Did you find this post helpful? Yes | No

    Default

    All good questions............let me stick some LED's in there and see whats going on then

  26. #26


    Did you find this post helpful? Yes | No

    Default

    This is now officially doing my head in.....pause 10 in place of WEND gives a temp of 4000 and a humidity of 65071. methinks this is not working for me, and my sanity quotient has dramatically decreased these last few days.

  27. #27
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    This is now officially doing my head in.....pause 10 in place of WEND gives a temp of 4000 and a humidity of 65071. methinks this is not working for me, and my sanity quotient has dramatically decreased these last few days.
    Well, then get rid of all that crazy math (ok, it's really not that crazy, but it does increase the chance of a logical error of some sort) you've got going on, read raw values and see if anything at all makes sense.

    Put the sensor in ice water, run the program, read the value.

    Put the sensor in really hot water, run the program, read the value, see if the temp rises by something that's reasonable, like say you went from ice to boiling, the temp sensor might rise by 100 (or 212 depending on your units). And the humidity would surely rise a bunch too. Then maybe put the sensor in a bunch of dessicant, to dry it out really good and see what the humidity output reads.

    That 4000 you've got might be 40.00C (doubt it, but anything's possible), that 65071 might be 65.071%RH (again, doubt it, but, you know...).

  28. #28


    Did you find this post helpful? Yes | No

    Default

    Careful Ski, people might start accusing you of knowing things!!!!!! I think what the problem is, is the SHT is either not understanding the commands, or the program isn't complete (I got it off the forum). I wonder is there anyone out there who has experience at this sensor?

    I have tried reading the raw data, and got, well, nothing. Or maybe less.
    Last edited by gringobomba14; - 19th June 2008 at 18:57. Reason: bad spelling again

  29. #29
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Careful Ski, people might start accusing you of knowing things!!!!!!
    That's the last thing I want...and/or need...

    I think what the problem is, is the SHT is either not understanding the commands, or the program isn't complete (I got it off the forum). I wonder is there anyone out there who has experience at this sensor?
    That post I saw looked pretty complete to me.

    I have tried reading the raw data, and got, well, nothing. Or maybe less.
    Maybe you let all the smoke out of it?

    I'd put it down, go out and mow the lawn or something, come back to it later.
    But that's just me...and that's what I do when crap ain't working.

  30. #30


    Did you find this post helpful? Yes | No

    Default

    Blue smoke genie is still in one piece, but just to make sure I changed PIC's and SHT's. (Maybe there is an "I" missing in that sensor code somewhere...........)
    Here is a question. If I wanted to send say "00000101" from a pin on the PIC, how would I do that? SEROUT? and then to receive "01101010" would be SERIN right? Maybe I might have a go at some changes and see what kind of trouble I can get myself into

  31. #31
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Here is a question. If I wanted to send say "00000101" from a pin on the PIC, how would I do that? SEROUT? and then to receive "01101010" would be SERIN right? Maybe I might have a go at some changes and see what kind of trouble I can get myself into
    It's all in the PBP manual, check the modifiers.

  32. #32


    Did you find this post helpful? Yes | No

    Red face

    Ah yes, the standard RTFM answer. In the meantime, another search has produced results of some sort, which has the sensor doing SOMETHING, but I think now it's down to the crazy maths. Watching SCRUBS is a great way of clearing the mind and getting back to work.

  33. #33
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Ah yes, the standard RTFM answer.
    In this case, yes. 3 little letters might help BIN

    In the meantime, another search has produced results of some sort, which has the sensor doing SOMETHING, but I think now it's down to the crazy maths
    Don't forget about overflowing bytes and words...

    Watching SCRUBS is a great way of clearing the mind and getting back to work.
    Damn straight. Although, I'm not so sure it's so much that it clears the mind as it makes the mind DUMP...

  34. #34


    Did you find this post helpful? Yes | No

    Talking Beer for everyone!!!!

    I found this code posted by NavMicroSystems, made some SLIGHT changes, and it works perfectly. Cheers to everyone. This works for both the SHT1x and the SHT7x sensors. I have pasted the code below for everyone to see, and play with should the need arise. Thanks again to everyone who spent time trying to make my little project work. Beers are on me (sorry, no delivery outside of my local area)
    Code:
    '** Pin-Assingments
    DEFINE xtal 4
    Define  LCD_DREG        PORTB
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTB
    Define  LCD_RSBIT       1
    Define  LCD_EREG        PORTB
    Define  LCD_EBIT        3
    portB.2=0
    output portb.2
    dta VAR PORTD.0 ' Sensor Data
    clk VAR PORTD.1 ' Sensor Clock
    
    '** Constants
    
    cmdtr CON %00000011 ' Command "read temperature"
    cmdhr CON %00000101 ' Command "read humitity"
    
    '** Variables
    
    result VAR WORD ' RAW Data from Sensor
    chksum VAR BYTE ' Checksum
    cmd VAR WORD ' Sensor Command
    RHlin VAR WORD ' Rel. Humidity (RH) Linear (% *10)
    RHtc VAR WORD ' Rel. Humidity (RH) temp. compensated (% *10)
    Temp VAR WORD ' Temperature (°C *100)
    DP VAR WORD ' Dewpiont (°C *10)
    
    
    '** Temp variables used in div. calculations
    
    TempDP VAR WORD
    Rchk VAR BYTE 
    logEW VAR WORD
    sign VAR BIT
    wy VAR WORD
    wz VAR WORD
    wj VAR WORD
    wx VAR WORD
    i VAR BYTE
    ix VAR BYTE
    bt VAR BIT
    
    
    Pause 500
    LCDOut $FE,1,"** SHT 71 **"
    PAUSE 1000
    
    main:
    
    GoSub init
    cmd = cmdtr
    GoSub readsensor
    Temp=result-3995
    GoSub init
    cmd = cmdhr
    GoSub readsensor
    RHlin=(26542-(54722**result+result))**result-40 ' RH linear
    RHtc=655+(result*5)+(result**15917) 
    RHtc=(RHtc**(Temp/10+2480))-(RHtc**2730)+RHlin ' RH temp. compensated
    
    'GoSub dewpoint
    
    LCDOut $FE,$80," ",$DF,"C","   ",$25,"RH","   DP "
    LCDOut $FE,$C0,DEC2 (TEMP/100),".",DEC1 (temp/10)," ",DEC2 RHlin/10,".",DEC1 RHLin'," ",DEC2 ABS DP/10,".",DEC1 ABS dp
    pause 1000
    GoTo main
    
    '** Init Sensor
    init: 
    High dta 
    Low clk 
    For i=1 to 10 
    High clk
    Pause 1 
    Low clk
    Pause 1 
    Next i 
    Call tstart 
    Return 
    
    '** start transfer
    tstart:
    High clk
    Pause 1 
    Low dta 
    Pause 1 
    Low clk
    Pause 1 
    High clk
    Pause 1 
    High dta 
    Pause 1 
    Low clk
    Return 
    
    '** get Data from Sensor
    readsensor:
    GoSub tstart
    GoSub WaitSensor
    
    ShiftOut dta,clk,1,[cmd\8] ' send command
    Input dta ' wait acknowledge 
    Low clk
    While dta=1 
    Wend
    PulsOut clk,10 ' send ack 
    While dta=0 
    Wend
    While dta=1 ' wait for conversion to complete
    Wend 
    Low clk
    ShiftIn dta,clk,0,[result.highbyte\8] ' get first byte
    Low dta 
    PulsOut clk,10 ' send ack 
    ShiftIn dta,clk,0,[result.lowbyte\8] ' get second byte
    Low dta 
    PulsOut clk,10 ' send ack 
    ShiftIn dta,clk,0,[chksum\8] ' get third byte (checksum)
    High dta 
    PulsOut clk,10 ' send ack 
    Input dta ' End of Transmission
    Input clk 
    
    Return
    
    '** Dewpoint Calculation
    ' See: SENSIRION Application Note "Dewpoint Calculation"
    ' logEW = (0.66077+7.5*T/(237.3+T)+(log(RH)-2)
    ' DP = ((0.66077-logEW)*237.3)/(logEW-8.16077)
    
    DewPoint:
    
    TempDP=Temp/10
    logEW=6608
    sign=TempDP.bit15
    wz=ABS TempDP
    wx=(7*wz)+(wz/2) 
    wy=2373+wz
    wj=wx/wy
    For ix=15 to 0 step -1
    wx=(wx//wy)<<1
    wz.bit0(ix)=wx/wy
    Next
    wx=(-sign^((wj*10000)+(wz**10000)))+sign 
    logEW=wx+logEW
    wx=RHtc
    wj=(NCD wx) - 1
    wx=wx<<(15-wj)
    wz=0
    For ix=14 to 0 step -1
    wy=wx**wx
    wz.bit0(ix)=wy.bit15
    bt=~wy.bit15
    wx=(wy<<bt)+(bt &&="" wx.bit15)="">
    Next
    
    wx=((wj*4000)**49321)+(wz**6021)
    logEW=wx+logEW-30000 
    sign=logEW.bit15
    logEW=(-sign^(((ABS logEW)+2)/4))+sign
    wx=1652-logEW
    sign=~wx.bit15
    wx=ABS wx
    wy=20402-logEW
    wj=wx/wy
    
    For ix=15 to 0 step -1
    wx=(wx//wy)<<1
    wz.bit0(ix)=wx/wy
    Next
    
    DP=((23730**wz)+5)/10
    DP=(-sign^DP)+sign
    
    Return
    
    WaitSensor:
    result=4096
    Loop:
    result=result-1
    IF dta && result.bit11 Then Loop
    Return
    End
    </bt)+(bt>
    Last edited by ScaleRobotics; - 5th January 2011 at 04:02. Reason: added code tags

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 12:13
  2. real time clock - PCF8583
    By maria in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th April 2010, 15:41
  3. Real time clock ICs
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 66
    Last Post: - 20th October 2008, 16:05
  4. Real time clock... what a headache!
    By Eng4444 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 8th June 2006, 21:56
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

Members who have read this thread : 1

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