Embedded Strings in your Code Space


Results 1 to 40 of 50

Threaded View

  1. #13
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Thumbs up It works!!!!

    Thanks Bruce, it works great!

    And now here it is utilizing your RS232 code:
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 40               ' change to suit oscillator speed
    
    temp var byte
    
    Main:
       CALL USART_Init
    
        Call prntSTR
    @ data "This is a string",0
    
        Call prntSTR
    @ data "yet another string again",0
    
        Call prntSTR
    @ data "and one more time!",0
    
    Done:
       Goto Done
    
    asm
    _USART_Init
        movlw   B'00100100'     ; initialize USART
        movwf   TXSTA           ; 8-bit, Async, High Speed
        movlw   .129            ; value for 19200 bps @ 40MHz
        movwf   SPBRG           ; set SPBRG for 19200 bps @ 40MHz
        movlw   B'10010000'     ; enable USART
        movwf   RCSTA
        return
    
    _prntSTR
    ;copy return address to TBLPTR and then pop it off the stack
        movf    TOSU,W
        movwf   TBLPTRU
        movf    TOSH,W
        movwf   TBLPTRH
        movf    TOSL,W
        movwf   TBLPTRL
        POP
    
    ;TBLPTR should now be pointing to 1st character in string
    Next_Char
        tblrd   *+              ; table read and post increment TBLPTR
        movff   TABLAT,_temp    ; fetch character from message string
        bra     Test_EOM        ; go test for EOM character
    	
    Continue                    ; If not EOM then...
        movf    _temp,W         ; move character into TXREG and...
        movwf   TXREG           ; send it!
        btfss   TXSTA,TRMT      ; has it been transmitted?
        goto    $-2             ; If not, keep checking
        bra     Next_Char       ; fetch next message character from table
    	
    Test_EOM
        movlw   .0              ; check for EOM character
        cpfseq  _temp,W         ; compare temp with w, if temp = 0 then end			
        bra     Continue        ; no EOM, so continue
        movlw   "\r"            ; move carriage return into TXREG and...
        movwf   TXREG           ; send it!
        btfss   TXSTA,TRMT      ; has it been transmitted?
        goto    $-2             ; If not, keep checking	
        movlw   "\n"            ; move line feed into TXREG and...
        movwf   TXREG           ; send it!
        btfss   TXSTA,TRMT      ; has it been transmitted?
        goto    $-2             ; If not, keep checking
    
    ;use incremented value of TBLPTR as new return address (push it)
        PUSH
        movf   TBLPTRU,W
        movwf   TOSU
        movf   TBLPTRH,W
        movwf   TOSH
        movf   TBLPTRL,W
        movwf   TOSL
        return                  ;finished with message, return to caller
    endasm
    This is real sweet, because all you have are 2 lines of code to send a message, and without any limitations as to how many or where they are located (assuming it fits in the program space).

    Well this is what I wanted in the first place, all it took was a bit of head scratching and some terrific help from you and Darrel. Heck until I started reading through the PIC18F reference material, I had assumed that there was no way to PUSH and POP a PIC chip (BTW, that is a great link to all kinds of good information).

    Next: Do the same thing for an LCD. Anyone got some good LCD asm code and an LCD to try it on?

    (yet another challenge for some brave soul)

    EDIT: Opps!! Darrel I guess you'll have to move this as well... Sorry

    see ya,
    Last edited by mytekcontrols; - 1st July 2005 at 05:04.

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08: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, 01: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