Write Onewire data toa I2C memory / read ASCI


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Might I suggest that you back up in your process just a bit and practice/learn how to convert and display various types of numbers in general before trying to convert and display a result from a temperature sensor.
    You don't seem to understand that the references to the earlier posts that we are giving you have the some of the information and answers you need to finish your project, DIG is on of those, if not the only one you'll need to convert your data from the binary format to the ASCII format (along with a bit of simple addition) to send to your display subroutine.
    We do not have the hardware you have. We do not have the same 'vision' of the final project that you have, therefore, I think it is relatively unreasonable to ask others to write code FOR you, since that code that is written probably won't work for YOUR particular setup in the end. One thing that DOES work almost everytime though is trying to give a person the building blocks to start somewhere and end up somewhere else...

  2. #2
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Might I suggest that you back up in your process just a bit and practice/learn how to convert and display various types of numbers in general before trying to convert and display a result from a temperature sensor............................................ ...
    OK ! I ' ll do , be sure . Thank you all , for your help . If have you a new idea , pleace , let me know it .

    PS. I have tried all your ideas , and DIG , but they do not work .

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    OK ! I ' ll do , be sure . Thank you all , for your help . If have you a new idea , pleace , let me know it .
    PS. I have tried all your ideas , and DIG , but they do not work .
    I'm trying to help you out. I think in this case, it's a language thing...
    DIG should work for you...pulling individual digits out of the results and displaying them one by one. I don't know what else to say how or to say it for that matter that'll make more sense to you.

  4. #4
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I'm trying to help you out. I think in this case, it's a language thing...
    DIG should work for you...pulling individual digits out of the results and displaying them one by one. I don't know what else to say how or to say it for that matter that'll make more sense to you.
    Look here , is what I have tried :

    adr = 22
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 4+48 ]
    pause 15
    adr=25
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 3+48]
    pause 15
    adr=28
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 2 + 48]
    pause 15
    adr=31
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 1+ 48]
    pause 15
    adr = 34
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 0 + 48]
    pause 15

    ...on display I read 0 0 1 2 1 or 0 0 2 2 2 , and other numbers .

    I'll try to explain my program ( this side with display ) :
    after read a sign from eeprom program look in SELECT CASE CARACTER for a ASCI code and return a runing number >>>>


    SELECT CASE CARACTER

    CASE 65: SIR_NO=4 ;A
    CASE 66: SIR_NO=9 ;B
    CASE 67: SIR_NO=14 ;C
    CASE 68: SIR_NO=19 ;D
    CASE 69: SIR_NO=24 ;E
    CASE 70: SIR_NO=29 ;F
    CASE 71: SIR_NO=34 ;G
    CASE 72: SIR_NO=39 ;H
    CASE 73: SIR_NO=42 ;I
    CASE 74: SIR_NO=47 ;J
    CASE 75: SIR_NO=52 ;K
    CASE 76: SIR_NO=57 ;L
    CASE 77: SIR_NO=62 ;M
    CASE 78: SIR_NO=67 ;N
    CASE 79: SIR_NO=72 ;O
    CASE 80: SIR_NO=77 ;P
    CASE 81: SIR_NO=82 ;Q
    CASE 82: SIR_NO=87 ;R
    CASE 83: SIR_NO=92 ;S
    CASE 84: SIR_NO=97 ;T
    CASE 85: SIR_NO=102 ;U
    CASE 86: SIR_NO=107 ;V
    CASE 87: SIR_NO=112 ;W
    CASE 88: SIR_NO=117 ;X
    CASE 89: SIR_NO=122 ;Y
    CASE 90: SIR_NO=127 ;Z
    CASE 32: SIR_NO=132 ;SPATIU
    CASE 48: SIR_NO=137 ;0
    CASE 49: SIR_NO=140 ;1
    CASE 50: SIR_NO=145 ;2
    CASE 51: SIR_NO=150 ;3
    CASE 52: SIR_NO=155 ;4
    CASE 53: SIR_NO=160 ;5
    CASE 54: SIR_NO=165 ;6
    CASE 55: SIR_NO=170 ;7
    CASE 56: SIR_NO=175 ;8
    CASE 57: SIR_NO=180 ;9
    CASE 46: SIR_NO=185 ;.
    CASE 58: SIR_NO=188 ;:
    CASE 61: SIR_NO=193 ;=
    CASE 33: SIR_NO=196 ;!
    CASE 45: SIR_NO=201 ;-
    CASE 44: SIR_NO=204 ; ,
    case 42: SIR_no=209 ; *
    CASE 59: SIR_NO=212 ; ;

    After this go to a tabel and serch for this runing number -OFSET-,from where return a matrix with what leds are on .

    TABLOU:
    LOOKUP OFSET,[_
    $3F,$48,$48,$48,$3F,_ ;A 0-4
    $36,$49,$49,$49,$7F,_ ;B 4-9
    $22,$41,$41,$41,$3E,_ ;C 9-14
    $3E,$41,$41,$41,$7F,_ ;D 14-19
    $41,$49,$49,$49,$7F,_ ;E 19-24
    $40,$48,$48,$48,$7F,_ ;F 24-29
    $2E,$49,$49,$41,$3E,_ ;G 29-34
    $7F,$08,$08,$08,$7F,_ ;H 34-39
    $41,$7F,$41,_ ;I 39-42
    $40,$7E,$41,$01,$02,_ ;J 42-47
    $41,$22,$14,$08,$7F,_ ;K 47-52
    $01,$01,$01,$01,$7F,_ ;L 52-57
    $7F,$20,$10,$20,$7F,_ ;M 57-62
    $7F,$04,$08,$10,$7F,_ ;N 62-67
    $3E,$41,$41,$41,$3E,_ ;O 67-72
    $30,$48,$48,$48,$7F,_ ;P 72-77
    $3D,$42,$45,$41,$3E,_ ;Q 77-82
    $31,$4A,$4C,$48,$7F,_ ;R 82-87
    $26,$49,$49,$49,$32,_ ;S 87-92
    $40,$40,$7F,$40,$40,_ ;T 92-97
    $7E,$01,$01,$01,$7E,_ ;U 97-102
    $7C,$02,$01,$02,$7C,_ ;V 102-107
    $7E,$01,$0E,$01,$7E,_ ;W 107-112
    $63,$14,$08,$14,$63,_ ;X 112-117
    $70,$08,$07,$08,$70,_ ;Y 117-122
    $61,$51,$49,$45,$43,_ ;Z 122-127
    $00,$00,$00,$00,$00,_ ;SPATIU 127-132
    $3E,$51,$49,$45,$3E,_ ;0 132-137
    $01,$7F,$21,_ ;1 137-140
    $31,$49,$45,$43,$21,_ ;2 140-145
    $46,$69,$51,$41,$42,_ ;3 145-150
    $04,$7F,$24,$14,$0C,_ ;4 150-155
    $4E,$51,$51,$51,$72,_ ;5 155-160
    $06,$49,$49,$29,$1E,_ ;6 160-165
    $60,$50,$48,$47,$40,_ ;7 165-170
    $36,$49,$49,$49,$36,_ ;8 170-175
    $3C,$4A,$49,$49,$30,_ ;9 175-180
    $00,$00,$00,$00,$01,_ ;. 180_185
    $00,$24,$00,_ ;: 185_188
    $28,$28,$28,$28,$28,_ ;= 188_193
    $00,$7D,$00,_ ;! 193_196
    $00,$08,$08,$08,$00,_ ;- 196_201
    $00,$02,$01,_ ;, 201_204
    $2A,$14,$3E,$14,$2A,_ ;* 204_209
    $00,$0A,$01],DATE

    I put this OFSET on a PIC port and scroll to left on display .

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Eugeniu View Post
    Look here , is what I have tried :
    adr = 22
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 4+48 ]
    ....and so on and so on....
    Right. I understand what you are trying to do, with the EEPROM and the LED matrix's and such. It's a relatively common project.
    What you aren't understanding is that you are only writing ONE BYTE at a time with those statements, not 3 at a time as your changing addresses would indicate.
    And one other thing is 'precedence'. I'm not sure if it's applicable in this case, but...
    In your statement above...
    Code:
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 4+48 ]
    How does that get interpreted?
    Assume temperature.lowbyte = 123
    You are trying to retrieve the 4th (actually 5th) digit of a byte value to which there can only be 3 digits.
    Another thing, still assuming temperature.lowbyte = 123, and assume that 'dig 4' is actually 'dig 0'...
    Will that statement return "3" + 48 or does it try to return the 52nd digit of temperature.lowbyte?
    A better way to put that statement might be:
    Code:
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[ ( temperature.LOWBYTE dig 4 ) + 48 ]
    And again, trying to retrieve the 4th digit of a 3 digit value (at most) won't work...

    Since you have obviously modified your program, could you post the whole thing again, including all the relevant information, PIC type, hardware setup, etc.etc.

  6. #6
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    skimask;64450]Right. I understand what you are trying to do, with the EEPROM and the LED matrix's and such. It's a relatively common project.
    What you aren't understanding is that you are only writing ONE BYTE at a time with those statements, not 3 at a time as your changing addresses would indicate.
    And one other thing is 'precedence'. I'm not sure if it's applicable in this case, but...
    In your statement above...
    Code:
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[temperature.LOWBYTE dig 4+48 ]
    How does that get interpreted?
    Assume temperature.lowbyte = 123
    You are trying to retrieve the 4th (actually 5th) digit of a byte value to which there can only be 3 digits.

    I understand what you say , but I try something , to see what display

    Another thing, still assuming temperature.lowbyte = 123, and assume that 'dig 4' is actually 'dig 0'...
    Will that statement return "3" + 48 or does it try to return the 52nd digit of temperature.lowbyte?
    A better way to put that statement might be:
    Code:
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[ ( temperature.LOWBYTE dig 4 ) + 48 ]

    Is not imprtant , + or - paranthesis I see on display the same result .

    For the result of " temperature.LOWBYTE " I do not understand what is this number .
    If I put

    adr = 24
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[(temperature dig 2) + 48]
    pause 15
    adr = 27
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[(temperature dig 1) + 48]
    pause 15
    adr = 30
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[(temperature dig 0) + 48]
    pause 15


    Obtein a number which is a hexa from a teperature ...968 ,975 - 2408,2421
    For a LCD display write DEC2 (temperature/100) "," DEC2 (temperature//100). But for me in this moment I do not know what to do !

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, so the parenthesis don't make a difference, no problem...Guess we're going to have to build this up from scratch...
    Do you have that LCD connected to your project? Is it working as you expect it to work (i.e. displays HELLO if you command it)

    EDIT: Never mind, obviously you do have the LCD connected...

    In reference to your I2CWRITE statements a few posts ago...
    adr = 24
    i2cwrite I2CDAT, I2CCLK, $A0, adr,[(temperature dig 2) + 48]
    pause 15.......and so on.....
    You do NOT need to store temperature in the manner you are storing it. What you are doing in effect is storing the ASCII equivalent of your temperature value in 3 bytes, then retrieving that same result and trying to display the ASCII result of each of those bytes...in effect, display the ASCII values of the ASCII values of the bytes originally stored....sort of like looking at a camera which is looking at you looking at a camera which is looking at you...infinite regression...

    It looks to me like you're doing twice as much work as you need to do!
    Try to store the temperature like this:
    Code:
    adr = 24
    i2cwrite i2cdat, i2cclk, $a0, adr,[temperature.highbyte]
    adr = 25
    i2cwrite i2cdat, i2cclk, $a0, adr,[temperature.lowbyte]
    This will store the WORD variable temperature in two bytes as required.
    Then for retrieving that same value:
    Code:
    adr = 24
    i2cread i2cdat, i2cclk, $a0, adr, temperature.highbyte
    adr = 25
    i2cread i2cdat, i2cclk, $a0, adr, tempearture.lowbyte
    .............
    lcdout DEC2 (temperature/100) , "," , DEC2 (temperature//100)
    This should display on the LCD is in fact the temperature sensor and it's code are working properly.

    To get the individual digits from this value for display on the LED matrix instead of the LCD:
    Code:
    adr = 24
    i2cread i2cdat, i2cclk, $a0, adr, temperature.highbyte
    adr = 25
    i2cread i2cdat, i2cclk, $a0, adr, tempearture.lowbyte
    .............
    digit var byte[5]
    digit[5] = temperature dig 4
    digit[4] = temperature dig 3
    digit[3] = temperature dig 2
    digit[2] = ","
    digit[1] = temperature dig 1
    digit[0] = temperature dig 0
    ............
    Last edited by skimask; - 20th October 2008 at 05:03.

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


    Did you find this post helpful? Yes | No

    Post

    Ok, look at the info below. Most of it came from http://www.rentron.com/PicBasic/one-wire3.htm and your posted program.

    This may not be the most elegant method, but it should give you a start. I still do not think there is any real value in adding all the "text" characters to the EEPROM, but that's a different story.

    Code:
    ' Additional Variables
    Cold_Bit		VAR temperature.Bit11	' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Sign			VAR BYTE	' +/- sign for temp display
    temperature_int		VAR BYTE	' integer part of temperature   
    temperature_dec		VAR BYTE	' fractional part of temperature
    
    ' Temperature Readout and manipulation
    OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
    IF Cold_Bit = 0 THEN	' If Cold_Bit = 0, positive temperature
        Sign  = "+"
        temperature = temperature & $00FF	' Mask lower byte of temperature
        (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    ELSE	' If Cold_Bit = 1, negative temperature
        Sign  = "-"
        temperature = temperature & $00FF	' Mask lower byte of temperature
        (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    ENDIF
    
    'separate interger part from decimal part
    temperature_int = ((temperature DIG 4) * 10) + (temperature DIG 3)	' integer part of temperature
    temperature_dec = ((temperature DIG 1) * 10) + (temperature DIG 0)	' fractional part of temperature
    
    'write digits to EEPROM
    i2cwrite I2CDAT, I2CCLK, $A0, 71,[(temperature DIG 4)+48]	'load EEPROM with integer part
    pause 5
    i2cwrite I2CDAT, I2CCLK, $A0, 72,[(temperature DIG 3)+48]	'load EEPROM with integer part
    pause 5
    i2cwrite I2CDAT, I2CCLK, $A0, 74,[(temperature DIG 2)+48]	'load EEPROM with decimal part
    pause 5  
    i2cwrite I2CDAT, I2CCLK, $A0, 75,[(temperature DIG 1)+48]	'load EEPROM with decimal part
    pause 5

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by languer View Post
    Ok, look at the info below. Most of it came from http://www.rentron.com/PicBasic/one-wire3.htm and your posted program.

    This may not be the most elegant method, but it should give you a start. I still do not think there is any real value in adding all the "text" characters to the EEPROM, but that's a different story.
    I think his problem is extracting the individual digits out of the byte values to display on the LED matrix's, by using DIG, and he hasn't figured that part out yet, which is why I suggested earlier since he's got an LCD, to play with that first and get used to everything (and to find out if his temp sensor is actually working in the first place). Then build it all back up to displaying the reading on the LED matrix.

  10. #10
    Join Date
    Nov 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by languer View Post
    Ok, look at the info below. Most of it came from http://www.rentron.com/PicBasic/one-wire3.htm and your posted program.

    This may not be the most elegant method, but it should give you a start. I still do not think there is any real value in adding all the "text" characters to the EEPROM, but that's a different story.
    ...................................[/CODE]
    Thank you for link . I do not find your example on this link . Tell me a link for it , or post all example .
    I am looking for little time on this program ...and I see that they use LCD display with " DEC " command .
    Last edited by Eugeniu; - 19th October 2008 at 19:22.

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