Help with stopping a loop with a serial receive on 16F876.


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Hserout [DEC5 period,DEC5 period2,"T",13,10]
    'IF PORTA.5 = 0 THEN return ' If PORTA, pin 5 is low (0), return to menu

    HSERIN 100, skip,[MI]

    “This where I would like to check for USART receive”

    If MI = "Z" then return
    Skip:


    period2 = 0
    GoTo sloop

    If you want to get out of the subroutine when you receive a byte (I used "Z" but you can use any byte) the above three lines of code will solve the problem. I have used a timeout of 100 millisecs but you can short it if too long for your need.

    Merry Christmas to you too.

    Al.
    All progress began with an idea

  2. #2
    Join Date
    Dec 2010
    Location
    Colchester England
    Posts
    20


    Did you find this post helpful? Yes | No

    Wink

    Thanks to both of you.

    I will be trying both methods as soon as I can and report back.

    Thanks for your quick response's

  3. #3
    Join Date
    Dec 2010
    Location
    Colchester England
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Sorted

    Hi

    As a follow up I have used a combination of both suggestions.

    I have to say that watching PIR1.5 (RCIF suggested by cncmachineguy)for a change is my preferred method of checking for a character received in the USART buffer. This seems to cause me less problems with my CCPx capture i.e. less time delay. Unfortunately the down side is that it is read only and I have not found a way (yet!) to reset/clear the USART buffer by using the registers. So I have utilised the HSERIN, with a small timeout, command as aratti suggested. Using this then clears the USART buffer and appears to work fine.

    Code:
    if PIR1.5 = 1 then 
    Hserin 1,jump,[MI]           ' 1mS timeout then read the character and clear buffer
    jump:                        ' Character is any because it is only used as an interupt
    gosub gratio
    endif
    Thanks again much appreciated......

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ceetee View Post
    Unfortunately the down side is that it is read only and I have not found a way (yet!) to reset/clear the USART buffer by using the registers.

    From datasheet:
    Flag bit RCIF is a read-only bit which is
    cleared by the hardware. It is cleared when the RCREG
    register has been read and is empty
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Dec 2010
    Location
    Colchester England
    Posts
    20


    Did you find this post helpful? Yes | No

    Smile

    Hi cncmachineguy

    OOOps !. I have been reading that section of the datasheet over and over again but it didn't click until you highlighted it so I have removed the:-
    Code:
    if PIR1.5 = 1 then 
    Hserin 1,jump,[MI]                                      ' Read a character and clear buffer
    jump:                  
    gosub gratio
    endif
    and replaced by using a "dummi" variable to read RCREG as follows
    Code:
    if PIR1.5 = 1 then 
    dummi = RCREG                              ' Read a character and clear buffer
    gosub gratio
    endif
    That seems to work ok.

    Thanks again

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Very likely this is what you need! But I thought you should have control on the direction of your program flow. In this way any byte received will direct you to the gosub indicated and this could also happen out of your control. I personally would have identified the byte received and if the byte was the correct jump_byte then the program could proceed with the jump, any other bytes would be ignored.

    But as I just said above, if this is what you need and you are happy with it, why changing it.

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Al, I like your way. But I guess it really depends on what you want to do with the byte. In my upcoming app, I will need something simular to what you have suggested. Just one more reason to LOVE this place. Multiple ways to solve a problem, some better then others depending on the app.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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