Message String Table using Readcode


Results 1 to 3 of 3

Threaded View

  1. #1
    mytekcontrols's Avatar
    mytekcontrols Guest

    Default Message String Table using Readcode

    I've tested the following code on the PIC18F series (I don't know if it will work on other PIC's).

    Code:
    MsgBaseAddr var word
    MsgIdx var byte
    Msg_Ctr var byte
    Char_Ctr var byte
    ascii var byte
    
    '================================================
    ' Program Start
    '================================================
    'GetMesg Program Routine retrieves character string from Message Table
    'Format: "MsgIdx = X: GoSub GetMesg" (where X = 0 to last message in table)
    
    GetMesg:
    'Initialize counters
        Msg_Ctr = 0
        Char_Ctr = 0
    
    'Retrieve Message Table Base Address
    asm
        movlw  Low Msg_table
        movff  WREG, _MsgBaseAddr
        movlw  High Msg_table
        movff  WREG, _MsgBaseAddr + 1
    endasm
    
    'Locate beginning of message string and adjust base address to match
        While MsgIdx > Msg_Ctr                  ' When we have a match, exit!
        Readcode MsgBaseAddr, ascii             ' Retrieve character and
        MsgBaseAddr = MsgBaseAddr + 1           ' move index to next position. 
        If ascii = 0 Then                       ' If at end-of-message...
            Msg_Ctr = Msg_Ctr + 1               ' Increment to next mesg string and
            If MsgBaseAddr // 2 = 0 Then        ' Determine end-of-string padding.
                MsgBaseAddr = MsgBaseAddr + 2   ' If Even #, pad 2 spaces
            Else
                MsgBaseAddr = MsgBaseAddr + 1   ' If Odd #, pad 1 space
            Endif
        Endif
        Wend
    
    ;Retrieve message and send it
    GetString:
        Readcode (MsgBaseAddr + Char_Ctr), ascii	' Retrieve character
        If ascii = 0 Then Return			' Leave if end-of-message!
    
    '---- your output code goes here (HSEROUT [ascii], LCDOUT ascii, ect) ----
    
        Char_Ctr = Char_Ctr + 1			' set pointer to next character
        Goto GetString
    
    '================================================
    ' Message Table
    '================================================
    
    ' Each string is terminated with a 0
    asm
    Msg_table
        DATA "message #0",0
        DATA "message #1",0
        DATA "message #2",0
        DATA "message #3",0
        DATA "message #4",0
        DATA "message #5",0
        DATA "message #6",0
        DATA "message #7",0
        DATA "message #8",0
        DATA "message #9",0
        DATA "message #10",0
    endasm
    Here is the format to call the above routine, in order to output the individual message strings:
    Code:
        MsgIdx = 0: GoSub GetMesg
        MsgIdx = 1: GoSub GetMesg
        MsgIdx = 2: GoSub GetMesg
    In the section: "---- your output code goes here"
    You can do whatever you desire to fullfill your particular needs. For instance; In the following example, we add a carriage return and linefeed at the end of the message string, sending it all out the hardware usart (RS232).
    Code:
    ;Retrieve message and send it
    GetString:
        Readcode (MsgBaseAddr + Char_Ctr), ascii	' Retrieve character
        If ascii = 0 Then Exit			' Leave if end-of-message!
        HSEROUT [ascii]
        Char_Ctr = Char_Ctr + 1			' set pointer to next character
        Goto GetString
    Exit:
        HSEROUT [$0D,$0A]
        Return
    Anything is possible, just use your imagination.

    Edit: corrected missing variable declaration for ascii

    Enjoy,
    Last edited by mytekcontrols; - 10th July 2005 at 23:05. Reason: forgot to declare variable

Similar Threads

  1. How about String Variables?
    By mytekcontrols in forum PBP Wish List
    Replies: 40
    Last Post: - 20th January 2015, 12:53
  2. Lookup Table
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th March 2008, 10:38
  3. Embedded Strings in your Code Space
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 9th March 2008, 07:50
  4. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  5. PIC 18F452 Table Pointer/ Table Read
    By sougata in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th March 2006, 03:07

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