I've tested the following code on the PIC18F series (I don't know if it will work on other PIC's).
Here is the format to call the above routine, in order to output the individual message strings: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
In the section: "---- your output code goes here"Code:MsgIdx = 0: GoSub GetMesg MsgIdx = 1: GoSub GetMesg MsgIdx = 2: GoSub GetMesg
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).
Anything is possible, just use your imagination.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
Edit: corrected missing variable declaration for ascii
Enjoy,




Bookmarks