Announcement

Collapse
No announcement yet.

GOSUB address

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GOSUB address

    How can I make GOTO/GOSUB to a specific memory loctaion? GOSUB $1000 doesn`t work

  • #2
    Use an inline Assembly command:

    Code:
    @  goto 0x6200  ; jump to bootloader
    Charles Leo
    ME Labs, Inc.
    http://melabs.com

    Comment


    • #3
      You would have to use Assembly Language to do it. To write ASM in PBP:
      ASM
      [write code]
      END ASM
      or
      @ [Line of ASM]
      That part is covered in the PBP Manual.
      To call a specific address, you have to know what BANK that address is in. The Memory Organization section of the processor's Data Sheet will break that down for you. I have the PIC16F1503 Data Sheet in front of me. Section 3.1.1 covers accessing memory locations directly. The 16F1503 addresses don't go up to $1000, so here is address $A70:
      [CODE]
      ASM
      BANKSEL 15h ;Bank 20d
      MOVLP 0A70h ;PCLATCH = address $A70
      ENDASM
      Since this is untested, here's another potential version:
      ASM
      BANKSEL 15h
      GOTO 0A70h
      ENDASM

      I've never done that before, but the Data Sheet offers other possibilities. Table 27-3 shows an overview of the Assembly Commands, while Section 27-2 gives a more detailed description of how to use them.
      We can crack this cotton PIC'n thang!

      Comment


      • #4
        I'm afraid, Mike, you're conflating variable access with code address. Bank Selection only applies to RAM addresses, not codespace. Some older devices might have code pages to deal with.
        Charles Leo
        ME Labs, Inc.
        http://melabs.com

        Comment


        • #5
          Sorry, as I said I never tried it. I spent some time with the Data Sheet. You replied before I hit send or I never would have posted such uninformed crap.
          We can crack this cotton PIC'n thang!

          Comment


          • #6
            another obvious way is to use a label eg.

            Code:
              
            
            more code ..............
            
              GOSUB Write_HEF  ;  gosub label
                ;prove success
                for i= 0 to (N_HeF_V-1)
                    READCODE HeF_START+(i),RESULT[i]
                next
                lcdout $FE,1
                lcdout $FE,$80,"X " ,#RESULT[0],",",#RESULT[1]
                lcdout $FE,$c0,"X " ,#RESULT[2],",",#RESULT[3]
            
            more code ..............
            
            end
            
            Write_HEF:    ;   label 
            ASM
                CALL   FLERASE       ; WARNING ENTIRE ROW IS ERASED BEFORE WRITE
                movlw   _N_HeF_V
                BANKSEL _hefx
                MOVWF   _hefx
                BANKSEL _heFvar
                movlw   LOW  _heFvar
                MOVWF   FSR0L
                movlw   HIGH _heFvar
                MOVWF   FSR0H
                BANKSEL PMADRH
                MOVLW   HIGH (_HeF_START)
                MOVWF   PMADRH                        
                MOVLW   LOW  (_HeF_START)
                MOVWF   PMADRL                     
                BCF     PMCON1,CFGS
                BSF     PMCON1,WREN
                BSF     PMCON1,LWLO
                BCF     PMCON1,FREE
            LOOP
                MOVIW   FSR0++         ; Load  data byte into lower
                MOVWF   PMDATL         ;
                MOVIW   FSR0++         ; Load  data byte into upper
                MOVWF   PMDATH         ;
                BANKSEL _hefx
                DECF    _hefx,F
                BTFSC   STATUS,Z
                GOTO    START_WRITE
                CALL    ULOC
                ;BANKSEL PMADRL
                INCF    PMADRL,F        ; Still loading latches Increment address
                GOTO    LOOP            ; Write next latches
            START_WRITE
                BANKSEL PMCON1  
                BCF     PMCON1,LWLO
                CALL    ULOC
                ;BANKSEL PMCON1
                BCF     PMCON1,WREN
                BANKSEL 0
                RETURN  
            ULOC
                BANKSEL PMCON2
                MOVLW   55h              ; Start of required write sequence:
                MOVWF   PMCON2 & 0x7F    ; Write 55h
                MOVLW   0XAA             ;
                MOVWF   PMCON2 & 0x7F    ; Write AAh
                BSF     PMCON1 & 0x7F,WR ; Set WR bit to begin write
                NOP                      ; NOP instructions are forced as processor
                NOP                      ; loads program memory write latches  
                RETURN
            FLERASE   
                BANKSEL PMADRL
                MOVLW   HIGH (_HeF_START)
                MOVWF   PMADRH                        
                MOVLW   LOW  (_HeF_START)
                MOVWF   PMADRL 
                BCF     PMCON1,CFGS      ; Not configuration space
                BSF     PMCON1,FREE      ; Specify an erase operation
                BSF     PMCON1,WREN      ; Enable writes
                MOVLW   55h              ; Start of required sequence to initiate erase
                MOVWF   PMCON2           ; Write 55h
                MOVLW   0AAh             ;
                MOVWF   PMCON2           ; Write AAh
                BSF     PMCON1,WR        ; Set WR bit to begin erase
                NOP                      ; NOP instructions are forced as processor starts
                NOP                      ; row erase of program memory.
                BCF     PMCON1,WREN      ; Disable writes
                ;BANKSEL 0
                RETURN
            
            endasm


            Comment

            Working...
            X