Write Onewire data toa I2C memory / read ASCI


Results 1 to 40 of 68

Threaded View

  1. #26
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    Eugeniu, below are some ideas on how to modify your code with the help of an LCD. This should provide all the info for the conversion, decoding, and displaying of the temp based on the DS18S20 (which matches your previous posted table). All based on your code, SKIMASK's suggestions, and readily available code on the forum.

    modifications to variables
    Code:
    Cold_Bit VAR temperature.Bit11	' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Half_Deg_Bit VAR temperature.Bit0	' 0.5deg Bit
    Sign VAR temperature.HIGHBYTE	' +/- sign for temp display
    temperature_int VAR temperature.LOWBYTE	' integer part of temperature   
    temperature_dec VAR BYTE	' fractional part of temperature
    digit var byte[5]
    reading temperature (this is not better than what you had, just short and simple)
    Code:
    'read temperature
    OWOut DQ, 1, [$CC, $44]	' Start temperature conversion
    pause 1000	' Wait max conversion time
    OWOut DQ, 1, [$CC, $BE]	' Read the temperature
    OWIn DQ, 0, [temperature_int, sign]	' Store temperature on variable
    storing raw temperature on EEPROM
    Code:
    'store raw value of temperature in EEPROM (like SKIMASK suggested)
    adr = 24
    i2cwrite i2cdat, i2cclk, $a0, adr,[sign]
    adr = 25
    i2cwrite i2cdat, i2cclk, $a0, adr,[temperature_int]
    reading raw temperature from EEPROM
    Code:
    'read raw temperature from EEPROM
    adr = 24
    i2cread i2cdat, i2cclk, $a0, adr, sign
    adr = 25
    i2cread i2cdat, i2cclk, $a0, adr, temperature_int
    decoding temperature (including negative temperatures)
    Code:
    'decode temperature as needed (this will decode both positive and negative temperatures)
    IF Cold_bit = 1 THEN	' If Cold_Bit = 1, negative temperature
    	Sign  = "-"
    	temperature_int = (255 - temperature_int) + 1	' 2s Complement
    ELSE	' If Cold_Bit = 0, positive temperature
    	Sign  = "+"
    ENDIF
    temperature_int = temperature_int / 2	' Strip LSB from temperature reading
    IF Half_Deg_Bit = 1	' If Half_Deg_Bit = 1, add half degree to result
    	temperature_dec = 5
    ELSE
    	temperature_dec = 0
    ENDIF
    displaying decoded temperature on LCD
    Code:
    'to display temperature on LCD
    lcdout sign , DEC2 (temperature_int) , "," , DEC2 (temperature_dec)
    storing decoded temperature digits
    Code:
    'to extract digits
    digit[5] = temperature_int dig 2
    digit[4] = temperature dig 1
    digit[3] = temperature dig 0
    digit[2] = ","
    digit[1] = temperature_dec dig 0
    digit[0] = 0
    P.S. When posting use the "code" tags to wrap the code and display it nice and tidy. Also use the "quote" tags when quoting somebody; again it displays nice and tidy.
    Last edited by languer; - 20th October 2008 at 18:06.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  3. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  4. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

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