Serin serout problem - Page 4


Closed Thread
Page 4 of 9 FirstFirst 12345678 ... LastLast
Results 121 to 160 of 337
  1. #121
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok eee, seems to be working now, am I awake....
    thank you thank you
    i will try the wireless

    what is this line for (was for , or intended to)
    'templo = converts[templo] : temphi = converts[temphi]

  2. #122
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ok eee, seems to be working now, am I awake....
    thank you thank you
    i will try the wireless

    what is this line for (was for , or intended to)
    'templo = converts[templo] : temphi = converts[temphi]
    Well, what program are you running right now? I changed some stuff and was about to post it...but if you say it's working correctly at both ends, then I'll go with that.... So, repost the program you're running now (if it works), so I can remember what the line above did.

  3. #123
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    using post 118

    it works wireless,
    does it have to do with the encoding technique ?
    but most often its showing good temp.

  4. #124
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    could I add a 10v voltage regulator for the RF transmitter to boost up the signal ? I am using the rentron 433mhz chips tws

  5. #125
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    using post 118

    it works wireless, I get a lot glitches meaning temperature showing weird numbers like 930 , 445, etc.. it stays at those odd numbers for 3-5 seconds sometimes,
    does it have to do with the encoding technique ?
    but most often its showing good temp.
    Glitches - Probably has to do with the encoding technique because the data isn't encoded (I commented that part out in post #118), but the 'training' bytes are encoded.

    Maybe try to add a few more $55 to the serout line in the transmit section. And make sure the char_pacing isn't in the define sections anymore.

  6. #126
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    could I add a 10v voltage regulator for the RF transmitter to boost up the signal ? I am using the rentron 433mhz chips tws
    If you're running the module at 5v now, you're good for about 500ft (that's what I've gotten at 9600 a few times, a few errors, but it still worked). and if you read the datasheet, you'll see that you have to run your data input line to the TX module at the same voltage range as your power input.

    I've ran that TX module at 2.5v before and gotten 100ft without troubles.

  7. #127
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I di dwhat you told me removing the char_spac adding more $55, its worst now,
    its constantly showing 360, 445, and sometime the temperature
    more often 445

  8. #128
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I di dwhat you told me removing the char_spac adding more $55, its worst now,
    its constantly showing 360, 445, and sometime the temperature
    more often 445
    Well, I would think that taking out the char_pacing and adding $55 would help it, but apparently not since none of the data is being encoded, the receiver is picking the $55 up as actual data or something.
    Try it the other way around, but do one thing at a time.
    1) No char_pacing - a single $55, no $55 (which should not work!)
    2) no char_pacing - two $55's
    3) no char_pacing - 4 $55's
    4) small char_pacing - single $55 (I would think that any char_pacing value above 4000 would mess things up bad enough not to work at all)
    ....
    ....
    etc.
    See which one works out the best...
    OR....
    you could add you manchester encoding routine back into the program (from way back when, ya know, page 1!!!) and see what happens.

  9. #129
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I added DEFINE CHAR_PACING 2000
    also 1000 works good with four $55
    But it seems to be long to change the temperature, sometime the receiver seems to hang there with its value.

  10. #130
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    HI, ok
    I learned a lot in these four pages of posts,
    What i did now I took the original program and modified it (serin, definnes, $55 , $aa ...
    it works great now
    I got a couple of glitches when I took the reciever down in the basement ( one floor below in a zig zag)
    if you would like to see the code i could post it,
    Last edited by lerameur; - 27th December 2006 at 20:25.

  11. #131
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    HI, ok
    I learned a lot in these four pages of posts,
    What i did now I took the original program and modified it (serin, definnes, $55 , $aa ...
    it works great now
    I got a couple of glitches when I took the reciever down in the basement ( one floor below in a zig zag)
    if you would like to see the code i could post it,
    Sure, maybe I can streamline it a bit or something...who knows...

    Then again...maybe I better not touch it! It works...leave it!
    But seriously, I'll take a look...

  12. #132
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I added DEFINE CHAR_PACING 2000
    also 1000 works good with four $55
    But it seems to be long to change the temperature, sometime the receiver seems to hang there with its value.
    Those temp sensors aren't designed to respond to temp changes RIGHT NOW. If they did, they'd be all over the place. Remember, you have a certain amount of mass that you have to heat or cool and it takes X amount of time to do that, especially buried down in the middle of the blob of goo where the sensing element actually is. Fill a glass with ice cubes, fill the rest of the glass with water, let it sit for a bit, then dip the sensor in the water. It should read just a hair over, if not right on 0C/32F. You can add a bit of calibration by doing that. I don't think I'd try the boiling water for the other end though!

  13. #133
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    well here goes,
    I still need to do work, because I dont think it measures negatives temperature. Not sure yet how i am going to do it, but I will be

    Transmitter:
    'TRANSMIT PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    DQ var PortB.4
    temp var word

    temperature var word
    count_remain var byte
    count_per_c var byte
    counter var byte
    tempc var word
    dataout var word
    dataout2 var word
    datain var word
    array var word
    encoded1 var word
    encoded2 var word
    encoded22 var word
    encoded11 var word


    loop:
    owout DQ,1,[$cc]
    owout DQ,0,[$44]
    Pause 500
    owout DQ,1,[$cc]
    owout DQ,0,[$be]
    owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
    '50
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempc = (((temperature *9) / 5)+3200)
    dataout = temperature / 100
    dataout2 = temperature

    encoded1 =temperature.LowBYTE
    encoded2 =temperature.HighBYTE

    For counter=0 TO 7
    IF encoded1.0[counter]=0 Then
    encoded11.0[counter*2]=0
    encoded11.0[counter*2+1]=1
    Else
    encoded11.0[counter*2]=1
    encoded11.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF encoded2.0[counter]=0 Then
    encoded22.0[counter*2]=0
    encoded22.0[counter*2+1]=1
    Else
    encoded22.0[counter*2]=1
    encoded22.0[counter*2+1]=0
    EndIF
    Next counter
    lcdout $FE,1
    LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

    serout portb.2, n2400, [$55, $55, $55, $55, $aa]
    serout portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
    goto loop

    End


    Receiver:
    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    '16
    datain2 var word :temp var word
    datain var word
    dataout var word
    counter var byte
    temperature var word
    encoded1 var word
    encoded2 var word
    encoded11 var word
    encoded22 var word

    pause 2000
    '28
    loop:

    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    '36
    serin portb.2, n2400, encoded22.HighBYTE
    serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded11.HighBYTE
    serin portb.2, n2400, encoded11.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2]
    encoded2.0[counter]=encoded22.0[counter*2]
    Next counter

    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2

    lcdout $FE,1
    LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"


    goto loop
    end

  14. #134
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    well here goes,
    I still need to do work, because I dont think it measures negatives temperature. Not sure yet how i am going to do it, but I will be

    Transmitter:
    'TRANSMIT PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    DQ var PortB.4 : temp var word : temperature var word
    count_remain var byte : count_per_c var byte : counter var byte
    tempc var word : dataout var word : dataout2 var word : datain var word
    array var word : encoded1 var word : encoded2 var word
    encoded22 var word : encoded11 var word

    loop:
    owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc]
    owout DQ,0,[$be]
    owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
    '50
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempc = (((temperature *9) / 5)+3200) : dataout = temperature / 100
    dataout2 = temperature

    encoded1 = temperature.LowBYTE : encoded2 =temperature.HighBYTE

    For counter=0 TO 7
    IF encoded1.0[counter]=0 Then
    encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
    Else
    encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF encoded2.0[counter]=0 Then
    encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
    Else
    encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
    EndIF
    Next counter
    lcdout $FE,1
    LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

    serout portb.2, n2400, [$55, $55, $55, $55, $aa]
    serout portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
    goto loop

    End


    Receiver:
    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250

    '16
    datain2 var word :temp var word : datain var word : dataout var word
    counter var byte : temperature var word : encoded1 var word
    encoded2 var word : encoded11 var word : encoded22 var word

    pause 2000
    '28
    loop:

    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    '36
    serin portb.2, n2400, encoded22.HighBYTE
    serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded11.HighBYTE
    serin portb.2, n2400, encoded11.LowBYTE
    'you can combine the serin's into one statement (now that we got the bracket thing straightened out!!!)

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2]
    encoded2.0[counter]=encoded22.0[counter*2]
    Next counter

    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1 : temperature.HighBYTE = encoded2

    lcdout $FE,1
    LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

    goto loop
    end

    Looks good enough. As far as handling the negative numbers, I'd do all the math at the receiving end, that way you can preserve the sign bit and work with it there rather than try to worry about how to transmit the sign bit along with the real temperature and screwing it up in the process.

    The negative temperature is nothing more than using 2's complement math. Google it, re-read the -1820 datasheet. It's not that hard to handle those cases. It just takes a bit of creative math to work it out. And PBP can handle it if you work it right (hint: re-read the PBP manual, the SEROUT can handle 'signed' integers, make that work for you in the receiver code).

  15. #135
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    hi, I have this simple if then statement, it givs me four mistakes.. It tells me I need and endif and also its abad expression , this is straight out of the pbp manual. what is wrong with it

    IF temperature.bit11 = 1 Then zerotemp


    zerotemp
    program here

  16. #136
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    hi, I have this simple if then statement, it givs me four mistakes.. It tells me I need and endif and also its abad expression , this is straight out of the pbp manual. what is wrong with it

    IF temperature.bit11 = 1 Then zerotemp


    zerotemp
    program here
    If temperature.11 = 1 then goto zerotemp (don't need the goto but it always keeps me straight, and bit11 should work, but I just use 11 for no reason in particular)

    zerotemp: (you didn't have a colon)
    program here

  17. #137
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    naa, i was initializing zerotemp dee.
    I am going to put the calculation on the receiver side only, this is getting real confusing.
    The reason i did not want to do that is I am sending 4 byte of coded information. I want to have a high accuracy, so i would like to send the count_per_c and count_remain and in the data sheet. that will add more bytes, If I take the raw information and send it, it will be 4 bytes or 8 encoded byte to send. Is this do able ?
    I mean is it too much to send wireles ?
    k

  18. #138
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    anywau here si the code fo the sending part:
    i am just worried about the two serout line, should I put it into one line, or is it just the same like this,

    I am leaving now, coming back ina few hours


    'TRANSMIT PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    DQ var PortB.5
    temp var word

    temperature var word
    count_remain var byte
    count_per_c var byte
    counter var byte

    encoded1 var word
    encoded2 var word
    encoded22 var word
    encoded11 var word
    encoded33 var word
    encoded44 var word

    loop:
    owout DQ,1,[$cc]
    owout DQ,0,[$44]
    Pause 500
    owout DQ,1,[$cc]
    owout DQ,0,[$be]
    owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
    '50

    encoded1 =temperature.LowBYTE
    encoded2 =temperature.HighBYTE

    For counter=0 TO 7
    IF encoded1.0[counter]=0 Then
    encoded11.0[counter*2]=0
    encoded11.0[counter*2+1]=1
    Else
    encoded11.0[counter*2]=1
    encoded11.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF encoded2.0[counter]=0 Then
    encoded22.0[counter*2]=0
    encoded22.0[counter*2+1]=1
    Else
    encoded22.0[counter*2]=1
    encoded22.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF count_remain.0[counter]=0 Then
    encoded33.0[counter*2]=0
    encoded33.0[counter*2+1]=1
    Else
    encoded33.0[counter*2]=1
    encoded33.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF count_per_c.0[counter]=0 Then
    encoded44.0[counter*2]=0
    encoded44.0[counter*2+1]=1
    Else
    encoded44.0[counter*2]=1
    encoded44.0[counter*2+1]=0
    EndIF
    Next counter


    lcdout $FE,1
    LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"

    serout portb.2, n2400, [$55, $55, $55, $55, $aa]
    serout portb.2, n2400, [encoded11.HighBYTE, encoded11.LowBYTE, encoded22.HighBYTE, encoded22.LowBYTE ]
    serout portb.2, n2400, [encoded33.HighBYTE, encoded33.LowBYTE, encoded44.HighBYTE, encoded44.LowBYTE ]
    goto loop

    End

  19. #139
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    naa, i was initializing zerotemp dee.
    I am going to put the calculation on the receiver side only, this is getting real confusing.
    The reason i did not want to do that is I am sending 4 byte of coded information. I want to have a high accuracy, so i would like to send the count_per_c and count_remain and in the data sheet. that will add more bytes, If I take the raw information and send it, it will be 4 bytes or 8 encoded byte to send. Is this do able ?
    I mean is it too much to send wireles ?
    k
    I send strings and strings of data using the TWS/RWS modules without much problem at all. Of course I get messed up data once in awhile, that's what error detection is for (checksums, etc.). 4/8 bytes is fine...1000 bytes is fine. It's all in how you want to send it, break it down, detect errors, etc. Just create and use LEDAWDTP (lerameur's error detection and wireless data transfer protocol).

    I agree...send only the raw information, then do the math at the receiver end, again, with some error correction. For instance, you get one reading, save it placeA and display it...you get the next reading, save it in placeB. If the placeB reading is higher than placeA, then increment placeA by one, same thing is it's lower, decrement it by one. That way, a one-time reading that's 'out in the weeds' because of bad data won't neccessarily show up on the output as a fluctuating result.

  20. #140
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Now that the whole thing is working, you can probably condense those serout lines down into one line...try it and find out...
    That and it makes the program shorter on the screen so you don't have to scroll thru so much stuff...

    'TRANSMIT PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    DQ var PortB.5 : temp var word : temperature var word : count_remain var byte : count_per_c var byte : counter var byte
    encoded1 var word:encoded2 var word:encoded22 var word:encoded11 var word:encoded33 var word:encoded44 var word

    loop:
    owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc] : owout DQ,0,[$be]
    owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
    '50

    encoded1 =temperature.LowBYTE : encoded2 =temperature.HighBYTE

    'I'd put these encoding/decoding sections into their own subroutine to GOSUB to...
    For counter=0 TO 7
    IF encoded1.0[counter]=0 Then
    encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
    Else
    encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF encoded2.0[counter]=0 Then
    encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
    Else
    encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF count_remain.0[counter]=0 Then
    encoded33.0[counter*2]=0 : encoded33.0[counter*2+1]=1
    Else
    encoded33.0[counter*2]=1 : encoded33.0[counter*2+1]=0
    EndIF
    Next counter

    For counter=0 TO 7
    IF count_per_c.0[counter]=0 Then
    encoded44.0[counter*2]=0 : encoded44.0[counter*2+1]=1
    Else
    encoded44.0[counter*2]=1 : encoded44.0[counter*2+1]=0
    EndIF
    Next counter


    lcdout $FE,1 : LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"

    serout portb.2, n2400,[$55,$55,$55,$55,$aa,encoded11.HighBYTE,encoded11.L owBYTE,encoded22.HighBYTE]
    serout portb.2, n2400,[encoded22.LowBYTE,encoded33.HighBYTE,encoded33.Low BYTE,encoded44.HighBYTE]
    serout portb.2, n2400,[encoded44.LowBYTE]
    goto loop
    Last edited by skimask; - 28th December 2006 at 16:16.

  21. #141
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    OK, I must be getting lucky, I'm not getting many mistakes as before. The system works now, the sending code is good. The receiving is good for positive celcius, For some undetermined reason it is not giving the right Ferenheit degrees, and I am using the same math equation as before to translate from C to F.
    I am now working on the negative celcius and also in that scenatio there is two cases, positive and negative F ...
    I will the subroutine for later, I never touched it before so I will do it at the end once everything is working

    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    counter var byte : temperature var word : encoded1 var word : encoded2 var word : encoded3 var byte
    encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
    count_remain var byte : count_per_c var byte : temp var byte : tempc var byte
    pause 2000

    loop:
    '23
    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
    serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
    encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
    Next counter
    '41
    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2
    count_remain = encoded3
    count_per_c = encoded4

    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempc = (((temperature *9) / 5)+3200)

    lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
    goto loop

    Zerotemp:
    temperature = temperature >> 1 'removing lowest bit
    for counter=0 to 14 ' 2's compliment, starting to invert all the digits
    if temperature.0[counter] = 1 then temperature.0[counter] =1
    if temperature.0[counter] = 0 then temperature.0[counter] =0
    next counter
    temperature = temperature + 1 ' 2,s compliment ends by adding a one

    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempc = (((temperature *9) / 5)+3200)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
    goto loop


    end

  22. #142
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    for one thing, tempc should be tempf shouldn't it?
    Another thing, if your temp value (which I assume is multiplied by 100 by that conversion/correction thing you've got going on) is above 7281, you'll overflow your 16 bit tempc value (65536 / 9 = 7281.xxx). So try dividing by 5 first, then multiply by 9.

    tempc = ( ( ( temperature / 5 ) * 9 ) + 3200 )

    another thing...what are you trying to do with the lcdout line?
    lcdout $FE,$C0,"TempF:",dec (tempc/100),".",dec2 tempc >>1," ",$DF,"F"

    I think what you really mean is:
    lcdout $fe,$c0,"TempF:",DEC3 (tempc/100),".",DEC2 (tempc//100)," ",$DF,"F"

    use the remainder (modulus) ( // ) function, not the shift ( >> ) function.

  23. #143
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    its working good, now, I think I have a problem with the 2,s compliment, working on it
    I am just doing 2,s compliment, I get all 1,s at the output


    Zerotemp:
    temperature = temperature >> 1 'removing lowest bit
    temperature1 = temperature
    for counter=0 to 6 ' 2's compliment, starting to invert all the digits
    if temperature.0[counter] = 1 then temperature.0[counter] =0
    if temperature.0[counter] = 0 then temperature.0[counter] =1
    next counter
    'temperature = temperature + 1 ' 2,s compliment ends by adding a one

    'temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    'tempc = (((temperature *9) / 5) + 3200)

    lcdout $FE,1, "TempC: ", bin temperature1, ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", bin temperature , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop
    Last edited by lerameur; - 28th December 2006 at 22:36.

  24. #144
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I just flip these around and it works

    if temperature.0[counter] = 0 then temperature.0[counter] =1
    if temperature.0[counter] = 1 then temperature.0[counter] =0

  25. #145
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Zerotemp:
    temperature = temperature >> 1 'removing lowest bit
    temperature1 = temperature
    ------------------------------------------why are you removing the lowest bit?

    for counter=0 to 6 ' 2's compliment, starting to invert all the digits
    if temperature.0[counter] = 1 then temperature.0[counter] =0
    if temperature.0[counter] = 0 then temperature.0[counter] =1
    next counter
    ------------------------------------this will never work....follow it thru
    1. if temp.counter = 1 then set it to 0
    2. if it's zero set it to 1.....it just got set to zero by the above line!!!!!
    what you want is:

    for counter = 0 to 6
    if temperature.0[counter] = 1 then
    temperature.0[counter] = 0
    else
    temperature.0[counter] = 1
    endif

    or just use this:
    temperature = ~ temperature (bitwise inversion)



    'temperature = temperature + 1 ' 2,s compliment ends by adding a one

    'temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    'tempc = (((temperature *9) / 5) + 3200)

    lcdout $FE,1, "TempC: ", bin temperature1, ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", bin temperature , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    And you didn't change the temperature to doing the /5 first, and then the *9. If you leave it the way you've got it, you'll get an overflow when it gets really warm outside!

  26. #146
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    when it get to ZERO, it shows 655,
    then when it reach about -3 then it shows the right temp, weird..
    any idea?

  27. #147
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I just flip these around and it works

    if temperature.0[counter] = 0 then temperature.0[counter] =1
    if temperature.0[counter] = 1 then temperature.0[counter] =0
    See my post above referring to your post #114...your logic above is flawed also

    (temperature.0[counter] - just call it temp for right now)
    if temp is zero, set it to one. then go to the next line down
    if temp is one, set it to zero. again, it just got set to 1 on the line above!

  28. #148
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    when it get to ZERO, it shows 655,
    then when it reach about -3 then it shows the right temp, weird..
    any idea?
    Not wierd, you just have to fix a bunch of stuff....!

  29. #149
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    its all good now, exept foe that part between 0 to -5 degrees celcius,
    There is no grey area, if the bit 11 os 1, then goto zerotemp, the math is the same for -1 C or -10C....

    'RECEIVE PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTA ' Set LCD Data port
    DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    counter var byte : temperature var word : encoded1 var word : encoded2 var word : encoded3 var byte
    encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
    count_remain var byte : count_per_c var byte : temp var word : tempc var byte : tempF var word
    temperature1 var word
    pause 2000

    loop:
    '23
    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
    serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
    encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
    Next counter
    '41
    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2
    count_remain = encoded3
    count_per_c = encoded4

    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = (((temperature /5) *9 ) + 3200)

    lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    Zerotemp: ' cases when zero celcius and positive Fahrenheit
    temperature = temperature >> 1 'removing lowest bit
    temperature1 = temperature
    for counter = 0 to 6
    if temperature.0[counter] = 1 then
    temperature.0[counter] = 0
    else
    temperature.0[counter] = 1
    endif
    next counter

    temp = temp + 1 ' 2,s compliment ends by adding a one
    temp = temp >> 5

    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)
    if tempF = 0 then goto ZeroF

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    end
    Last edited by lerameur; - 29th December 2006 at 00:34.

  30. #150
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post

    ZeroF: ' cases when zero celcius and 0 Fahrenheit

    end
    You do realize that 0C is not 0F right?
    0C = 32F
    0F = -17.78C

    Maybe it would be easier (if you really need to display both C and F) if you'd convert your initial celsius reading from the serin statements over to the Kelvin scale (0C = 273K, 0K = -273C), add in the correction factors, and then convert them back, taking into account the + and - as needed right before displaying the final numbers
    Last edited by skimask; - 29th December 2006 at 01:31.

  31. #151
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    You do realize that 0C is not 0F right?
    0C = 32F
    0F = -17.78C
    ------------ at 0F the program jumps to ZeroF taking into account that now both C anf F are negative


    Maybe it would be easier (if you really need to display both C and F) if you'd convert your initial celsius reading from the serin statements over to the Kelvin scale (0C = 273K, 0K = -273C), add in the correction factors, and then convert them back, taking into account the + and - as needed right before displaying the final numbers
    ----------- If I do that I will still have three posibilities with the same conversion won't I?
    I mean
    1) +C and +F
    2) -C and +F
    3) -C and -F

  32. #152
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ----------- If I do that I will still have three posibilities with the same conversion won't I?
    I mean
    1) +C and +F
    2) -C and +F
    3) -C and -F
    And all based from the celsius value....
    1) if tempC > 0 then both C and F are positive
    2) if tempC => -17 and tempC <=0 then C is negative, F is positive
    3) if tempC < -17 then both C and F are negative

    or in Kelvin terms...
    1) if tempK > 273 then C/F +
    2) if tempK => 256 and tempK <=273 then C- and F+
    3) if tempK < 256 then C/F -

  33. #153
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes exactly, that,s what i meant, I omitted the numerical degrees.
    I believe this is what I have in my program.
    One glitch is that when is hits ZERO, it immediatly shows -5C, the conversion from C to F is good (making conversion from -5 to 23F) BUt it is not getting the right values between 0 to -5 C

  34. #154
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Well, this might be a bug...or not...the tempC to tempF conversion is done differently in the 2 spots...and so are the lines above that...2 different methods... Shouldn't everything be the same except for the display?

    Quote Originally Posted by lerameur View Post
    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = (((temperature /5) *9 ) + 3200)
    ..................................................

    Zerotemp: ' cases when zero celcius and positive Fahrenheit
    ...............
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    'maybe should be tempf = (((temperature /5) *9 ) + 3200) like it was above?

    if tempF = 0 then goto ZeroF

    end


    I'm not sure, you're doing it a bit different than I would do it... maybe it's one of those 'features' like Windows always has in it that Microsoft fixes every Tuesday

  35. #155
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
    So
    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    --- SO if I need to do the conversion : -17C to 1.4F
    so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

    k
    Last edited by lerameur; - 29th December 2006 at 02:44.

  36. #156
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
    So
    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    --- SO if I need to do the conversion : -17C to 1.4F
    so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

    k

    Zerotemp: ' cases when zero celcius and positive Fahrenheit
    temperature = temperature >> 1 'removing lowest bit
    temperature1 = temperature
    for counter = 0 to 6
    if temperature.0[counter] = 1 then
    temperature.0[counter] = 0
    else
    temperature.0[counter] = 1
    endif
    next counter



    ------------------------------------temp value right here not set up
    temp = temp + 1 ' 2,s compliment ends by adding a one
    temp = temp >> 5

    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)
    if tempF = 0 then goto ZeroF

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: ' cases when zero celcius and 0 Fahrenheit
    temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    Where is the first temp getting set at? I don't think it is. I think it's always $ab (left over $aa from the serin with 1 added).

  37. #157
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I just got up, looked at the program , wow , a mess I did yesterday....
    I have to go be back working on it this afternoon.

  38. #158
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    ok I changed it a bit, but it is still getting confused about the zero mark.
    stll showing +655.XX celcius
    another thing, the decimal values are going the opposite way in the negative ,
    meaning, -1.96 to -1.90 instead of -1.90 to -1.96
    I have dec2 temperature for the decimal I tried
    1- dec2 temperature but it do not work ...

    loop:
    '23
    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
    serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
    encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
    Next counter
    '41
    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2
    count_remain = encoded3
    count_per_c = encoded4

    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = (((temperature /5) *9 ) + 3200)

    lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    temperature = ~temperature +1
    '63
    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = 3200 -((temperature /5) * 9)
    if tempF <= 0 then goto ZeroF

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
    tempF = 3200 -((temperature /5) * 9)

    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    end

  39. #159
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    ok I changed it a bit, but it is still getting confused about the zero mark.
    stll showing +655.XX celcius
    another thing, the decimal values are going the opposite way in the negative ,
    meaning, -1.96 to -1.90 instead of -1.90 to -1.96
    I have dec2 temperature for the decimal I tried
    1- dec2 temperature but it do not work ...
    end

    So, I can assume that the positive temperature readings are all correct?

    Why are the 2nd and 3rd temp conversion formula's different from the 1st?
    t = 3200 - *5 / 9 instead of t = T*5/9 + 3200 (shortened, you know what they are)

    temperature = ( ~temperature ) + 1 try that also





    loop:
    '23
    waitfor55:
    serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

    waitforaa:
    serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

    serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
    serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
    serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
    serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

    For counter=0 TO 7 'decoding
    encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
    encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
    Next counter
    '41
    temperature= encoded1 ' putting back together as the original temperature
    For counter=0 TO 7
    temperature.0[counter+8]=encoded2.0[counter+8]
    Next counter

    temperature.LowBYTE = encoded1
    temperature.HighBYTE = encoded2
    count_remain = encoded3
    count_per_c = encoded4

    IF temperature.11 = 1 Then goto Zerotemp
    temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = (((temperature /5) *9 ) + 3200)

    lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
    goto loop

    Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
    'temperature = ( ~ temperature ) + 1 ----- do this later, right before displaying it
    '63
    temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    tempF = ((temperature /5) * 9) + 3200

    if tempF <= 0 then goto ZeroF

    temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
    goto loop

    ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
    tempF = ((temperature /5) * 9) + 3200

    temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
    lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
    lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

    goto loop

    end



    Try that....

    I just did an edit... You might have to do the correction/conversion/calculation before you do the 2's complement conversion. I've modified the program for that.
    Last edited by skimask; - 29th December 2006 at 22:01. Reason: Changed program again!

  40. #160
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default Different software

    Found this at Rentron's site:

    '************************************************* *******
    '* Name : Temp.BAS *
    '* Author : Bruce Reynolds *
    '* Notice : Copyright (c) 2003 Reynolds Electronics *
    '* : All Rights Reserved *
    '* Date : 7/28/2003 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* *******
    DEFINE osc 20 ' We're using a 20MHz oscillator
    Comm_Pin VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
    Busy VAR BIT ' Busy Status-Bit
    R_Temp VAR WORD ' RAW Temperature readings
    TempC VAR WORD ' Temp in deg C
    TempF VAR WORD ' Temp in deg F
    Float VAR WORD ' Holds remainder for + temp C display
    Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    Real_Cold CON 1 ' Define Real_Cold = 1
    BAUD CON 16468 ' N9600 for serial LCD
    DISP VAR PortB.0 ' Pin to drive serial LCD
    Deg CON 223 ' Data to display Deg ° symbol
    CLR CON 1 ' CLR LCD command
    LINE1 CON 128 ' LCD line #1
    LINE2 CON 192 ' LCD line #2
    LINE3 CON 148 ' LCD line #3
    LINE4 CON 212 ' LCD line #4
    INS CON 254 ' LCD command mode parameter
    Sign VAR BYTE ' +/- sign for temp display
    Dummy VAR BYTE ' Dummy for Div32

    SEROUT2 DISP,BAUD, [INS,CLR]
    Start_Convert:
    OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion

    Wait_Up:
    OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
    IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
    OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
    OWIN Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
    GOSUB Convert_Temp
    GOTO Start_Convert

    Convert_Temp: ' +32.0 to +257 F
    IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
    Sign = "+"
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    Dummy = 1125 * R_Temp
    TempF = DIV32 100
    IF TempF >6795 THEN ' Over 99.5 deg F..?
    TempF = TempF + 3200
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
    DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
    ELSE
    TempF = TempF + 3200
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
    DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
    ENDIF
    TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
    Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    RETURN

    Yikes: ' Display full range -C to -F conversion
    Sign = "-" ' Display - symbol for negative temp
    Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
    TempF = ~R_Temp / 16 ' Begin conversion from -C to deg +/-F
    IF TempF >=18 THEN ' Check for -degrees F "-18 C = -0.4 F"
    TempF = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign, DEC TempF,Deg,"F "]
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
    DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    ELSE ' Else result = +deg F
    TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
    SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ","+",DEC TempF,Deg,"F "]
    SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
    DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
    SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
    ENDIF
    RETURN

    END



    Might get some good ideas from here on how to do the job efficiently.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44
  4. Replies: 11
    Last Post: - 13th July 2005, 19:26
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 2

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