Code:
Here's a handy little program that allows you to embed a string in your program which is accessed by the preceding call. In this case, it's used to write strings to an LCD display but the principle is useful elsewhere. The code was written for a 18F2480 ;The string must be terminated by a null ie ; CALL LCD_STR ; DA "Hello",0 ;On Exit,PC on stack points to next program instruction LCD_STR ;First copy address of string to program memory indirection pointer MOVFF TOSU,TBLPTRU ;Upper word of stack pointer MOVFF TOSH,TBLPTRH ;Middle MOVFF TOSL,TBLPTRL ;Low NEXTCH TBLRD*+ ;Read next byte in string & increment pointer MOVF TABLAT,W ;Get character BZ ENDSTRG LCD_CHAR_W ;Macro to write W to display BRA NEXTCH ;This way to update return address to that following end of string null ENDSTRG ;Beware, if the string is an even length, the return address with be invalid INTERRUPTS_OFF ;Else screwy things can happen BTFSC TBLPTRL,0 ;Is return address odd? TBLRD*+ ;Increment pointer to end on an even address MOVF TBLPTRL,W ;Low MOVWF TOSL MOVF TBLPTRH,W ;Mid MOVWF TOSH MOVF TBLPTRU,W ;Upper MOVWF TOSU INTERRUPTS_ON RETURN
James Newton of MassMind Says: " Nice! "