Need help multiplexing EUSART output


Results 1 to 35 of 35

Threaded View

  1. #27
    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

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