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 listserv@mitvma.mit.edu with SET PICList DIGEST in the body