Help with serin, serout, Manchester encoding


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    if (s.0=1) AND (s.1=1) then 'Check if address matches
    goto L2
    else *****
    write 3, s
    High 2
    Pause 2000
    Low 2
    End
    endif



    Why is there an 'End' in the middle of your code?

  2. #2
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    If the address (first two bits) don't match then I would end the program. I took that out but it seems like it is not advancing towards the correct loop. When my decoded data is stored in the byte s the first bit of my sequence should be coded a s.0 or do I have to define something else before doing s.0?

    Include "Modedefs.bas"
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte
    counter var byte : cnt55 var byte: 'counter is byte and cnt55 is byte
    encoded1 var byte : action var byte : alert var byte : B0=1 : B1=1
    'encoded1 word sized variable that holds encoded byte v, alert variable, action variable, B0 and B1 hardwired address
    s=0: encoded1=0

    main:
    cnt55 = 0 'counter for $55 is zero

    waitfor55:
    serin PORTB.0, n2400, encoded1 'take in data at pin 0 and place in encoded1
    if encoded1 = $55 then
    cnt55 = cnt55 + 1 '$55 read, increase cnt55 by 1
    if cnt55 = 4 then goto waitforaa 'if $55 occurs 4 times in a row check for $aa
    else
    goto main 'if not $55, reset counter at main and restart
    endif
    goto waitfor55

    waitforaa:
    serin PORTB.0, n2400, encoded1
    if encoded1 <> $aa then goto main 'restart, incorrect leader bit

    serin PORTB.0, n2400, encoded1 : 'serout PORTB.4, n2400, [encoded1] take in from pin 0 to encoded 1 output to pin 3 contens in encoded1
    write 0,encoded1
    High 7
    Pause 2000
    Low 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encoded1.0[counter*2]:Next counter
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message
    write 1, s
    High 6
    Pause 2000
    Low 6


    if (s.bit0=0) AND (s.bit1=1) then 'Check if address matches
    goto L3
    else
    write 2,s
    High 2
    Pause 2000
    Low 2
    endif


    L3:
    if (s.bit2=0) And (s.bit3=0) then 'if the address Tracking then
    s.bit2=1: action = s 'set the third bit to 1 and send it back
    alert = 0: 'serout PORTB.1, n2400, [action] 'output to pin 1 value in s
    write 3, action
    High 1
    Pause 2000
    Low 1
    endif

    if (s.bit2=0) AND (s.bit3=1) then 'If the address Tracking and Finding then
    s.bit2=1: action=s 'set the third bit to 1 and send back
    alert=1: 'serout PORTB.4, n2400, [action]: 'output to pin 1 value in s
    write 4, action
    High 4
    Pause 2000
    Low 4
    endif

    End
    Last edited by oneohthree; - 4th April 2007 at 22:16.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Are you sure that you are receiving at the RX the same thing you are sending at the TX?


    'Decoding
    For counter = 0 to 3 : s.0[counter] = encoded1.0[counter * 2 + 1] : Next counter

    Try that and see what happens...for grins...

  4. #4
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I think I figured it out I was reading the bits the wrong way. For example, when I send 2345 I originally assumed that s.0=2, s.1=3, s.2=4 and s.3=5 but it was in fact the other way. My code now works 90% of the time, occasionally my program will jump to if statements that it is not supposed to go to and write data there.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    I think I figured it out I was reading the bits the wrong way. For example, when I send 2345 I originally assumed that s.0=2, s.1=3, s.2=4 and s.3=5 but it was in fact the other way. My code now works 90% of the time, occasionally my program will jump to if statements that it is not supposed to go to and write data there.
    If you're using the RF link, try the straight serial connection first. You can keep the encoding in there.
    If it still doesn't work, check your oscillators. If you're using the internal oscillators, probably should go to a crystal.

  6. #6
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I'm using a 4 MHz crystal oscillator. I'm sure that the stuff is encoding and decoding correctly since it is written correctly in my EEPROM and my logic works most of the time. It seems like my program is executing straight down and is going through incorrect if loops sometimes. For example, when I enter 0101 but somehow my microcontroller will write in memory location 3 and 4. It is only supposed to write in memory location 4. Is there anyway to clear the memory before I start my program? Also, is there anyway that I can prevent it from executing through other if loops? I have attached my new code below.

    Receiver code:
    Include "Modedefs.bas"
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte
    counter var byte : cnt55 var byte: 'counter is byte and cnt55 is byte
    encoded1 var byte : action var byte : alert var byte : action2 var byte: B0=1 : B1=1
    'encoded1 word sized variable that holds encoded byte v, alert variable, action variable, B0 and B1 hardwired address
    s=0: encoded1=0

    main:

    maina:
    cnt55 = 0 'counter for $55 is zero

    waitfor55:
    serin PORTB.0, n2400, encoded1 'take in data at pin 0 and place in encoded1
    if encoded1 = $55 then
    cnt55 = cnt55 + 1 '$55 read, increase cnt55 by 1
    if cnt55 = 4 then goto waitforaa 'if $55 occurs 4 times in a row check for $aa
    else
    goto maina 'if not $55, reset counter at main and restart
    endif
    goto waitfor55

    waitforaa:
    serin PORTB.0, n2400, encoded1
    if encoded1 <> $aa then goto maina 'restart, incorrect leader bit

    serin PORTB.0, n2400, encoded1 : 'serout PORTB.4, n2400, [encoded1] take in from pin 0 to encoded 1 output to pin 3 contens in encoded1
    write 0,encoded1
    High 7
    Pause 2000
    Low 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encoded1.0[counter*2]:Next counter
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message
    write 1, s
    High 6
    Pause 2000
    Low 6


    if ((s.3==0) && (s.2==1)) then 'Check if address matches
    goto L3
    else
    write 2,s
    High 2
    Pause 2000
    Low 2
    End
    endif


    L3:
    if ((s.1==0) && (s.0==0)) then 'if the address Tracking then
    action = s: action.1=1'set the third bit to 1 and send it back
    alert = 0: 'serout PORTB.1, n2400, [action1] 'output to pin 1 value
    write 3, action
    High 1
    Pause 2000
    Low 1
    endif

    if ((s.1==0) && (s.0==1)) then 'If the address Tracking and Finding then
    action2 = s:action2.1=1 'set the third bit to 1 and send back
    alert=1: 'serout PORTB.4, n2400, [action2]: 'output to pin 1 value i
    write 4, action2
    High 4
    Pause 2000
    Low 4
    endif

    End

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    It seems like my program is executing straight down and is going through incorrect if loops sometimes.
    Well, yes, it is going to execute straight down (as it's laid out here in the forums). Read thru it. How is it supposed to NOT execute straight down? There's no jumps back to the main loop or anything anywhere (except for where the serial data is received).

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. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  4. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  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