hserout PIC pic 16F876


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1

    Question hserout PIC pic 16F876

    Hello !

    I would like to know if , using the define and the HESROUT instruction, it is possible to change the baud right *during* the execution of the program.

    I would like to make possible the user [ me , "8-) ] to select 9600 and 19200.

    Everything is ok in both speed, but i can't switch from one to another ...

    It seems that new define are not allowed during execution ...

    And writing to regsiter seems to confuse HSEROUT ...

    If someone has an idea or a piece of could, i would be glad to read it / him

    Thank a lot for helping !
    Apologize for poor english , i was a bad boy at school ...
    Vincent

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Apologize for poor english , i was a bad boy at school ...
    Vincent
    don't be afraid of that...

    Everything is ok in both speed, but i can't switch from one to another ...

    It seems that new define are not allowed during execution ...

    And writing to regsiter seems to confuse HSEROUT ...
    can you something for me. I'm not sure it's gonna work but... worth a try

    Let's assume you have a 20MHZ crystal.

    Refer to the table 10-4:
    SPBRG=129 '@9600 bauds
    SPBRG=64 '@19200 bauds


    IMO we can change the baud rate only by changing the value of the SPBRG register.

    so give a try to this snipet

    Code:
    DEFINE OSC 20
    
    start:
         TXSTA=$24
         RCSTA=$90
         SPBRG=129  '@9600 bauds
         pause 100 'try to remove this pause after
         HSEROUT ["comm @9600 bauds"]
         TXSTA=$24
         RCSTA=$90
         SPBRG=64  '@19200 bauds
         PAUSE 5000 'wait 5 seconds
         HSEROUT ["comm @19200 bauds"]
         goto start
    let me know... i'm curious.

    If it's working, try to define TXSTA and RCSTA only one time at the begining to see if it's also work.

    Code:
    DEFINE OSC 20
         TXSTA=$24
         RCSTA=$90
    
    start:
         SPBRG=129  '@9600 bauds
         pause 100 'try to remove this pause after
         HSEROUT ["comm @9600 bauds"]
         SPBRG=64  '@19200 bauds
         PAUSE 5000 'wait 5 seconds
         HSEROUT ["comm @19200 bauds"]
         goto start
    Last edited by mister_e; - 2nd February 2005 at 18:09.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    There should be no problem to switch between theese two baudrates "on the fly". All you need to do is put correct values in the SPBRG register(and perhaps bit BRGH in TXSTA). There is a table specifying SPBRG values at diffrent oscillatorspeeds. I can't help you further without knowing what crystal you're using.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hello,

    thanks for helping,

    my XT is a 4MHz , i will adapt value, and try what you suggest , i will let you know the results.

    Thanks
    Vincent

  5. #5


    Did you find this post helpful? Yes | No

    Thumbs up

    Hello,

    steve you are the king, your code works both 1 and 2 !

    To share my experiment :

    I did not use anymore the define, but i write to TXSTA and
    RCSTA , i only use the autoerror clearing define, and it is ok.


    The pause 100 after the change of SPBRG , is mandatory, probably the baud clock needs to get stable , without this pause the first char are lost ( maybe , 3 or 4 character at full speed simple serout like :

    hserout["ABCDEFG"]

    with 100ms pause, you are secure, and it is only at "initialization" not after.

    Many thanks for your help, switching the baudrates has been a big moment for me !

    Vincent STEINMETZ
    (France , other side of sea ... )

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Salut Vincent!

    Great to know it's working fine now. I don't know how the *initialisation* must be, but if you can try with some other low value like

    PAUSE 10
    PAUSE 1
    PAUSEUS 100
    PAUSEUS 10
    PAUSEUS 5
    @ NOP ' 1usec delay @4MHZ

    will be interesting to have the results...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7


    Did you find this post helpful? Yes | No

    Default ini

    Hello steve,

    I have done the tests

    the minimal pause seems to be pause 10 , under this value , the three first character are lost, every time , it is not erratic but highly repeteable ...

    =>I have 20Mhz pic working at 4mHz

    Let me know if you need something else.

    Vincent

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    That's perfect. Was for learning purpose. Great to know that.

    thanks.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. I2C Slave with a PIC
    By ralfmayr in forum mel PIC BASIC Pro
    Replies: 129
    Last Post: - 21st August 2016, 17:44
  2. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  3. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  4. Is HSEROUT corrupting bit 7 ?????
    By Robert Wells in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd October 2008, 16:26
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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