Microcontroller with 2 way paging application problem


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Can you give me an example of how to use checksum or a data identifier in my program? Also, is it a problem if I have to send it multiple times for the PIC to pick it up by wire?
    Last edited by oneohthree; - 18th April 2007 at 23:19.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    Can you give me an example of how to use checksum or a data identifier in my program? Also, is it a problem if I have to send it multiple times for the PIC to pick it up by wire?
    Transmit the data, and also transmit it's complement (ie. transmit a $00, also send an $fe, transmit a $01, also send an $fd). Add them both up, they come out to $FF.
    At the receiver, get 2 bytes, add them up, if they don't come up to $FF, the packet isn't any good, reject it, maybe even send a seperate reject code back to the TX.
    Hundred ways to do this...

  3. #3
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    I find that sometimes when I connect by wire it doesn't work. Sometimes my wireless connection works if I first connect the wire remove it and then I reconnect my wireless connection it works again. I'm not sure if the serout is not working correctly or the serin is not working correctly.

    Receiver (434)
    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : encode var byte: encode2 var byte 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: counter2 var byte'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    'counter2 counts the number of times acknowledge light blinks.
    encode1 var byte : action var byte : alert var byte : action2 var byte: B0=0 : B1=1: counter3 var byte
    'encode1 byte sized variable that holds encoded byte s, alert variable, action variable used for trakcing mode, action2 used for track and find mode, B0 and B1 are the hardwired address
    c var byte: d var byte: e var byte: s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0
    'c (track mode), d (track and find) and e(address) are bytes; initialize all values to zero
    'encode holds the encoded variable after ack made in track mode, encode2 holds the encoded variable after ack made in track and find mode.

    Main:

    Clr:
    s=0: encode1=0: c=0: d=0: e=0: action =0: action2=0: encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa '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 wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    'High 2 'High on Port B Pin 2
    'Pause 2000 'Pause
    'Low 2 'Low on Port B Pin 2


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    'High 6 'High on Port B Pin 6
    'Pause 2000 'Pause
    'Low 6 'Low on Port B Pin 6


    e = s 'Copy s to byte e
    If ((e.3=B0) and (e.2=B1)) Then 'Check if address matches (first two bits)
    goto L3 'if it matches go to L3
    Else
    write 2,s 'Write to EEPROM Location 2
    High 3 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 3 'Low on Port B Pin 2
    goto Clr
    Endif

    L3:
    'Tracking mode (mode is based on last two bits)
    c=s: d=s: 'Copy s to byte c and s to byte d
    If ((c.1=0) and (c.0=0)) Then
    action=s: 'Copy s to action byte
    action.1=1'set the third bit of action1 to 1 and send it back
    'alert = 0: 'set alert to 0
    write 3, action 'Write to EEPROM Location 3
    High 6 'High on Port B in 1
    Pause 2000 'Pause
    Low 6 'Low on Port B in 1
    'Manchester Encoding
    For counter = 0 to 3
    If action.0[counter]=0 Then
    encode.0[counter*2]=0 : encode.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode.0[counter*2]=1 : encode.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    write 8, encode 'Write encode to EEPROM Location 8
    Low 4 'Low on Port B Pin 4
    For counter = 0 to 5 'Blink LED 5 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter 'Back to beginning of loop
    For counter3 = 0 to 50 'Send three times
    serout PORTB.2, n2400, [ $55, $55, $55, $55, $55, $55, $55, $55, $55, $aa , encode ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    'Tracking and Finding mode (is based on last two bits)
    If ((d.1=0) and (d.0=1)) Then
    action2=s 'Copy s to action2 byte
    action2.1=1 'set the third bit of action2 to 1 and send back
    'alert=1
    write 4, action2 'Write to EEPROM Location 4
    High 5 'High on Port B Pin 4
    Pause 2000 'Pause
    Low 5 'Low on Port B Pin 4
    'Manchester Encoding
    For counter = 0 to 3
    If action2.0[counter]=0 Then
    encode2.0[counter*2]=0 : encode2.0[counter*2+1]=1 'If it is a zero make the first bit 0 and second bit 1
    Else
    encode2.0[counter*2]=1 : encode2.0[counter*2+1]=0 'If not then make first bit 1 and second bit 0
    EndIf
    Next counter :
    'serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $aa , encode2 ] 'send out preamble and code to Port B Pin 2
    write 9, encode2 'Write encode2 to EEPROM Location 9
    Low 4 'Low on Port B Pin 4
    For counter2 = 0 to 5 'Blink LED 50 times
    Pause 400 'Pause
    High 4 'High on Port B Pin 4
    Pause 400 'Pause
    Low 4 'Low on Port B Pin 4
    Next counter2 'Back to beginning of loop
    Low 1 'Low on Port B Pin 4
    For counter = 0 to 10 'Blink LED 50 times
    Pause 400 'Pause
    High 1 'High on Port B Pin 1
    Pause 400 'Pause
    Low 1 'Low on Port B Pin 1
    Next counter: 'Back to beginning of loop
    For counter3 = 0 to 50 'Send data times
    serout PORTB.2, n2400, [ $55 , $55 ,$55, $55, $55, $55, $55, $55, $55, $aa , encode2 ] 'send out preamble and encode on PORTB pin 2
    Next counter3 'Next number
    goto Clr
    Endif

    End




    Receiver (315)

    'IEEE encoding
    Include "Modedefs.bas"
    'trisb = 0
    s var byte : B0 var bit : B1 var bit : 's is byte to be encoded, B0 and B1 is byte for the hardwired address (first two bits)
    counter var byte : ct55 var byte: 'counter is the amt of bit which is 4 in the input is byte and ct55 is to count the $55 byte
    encode1 var byte : B0=0 : B1=1
    'encode1 byte sized variable that holds encoded byte s, B0 and B1 are the hardwired address
    e var byte: s=0: encode1=0:e=0
    ' e are bytes; initialize s, encode1, and e values to zero
    'encode1 holds the encoded variable received.

    Main:

    Clr:
    s=0: encode1=0: e=0: 'encode2=0 'initialize variables to zero

    Maina:
    ct55 = 0 'counter for $55 is zero

    Wait55:
    serin PORTB.0, n2400, encode1 'take in data at pin 0 and place in encoded1
    If encode1 = $55 Then
    ct55 = ct55 + 1 '$55 read, increase ct55 by 1
    If ct55 = 4 Then goto Waitaa '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 wait55

    Waitaa:
    serin PORTB.0, n2400, encode1 'wait for $aa
    If encode1 <> $aa Then goto Maina 'restart, incorrect leader bit
    serin PORTB.0, n2400, encode1 : 'serout PORTB.4, n2400, [encode1] take in from Port B Pin 0 to encoded1 output to Port B Pin 3 contents in encode1
    write 0,encode1 'write to EEPROM Location 0
    High 7 'High on Port B Pin 7
    Pause 2000 'Pause
    Low 7 'Low on Port B Pin 7


    'Decoding
    For counter=0 to 3:s.0[counter]=encode1.0[counter*2]:Next counter 'Go through counter place bit 0, 2, 4, 6 in s
    'serout PORTB.3, n2400, [s] 'Ouptut decoded message s to Port B Pin 3
    write 1, s 'write to EEPROM Location 1
    High 6 'High on Port B Pin 6
    Pause 2000 'Pause
    Low 6 'Low on Port B Pin 6

    e=s
    If ((e.1==1)) Then 'Acknowledgment received because third bit is 1
    goto L4 'Jump to L4
    Else
    write 2,s 'Write to EEPROM Location 2
    High 2 'High on Port B Pin 2
    Pause 2000 'Pause
    Low 2 'Low on Port B Pin 2
    goto Clr
    Endif

    L4:

    write 3, e 'Write to EEPROM Location 3
    High 1 'High on Port B in 1
    Pause 2000 'Pause
    Low 1 'Low on Port B in 1
    serout PORTB.3, n2400, [e.3] 'send out first bit from PORTB Pin 3
    serout PORTB.4, n2400, [e.2] 'send out second bit from PORTB Pin 4
    goto Clr


    End
    Last edited by oneohthree; - 19th April 2007 at 04:53.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by oneohthree View Post
    I find that sometimes when I connect by wire it doesn't work. Sometimes my wireless connection works if I first connect the wire remove it and then I reconnect my wireless connection it works again. I'm not sure if the serout is not working correctly or the serin is not working correctly.
    Sounds like a goofy ground wire/connection somewhere, induced capacitance, missing pullup or pulldown, etc., maybe a sloppy PCB.
    Are you working on a solderless breadboard?

  5. #5
    Join Date
    Mar 2007
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Yes, I am using a breadboard. Do you think it is possible that maybe that area of the breadboard is messed up?
    Could it be a training problem for the transmitter/receiver also?
    Last edited by oneohthree; - 19th April 2007 at 05:17.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Corrosion perhaps

    Quote Originally Posted by oneohthree View Post
    Yes, I am using a breadboard. Do you think it is possible that maybe that area of the breadboard is messed up?
    Could it be a training problem for the transmitter/receiver also?
    Hello oneohthree,
    I just trashed 4 breadboards due to corrosion. The contacts also wear out too. I really got tired of fighting to get even simple things to work, Oscillator sometimes wouldn't run, poor connections, bad things happen when components like PIC lose grounds too, anyway its worthwhile to check.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,945


    Did you find this post helpful? Yes | No

    Default

    And you STILL DID NOT put those semicolons....

    Also I would choose a different setup for the serin command. Maybe with a time out and a wait character.This would require the Serin2 though...

    Ioannis


    P.S. Also why don't you try simple things first, like send one character then two and see what happens. After that try the manchester encoding and if succesful try the CRC or checksum. Take it step by step. You program is too long to follow and debug. About this routines (manchester and CRC) there are link on this forum. Do a search and find. One is Melanies and one is mine.
    Last edited by Ioannis; - 19th April 2007 at 09:37.

Similar Threads

  1. PIC KIT 2 writing problem ?
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2010, 12:59
  2. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 11:55
  3. Replies: 7
    Last Post: - 15th December 2008, 05:18
  4. PWM Problem
    By cihhan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th June 2008, 18:43
  5. Replies: 18
    Last Post: - 24th January 2008, 22:44

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