Write Onewire data toa I2C memory / read ASCI


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    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.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    One of the key phrases to be taken from this statement:
    Quote Originally Posted by languer View Post
    ..........................
    All based on your code, SKIMASK's suggestions, and readily available code on the forum...........................
    And this might help your post formatting a bit...
    http://www.picbasic.co.uk/forum/misc...bbcode#imgcode

  3. #3
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    And this might help your post formatting a bit...
    http://www.picbasic.co.uk/forum/misc...bbcode#imgcode
    Was very usefully !

    Thank you .

    PS. I 'll be very bussy for a few day , and after this I'll work again to my project . I 'll tell you what I can doing .

  4. #4
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Code:
    [QUOTE=languer;64516]Eugeniu, below are some ideas on how to modify your code with the help of an LCD.
    Thank you for your try to halp me , But remember I do not use a LCD display !


    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
    I do not use it , becose I do not know it . Thanks !

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    Thank you for your try to halp me , But remember I do not use a LCD display !
    But you did say earlier that you do HAVE an LCD, and if you know how to use it, and can make it work, then why not use it to help you find your problem.
    And with those code snippets above, you should be able to pull out of them the chunks of code you may and/or may not need to get your project working, whether it be displayed on an LCD (which would be very handy) or LED matrix or on punch cards.

    I do not use it , becose I do not know it . Thanks !
    Which is why I put that link in post #57 above. That way you can learn how to use those 'tags'.
    Last edited by skimask; - 21st October 2008 at 18:55.

  6. #6
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    But you did say earlier that you do HAVE an LCD, and if you know how to use it, and can make it work, then why not use it to help you find your problem


    I have try , be sure . I use a test program on LCD , bat there it work , on LEDS display not . For LCD are very usefully DEC ; HEX;...commands . I'try to change the kind of writing text ,(in my programme) ,to use " SELECT CASE " for binary or hexa byte .

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    I have try , be sure . I use a test program on LCD , bat there it work , on LEDS display not . For LCD are very usefully DEC ; HEX;...commands . I'try to change the kind of writing text ,(in my programme) ,to use " SELECT CASE " for binary or hexa byte .
    So are you saying that everything works as you want it to work if you are using the LCD?
    There is no need to rewrite the entire program!!! Your answers have been practically handed to you in previous posts, with example provided. The only thing left to do is to write the code for you.

  8. #8
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    So are you saying that everything works as you want it to work if you are using the LCD?
    Yes ! But not on this plate . On this plate (Leds display )I use a PIC 16F876 and I have 3 free pins only on it . I can not install a LCD. Will be very usefully . I am not sure ( in my mind )every time that sensor work . In future I try to change PIC with 16F877 ,to can have together Leds and LCD display for ilk sensor .

    There is no need to rewrite the entire program!!! Your answers have been practically handed to you in previous posts, with example provided. The only thing left to do is to write the code for you
    I am not sure that I understand what you say !

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    Yes ! But not on this plate .
    Ok, as long as the code works in one place... I understand you don't have enough pins to run the LCD on this particular board and need to use the matrix'd LEDs...

    I am not sure that I understand what you say !
    Meaning that the posts referring to the use of the DIG function with bytes/words/whatever are most likely what you need to pull the individual digits out of the bytes/words/whatever to send to the LEDs...

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