16f88 ausart & defines


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1

    Default 16f88 ausart & defines

    My application requires use of the hardware usart ports for background serial comms.

    Problem is I need 9600,8,N,1 for Tx and 9600,8,E,1 for Rx

    So need 9 bit mode for RX and 8 bit mode for TX.

    I was going to use Hserout but note the defines affect both Hserin & Hserout

    Any ideas?

    Can I poke the RCSTA & TXSTA registers just before I use Hserin or Hserout to change
    from 8bit to 9 bit mode etc without corrupting anything Hserin/Hserout wants to do?

    I can't use Serin2 as i have some interupts going on which interfere with the Serin2 operation.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16f88 ausart & defines

    You do not need to set the DEFINES at the beginning of your code. You can set the registers as you go. I would setup a couple of sub routines for this.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 16f88 ausart & defines

    The code I use at present for the 9600,8,E,1 reception is

    Code:
    DEFINE HSER_BAUD 9600		'Set Baud rate to 9600bps
    DEFINE HSER_BITS 9		'Set to 9 bit mode
    DEFINE HSER_EVEN 1		'Set Even Parity
    DEFINE HSER_CLROERR 1 		'Clear overflow error automatically
    
    HSERIN [WAIT($87), STR BCMDATA\11]	'Wait for packet start $87 then Rxd 11 bytes into BCMDATA
    The code i use for the 9600,8,N,1 Transmission is

    Code:
    DEFINE HSER_BAUD 9600		'Set Baud rate to 9600bps
    
    HSEROUT [254,192,"Cruise ",#Cruise," Duty ",#DutyCycle]	'Display
    Both the above work fine in seperate programs, my program now needs to combine them into one and swap between one and the other
    during execution.

    So receive some data with parity, process it, then spit it out without parity and repeat.

    Could you help with an example? Your subroutine? Or what registers to change?
    I need to use hserin/out if i can as i can understand it and i'm working with arrays for the rxd data!!
    Last edited by retepsnikrep; - 13th March 2011 at 10:11.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16f88 ausart & defines

    If you have not been using mr. E's PicMulticalc grab it over here.
    http://www.picbasic.co.uk/forum/cont....-PICMultiCalc

    Quick example of not using DEFINES.
    MultiCalc gives this for 9600 Baud at 20Mhz:
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 129 ' 9600 Baud @ 20MHz, 0.16%
    So the code would be something like this:
    Code:
    Send_Data: 'Sending Sub
    RCSTA.4 = 0 : RCSTA.4 = 1
    RCSTA=$90:TXSTA=$24:SPBRG=129:HSEROUT[254,192,"Cruise ",#Cruise," Duty ",#DutyCycle]
    RETURN
    Because DEFINES are not used you can change things around at will. Just do the changing in Sub-routines then GOSUB when ever needed.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: 16f88 ausart & defines

    Hi,
    I'm currently working on something similar and have been thinking about this for a while. I'm afraid (though I DO wish I'm wrong) that it's not as easy as just setting the registers manually.

    Yes, you can control the way the (E)USART operates and enable it to send and/or receive 9 bits but the problem is that the DEFINE HSER_EVEN 1 and HSER_BITS 9 not only controls those registers, it also controls the way PBP generates the code.

    When using parity PBP has to calculate the parity bit for each byte it sends and "load" that bit into the TX9 location of the TXSTA register. (And similar for the RX-part of course). If you don't DEFINE HSER_EVEN PBP doesn't calculate the parity bit so simply enabling 9 bit transmision and/or reception by setting up RXSTA and TXSTA properly isn't enough I'm afraid.

    My personal project involves allowing the enduser to select between using parity or not which means it has to be done at runtime - not at buildtime.

    Looking forward to a disussion and hopefully a solution!

    /Henrik.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16f88 ausart & defines

    You might be correct, to be honest I do not use 9 bit that often so that may be the problem. I do use the register thing other wise. I had e a project a few years ago where the Baud needed to be changed on the fly.

    I am looking at PBPPI18L.LIB. I think the 9 bit stuff is done in hardware. Looks to me changing the RCSTA or TXSTA values is all that is needed???
    ifndef HSER_BITS
    HSER_BITS = 8 ; Default to 8 bits
    endif
    ifndef HSER_RCSTA ; Receive register data
    if (HSER_BITS != 9)
    HSER_RCSTA EQU 90h ; Receiver enabled
    else
    HSER_RCSTA EQU 0d0h ; Receiver enabled for 9 bits
    endif
    endif
    ifndef HSER_TXSTA ; Transmit register data
    if (HSER_BITS != 9)
    HSER_TXSTA EQU 20h ; Transmitter enabled
    else
    HSER_TXSTA EQU 60h ; Transmitter enabled for 9 bits
    endif
    endif
    I guess someone will have to give it a try...
    Dave
    Always wear safety glasses while programming.

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