Embedded Strings in your Code Space


Results 1 to 40 of 50

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Here's my own version. Not as brilliant as all the above but allow to send String and numeric value. Have fun!
    [html]
    ' ///////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    ' Embedded String and Data handling
    ' =================================
    ' Steve Monfette
    ' Mister E Enr
    '
    ' This program show how to use/define/send a combination of String and Data
    ' to a PC terminal or else @9600 bauds.
    '
    ' We can still use HSEROUT and do the same thing, of course but the
    ' following use another approach wich :
    ' 1. Allow to modify one or all string/data in a snap when needed.
    ' 2. Call a string many time only by calling his name with the macro.
    ' That is still more code efficient than if you create and use
    ' a specific SUBROUTINE.
    '
    ' Also, if you compare this method to the use of multiple HSEROUT,
    ' you'll notice a slight difference in the size of the generated code.
    '
    ' This program could also be usefull to send string/data to various device
    ' like I2C, LCD,...
    ' ///////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

    @ errorlevel 0,-207 ' avoid anoying MPASM error message
    ' -- found label after column 1 --

    ' PIC Definition
    ' ==============
    ' Done with an old & dusty PIC16F877 @ 20MHZ
    '
    DEFINE LOADER_USED 1
    DEFINE OSC 20

    ' Hardware define
    ' ===============
    '
    TRISC=%10111111

    ' Serial Comm definition
    ' ======================
    '
    RCSTA=$90 ' Enable USART, continuous receive
    TXSTA=$24 ' Enable transmit, BRGH=1
    SPBRG=129 ' 9600 Bauds

    ' Variable definition
    ' ===================
    '
    Char var byte ' Character to be read/send
    SAddr var word ' String adress pointer

    ' Software initialisation
    ' =======================
    '
    clear ' set all variable to 0
    goto Start ' Skip any Macro And string Definition

    ' String Definition
    ' =================
    ' String must be defined as follow
    ' <label> dt <data>,0
    '
    ' could also be
    ' <label> dt <data>
    ' dt <data>
    ' .........
    ' dt <data>,0
    '
    ' Any String must be NULL terminated. Can contain text and numeric value
    '
    asm

    s1 dt "String #1",13,10,0

    s2 dt "String #2",13,10
    dt "********************",13,10,0

    s3 dt "String #3",13,10,0

    s4 dt "String #4..... THE LAST ONE",13,10,0

    endasm

    ' Macro Definition
    ' ================
    '
    ' SendString:
    ' ===========
    ' This send the according string via USART
    ' Format:
    ' =======
    ' SendString <StringName>
    '
    asm
    SendString macro StringLabel
    CHK?RP _SAddr ; Reach the right BANK of SAddr
    MOVE?CW StringLabel,_SAddr ; Store address of StringLabel in SAddr
    L?CALL SendIt ; Send the string.
    endm
    endasm
    @SendIt
    Readcode SAddr, char ' Read character
    if Char then ' if not NULL, send it
    ASM
    MOVE?BB _Char,TXREG ; Load TXREG with Char
    IsFull
    BIT?GOTO 0, PIR1, 4, IsFull ; Loop while TXREG is full
    ; The above is the same as
    ; IF PIR1.4=0 THEN GOTO IsFull
    ;
    INCF _SAddr,1 ; Point to the next character
    GOTO SendIt ; Do it again
    ENDASM
    endif
    return


    ' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    Start:
    ' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    '
    ' Here we will send our data by using the above macro
    '
    @ SendString s1 ; Send string with label 's1'
    @ SendString s2 ; Send string with label 's2'
    @ SendString s3 ; Send string with label 's3'
    @ SendString s4 ; Send string with label 's4'
    pause 1500 ; wait a little bit
    goto Start ; do it again
    [/html]
    Last edited by mister_e; - 27th August 2005 at 18:58.
    Steve

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

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. Please help with storing strings in codespace
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th May 2008, 02:02

Members who have read this thread : 1

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