Searching \ for '[PIC]:Relative jumps in MACROS & local variables?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Relative jumps in MACROS & local variables?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Relative jumps in MACROS & local variables?'
2001\07\19@213654 by Ian Hynes

flavicon
face
PICers,
I'm having a bit of trouble seeing how you declare local variables in
macros.

I wrote this LCD programme with MACROs all over the place to avoid
having to call nested subroutines and run into problems with the
2-level nests in the 16C57 & 16F84.
Obviously you can't use labels in a MACRO with countdown loops caus
you genearte a duplicate label error if you invoke it twice.So i used
relative jumps in them and it works OK.

The MPASM guide shows how you declare a local variable wth a fixed
value but is it possible to declare one to take care of the jump
address within a loop? say you wanted a label called "rotate" on the
bsf PORTB line? what to do?
Thanx - Ian

;*********************************************************
; LCD_TX  .. a MACRO to drive the HC44780 LCD in 4-bit
;            mode via a 3-wire interface. Rewritten as a MACRO
;            from subroutine lcdtx4 so as to work around the
;            16C57's 2-level nesting limitation.
;
; NOTE .. can only use RELATIVE jumps in MACROS where a loop
;         is involved. Otherwise a duplicated address error
;         will be generated.
; Data byte must already be in the DATA register when the
; routine is called. Data format ... D7 D6 D5 D4 RS x x x
; Registers needed .. charac
;                     count_10
;                     PORTB.CH =     (character\instrucs)
;                     PORTB.CK =     (SIPO clock)
;                     PORTB.EN =     (LCD Enable)
;This routine shifts a NIBBLE of data into the LCD but does so
;using a BYTE count. DATA must be in the HIGH NIBBLE of the
;charac register.
;************************************************************
LCD_TX MACRO
        IFDEF DEBUG
          movlw  0x02
         ELSE
          movlw  0x08
        ENDIF
        movwf    count_10
        bcf      STATUS,C
        bcf      PORTB,CK
        nop                    ;Rest between bit ops.
        bsf      PORTB,CH    ;***Initialise the data port.
LABEL=rotate in SUBROUTINE?????
        rlf      charac,1      ;Rotate the the data thru CARRY, MSB
first.
        btfss    STATUS,C      ;Data bit = 1?
         bcf     PORTB,CH      ;No  - send a zero
        nop                    ;Rest between bit ops.
        bsf      PORTB,CK      ;Clock the bit thru
        nop
        nop                    ;Rest between bit ops.
        bcf      PORTB,CK
        decfsz   count_10,1    ;Stepped down thru 8 bits?
         goto    $-0x0A        ;No  - RELATIVE jump back to bsf
PORTB,CH
        nop                    ;Rest between bit-ops.
        bsf      PORTB,EN      ;Enable the LCD and
        nop
        nop
        nop                    ;transfer the data.
        bcf      PORTB,EN
        nop
        bcf      PORTB,CH      ;Leave PORTB in a defined state. All
LOW.
        ENDM

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\07\19@235614 by parkiss

picon face
Ian-

MPASM doesn't choke on multiple instances of:

LCD_TX MACRO
 LOCAL rotate
 IFDEF DEBUG
  movlw  0x02
 ELSE
  movlw  0x08
 ENDIF
 movwf    count_10
 bcf      STATUS,C
 bcf      PORTB,CK
 nop                    ;Rest between bit ops.
 bsf      PORTB,CH      ;***Initialise the data port.
rotate
 rlf      charac,1      ;Rotate the the data thru CARRY, MSB first.
 btfss    STATUS,C      ;Data bit = 1?
 bcf      PORTB,CH      ;No  -  send a zero
 nop                    ;Rest between bit ops.
 bsf       PORTB,CK     ;Clock the bit thru
 nop
 nop                    ;Rest  between bit ops.
 bcf      PORTB,CK
 decfsz   count_10,1    ;Stepped  down thru 8 bits?
 goto     rotate        ;No - jump back to bsf PORTB,CH
 nop                    ;Rest between bit-ops.
 bsf      PORTB,EN      ;Enable the LCD and
 nop
 nop
 nop                    ;transfer the data.
 bcf      PORTB,EN
 nop
 bcf      PORTB,CH      ;Leave PORTB in a defined state. All LOW.
ENDM

On 20 Jul 01 at 11:36, Ian Hynes wrote:

> PICers,
> I'm having a bit of trouble seeing how you declare local variables
> in macros.

Regards,

Steve
Boulder City, Nevada

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


2001\07\20@015846 by Quentin

flavicon
face
Ian, you are getting there. If you want a label in a macro that gets
repeated in your program, you must declare the label as a LOCAL to that
macro.
LCD_TX MACRO
       LOCAL  rotate   ;this label is for this macro, macro can be used many
times
        IFDEF DEBUG
       .
       .
rotate   bsf      PORTB,CH    ;***Initialise the data port.
       .
       .
       goto    rotate

Hope this helps
Quentin

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2001\07\20@081838 by Olin Lathrop

face picon face
> I'm having a bit of trouble seeing how you declare local variables in
> macros.

blahblah macro
        local <local symbol name>
        .
        .
        .
        endm

> Obviously you can't use labels in a MACRO with countdown loops caus
> you genearte a duplicate label error if you invoke it twice.

You can if you declare them local to the macro as above.

> The MPASM guide shows how you declare a local variable wth a fixed
> value but is it possible to declare one to take care of the jump
> address within a loop? say you wanted a label called "rotate" on the
> bsf PORTB line? what to do?

I can't make sense of what you are asking here.  If you want to see examples
of local symbols used in macros, take a look at STD.INS.ASPIC at
http://www.embedinc.com/pic.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...