Need help multiplexing EUSART output


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    RAM arrays.

    I'm using Timer0 and Timer1 at the moment, but i could prob use any for my application.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Tmr_tx-18

    Kamikaze,

    I think this will do what you wanted, without any external OR/AND gates.
    There's so much more I could do with it.
    But it's already more than you need, so I think I'll stop now.

    This is an Include module, that sends Serial data using a Timer as the baud rate generator.
    Currently, it will only work on 18F's, and it's only the Transmit side.

    It can use any one of Timer 0, 1 or 3. But does not use interrupts.
    Outputs on any digital I/O Pin.
    Can send Bytes, Words, Strings from arrays, Strings from Flash and ASCII decimal values.
    Runs up to 115200 with 32mhz(or higher) OSC.
    You can use HSEROUT for the USART, and this as a second UART.


    Setup is pretty simple.
    Just tell it which Timer to use, the baud rate and the I/O Pin...
    Code:
    ;----[Setup Timer based UART]-------------------------------------------------
    DEFINE  TX_TIMER 1                 ; Timer used for serial UART (0,1 or 3)
    DEFINE  TX_BAUD  9600              ; Baud Rate
    TX_Pin  VAR PORTB.6                ; Output Pin
    INCLUDE "TMR_TX-18.bas"            ; Include the Timed Serial module
    The TX_Pin is automatically set to output and idles high. (assuming there's no A/D etc. enabled on the pin)
    Serial signal is 8N1 True. Same as the USART.

    If all you are sending is Strings from Array's, then you just need 1 Command...
    Code:
    @  TX_STR?B  _StrArray, _Length
    Which is functionally the same as,
    HSEROUT [STR StrArray\Length]
    where Length is a BYTE variable.

    A variation of the same thing uses a Constant Length (max 255)
    Code:
    @  TX_STR?C  _StrArray, 16
    Using just array's, the module will use about 250 bytes of program space.
    Using the additional commands may add up to another 200 byes plus string data.
    Relatively small, compared to HSEROUT.<hr>Additional commands that are available are...
    Code:
    @  TX?C       Const              ;- send a Char (constant 0-255)
    @  TX?B       _Value             ;- Send a byte from a BYTE var
    @  TX?W       _Value             ;- Send a binary Word var (LSB first)
    @  TX_DEC?B   _Value             ;- Ascii Decimal Byte, no leading 0's
    @  TX_DEC?W   _Value             ;- Ascii Decimal Word, no leading 0's
    @  TX_DEC?CB  Len, _Value        ;- Ascii Decimal BYTE, Len is a constant
    @  TX_DEC?CW  Len, _Value        ;- Ascii Decimal WORD, Len is a constant
    @  TX_STR?C   Str, Len           ;- Send an Array, Len is a constant
    @  TX_STR?B   Str, _Len          ;- Send an Array, Len is BYTE var
    @  LoadStr    _Array, Str, _Len  ;- Load an Array from flash, Returns
                                     ;  the length of the string in BYTE var
    @  TX_FSTR   Fstr                ;- Send Fixed String from Flash
    @  TX_DSTR   Dstr                ;- Send PreDefined String from Flash
    Examples...
    Code:
    @  TX?C  "A"                    ; same as HSEROUT ["A"]
    
    @  TX?B  _ByteVar               ; same as HSEROUT [ByteVar]
    
    @  TX?W _WordVar                ; HSEROUT [WordVar.LowByte, WordVar.HighByte]
    
    @  TX_DEC?B   _ByteVar          ; HSEROUT [DEC ByteVar]
    
    @  TX_DEC?W   _WordVar          ; HSEROUT [DEC WordVar]
    
    @  TX_DEC?CB  3, _ByteVar       ; HSEROUT [DEC3 ByteVar]
    
    @  TX_DEC?CW  4, _WordVar       ; HSEROUT [DEC4 WordVar]
    
    @  TX_STR?C   _StrArray, 13     ; HSEROUT [STR StrArray\13]
    
    @  TX_STR?B   _StrArray, _ByteVar  ; HSEROUT [STR StrArray\ByteVar]
    
    @  TX_FSTR   "Hello World\r\n"  ; HSEROUT ["Hello World",13,10]
    
    @  TX_DSTR   Wassup             ; no equivilent
    @Wassup  string "Hey dude, wasssssup!\r\n"
    
    @  LoadStr    _StrArray, "Put me in Array\r\n", _ByteVar  
                                    ; returns length of string in ByteVar  
                                    ; To send the array use ...
    @  TX_STR?B   _StrArray, _ByteVar
    It's probably a bit confusing, so let me know if it doesn't make sense.
    <br>
    Attached Files Attached Files
    DT

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    All I can say is wow!

    Thats some nice work there Darrel.

    Thanks very much.

    I'll give it a go and report back
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    Yet another nice use & clever of text substitution, macro, include and PBP LIBs.

    Is there any baudrate limitation test report for different OSC speed?
    Steve

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

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve,

    I think you picked up on all my little tricks in this one.

    Is there any baudrate limitation test report for different OSC speed?
    No, not really.
    I've run it at 115200 with 32mhz
    19200 with 4mhz.

    I was a bit worried about what people might try, so I put in ERROR's if you try to use a baudrate that isn't suitable for your OSC freq.
    But those are really for "IDEAL" conditions.

    The timing will still be affected by the interrupts. The difference is that only the rise and fall times will vary. The overall bit timing will stay consistant (as long as the INT handlers aren't too long). So Lower baud rates will still be "more stable".
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Yup, i've just looked deeper in your code and i'm really confident. Used with simple care, this should solve many extra hardware thingy.

    Pretty slick!
    Steve

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

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Code:
    clrwdt        ; kick the dog
    Never heard it put that way before. Clever tho
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

Similar Threads

  1. Help changing CCP3 output pin
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th July 2008, 02:30
  2. Bit Banging input to output on PIC16F876A
    By Bronurstomp in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th June 2008, 19:50
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  5. HSEROUT Newbie question/problem
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th July 2006, 14: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