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

    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

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

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

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

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

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

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

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

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