Serin serout problem


Closed Thread
Results 1 to 40 of 337

Hybrid View

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

  2. #2
    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?

  3. #3
    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....!

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

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

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

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

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

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

  10. #10
    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).

  11. #11
    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!

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 : 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