Serial data sending#do someone came across programming 16f676 with TRH031M?


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi Henrik,

    Let's say Im now sending a serial data "Hanson" and i set my start frame as "AAAAA" and end frame as "EEEEE". So the serial data Im sending is like:
    "AAAAAHANSONEEEEE"

    at sending side:

    start:
    SEROUT dataout,N300,["AAAAA","HANSON", "EEEEE"]
    pause 100
    goto start

    My problem is at the receiving side, I wish to filter my received data before storing them. The only solution I have thought was "nested IF loop" but microcode studio don't support this kinda command rather just "IF...THEN". Right?
    so, how can I write my coding to perform this data filtering task?
    eg:
    check if data_in[0]="A" ;if yes then proceed checking for second "A"
    check if data_in[1]="A" ;if yes then proceed checking for third "A"
    check if data_in[2]="A" ;if yes then proceed checking for forth and fifth "A"
    check if data_in[13]="E" ;if yes then check for second "E"
    .
    .
    .
    check if data_in[16]="E" ;if all conditions matched (receive first 5 "A" and last 5 "E" properly) then store data_in
    else loop back subroutine and repeat checking for first "A"

    Regards

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi,
    Not sure what you mean by The only solution I have thought was "nested IF loop" but microcode studio don't support this kinda command rather just "IF...THEN".
    First of all MicroCodeStudio is just the editor, the support or lack there of for any commands etc is down to the compiler - which is PBP. And yes, PBP supports nested IF/THEN
    Code:
    If myData[0] = "A" THEN
      If myData[1] = "B" THEN
        If myData[2] = "C" THEN
        ' Do whatever
        ENDIF
      ENDIF
    ENDIF
    And yes PBP supports IF/THEN in loops...
    Code:
    i VAR BYTE
    DataIn VAR BYTE[16]
    ActualData VAR BYTE [6]
    
    ' DataIn is 16 bytes containg A A A A A H A N S O N E E E E E
    
    ' Verify that the first 5 bytes are all "A"
    For i = 0 to 4
      If DataIn[i] <> "A" THEN GOTO Start   ' Nope, not qualified, start over...
    NEXT
    
    ' Verify that the last 5 bytes are all "E"
    For i = 11 to 15
      If DataIn[i] <> "E" THEN GOTO Start   ' Nope, not qualified, start over...
    NEXT
    
    ' Yes, header and footer qualified. Now extract actual data, 6 bytes, store in array ActualData
    For i = 5 to 10
      ActualData[i-5] = DataIn[i]
    NEXT
    You could/should also look into the WAIT or possibly WAITSTR modifiers of the SERIN command. Or, once you've got all the data in the array, you might want to look at the ARRAYREAD command to parse the data. Lots of options available.

    /Henrik.

  3. #3
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi Henrik,


    • i VAR BYTEDataIn VAR BYTE[16]ActualData VAR BYTE [6]' DataIn is 16 bytes containg A A A A A H A N S O N E E E E E' Verify that the first 5 bytes are all "A"For i = 0 to 4 If DataIn[i] <> "A" THEN GOTO Start ' Nope, not qualified, start over...NEXT' Verify that the last 5 bytes are all "E"For i = 11 to 15 If DataIn[i] <> "E" THEN GOTO Start ' Nope, not qualified, start over...NEXT' Yes, header and footer qualified. Now extract actual data, 6 bytes, store in array ActualDataFor i = 5 to 10 ActualData[i-5] = DataIn[i]NEXT


    If first 5 bytes received are correct then GOTO start. In this case if first 5 bytes received correctly and last 5 bytes are wrong? It runs "start" subroutine without checking the last 5 bytes?

    Regards

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi,
    If first 5 bytes received are correct then GOTO start.
    No.... It checks the first 5 bytes, if any of them is NOT "A" it jumps to start.

    In this case if first 5 bytes received correctly and last 5 bytes are wrong? It runs "start" subroutine without checking the last 5 bytes?
    No.... If it finds that the first 5 bytes are received correct it continues to check the last 5 bytes. If they TOO are correct it extracts the data. If any of the last the 5 bytes are wrong it'll jump back to start without extracting the data.

    Only when the first bytes are "A" AND the last 5 bytes are "E" will it extract the data. As soon as ANY of the first 5 bytes OR the last 5 bytes does NOT match will it jump back to start - which is whay you said it should do:
    if all conditions matched (receive first 5 "A" and last 5 "E" properly) then store data_in
    /Henrik.

Similar Threads

  1. Problem on sending data on serial port
    By bwaxing in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd May 2011, 21:05
  2. Ir problem sending data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th December 2009, 05:27
  3. 16F676 programming problem
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th May 2009, 17:39
  4. VB sending serial data to PIC
    By Tissy in forum Serial
    Replies: 7
    Last Post: - 8th March 2006, 18:31
  5. Sending data over USB via VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 12th September 2005, 01:00

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts