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

    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

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

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

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

  5. #5
    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 17:16.

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

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

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