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

  2. #2
    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 21:25.

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

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

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

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

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

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

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

Similar Threads

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