Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MPASM macros, simple move (movlf)

Status
Not open for further replies.
I'm just starting to ween myself away from the Parallax assembler.
But I do miss many of the shortcuts.

Example in the Parallax assembler the mov instrutiction was simplified. Although not as versitile as Microchips movlw & movwf commands it did have the advantage of making a listing both shorter and more readable (IMHO)

Code:
    movlf    macro x,y        ;move literal to file register W = literal
    movlw    x
    movwf    y
    endm

although it's a real simple macro, find it helpful (to me) when reading through a program.

Any suggestions, do you have a favorite PIC macro?
 
Most macros that I use are the built in ones (banksel). But I do have made few myself. One can use:

Code:
@TABLE	macro	const
	@MOVLF	TBLPTRL, LOW const
	@MOVLF	TBLPTRH, HIGH const
	@MOVLF	TBLPTRU, UPPER const
	endm

For simple TABLRD*+ instruction to read data from PIC18 ROM.

PS: I use the '@' sign for all macros, to remind me it is not a function name. Sometimed I accidentally may place a 'CALL macro_name' instead just 'macro_name' leading to erratic (understandable) behaviour. Such error is sometimes hard to track as MPLAB doeasn't issue an error/warning.
 
What is IF? ... else ...endif ? as it pertains to PIC assembly?
sorry for the look of the code its impossible to copy and paste from a .lst file without getting the line numbers ect..
i got this from DS00594B from microchip.
although there were were comments in the rest of the code , there were none for the If else endif statements.
ps i understand the use of( if else and endif) , but did not know it could be used in PIC programming..


Code:
00000001 00040 PICMaster EQU TRUE ; A Debugging Flag
00000001 00041 Debug EQU TRUE ; A Debugging Flag
00000001 00042 Debug_PU EQU TRUE ; A Debugging Flag



 T1OVFL
      BCF PIR1, TMR1IF ; Clear T1 Overflow Interrupt Flag
  if (PICMaster )
      MOVF DUMMY_PD, W ;
 else
     MOVF PORTD, W ;
   endif    MOVWF DC_HI ;
  if (PICMaster )
       MOVF DUMMY_PE, W ;
 else
      MOVF PORTE, W ;
 endif
      MOVWF DC_LO ;
 if (PICMaster )
      MOVF DUMMY_PB, W ;
 else
      MOVF PORTB, W ;
 endif
 
Those are just Assembler commands (Conditional assembly).

For example:

Code:
Fosc	equ	20	;This would be in a header file of our project


if	Fosc == 20	;This could be in the Delay file for example

	;20Mhz code here

endif

if	Fosc == 8

	;8Mhz code here


endif

It allows you to select which partions of code to compile.
More info on this is in the MPLAB help.
 
Jay.slovak said:
PS: I use the '@' sign for all macros, to remind me it is not a function name. Sometimed I accidentally may place a 'CALL macro_name' instead just 'macro_name' leading to erratic (understandable) behaviour. Such error is sometimes hard to track as MPLAB doeasn't issue an error/warning.

Not a bad idea, are there other characters MPLAB thinks is fine aside from @ or _
 
William At MyBlueRoom said:
Any suggestions, do you have a favorite PIC macro?
I'm fond of this macro/driver combination used for printing string tables located in-line with my code. It seems more intuitive (to me) than placing string tables at the beginning or end of the program.

Here's what it looks like when you use it;
Code:
;
        Print   " Menu items\n\n\r"
        Print   " 1 - Set default power-up azimuth\n\r"
        Print   " 2 - Set default power-up elevation\n\r"
        Print   " X - Exit, return\n\r"
;
Here's the actual Print macro;
Code:
;
;  Print macro - print in-line character string
;
Print   macro   str             ;
        local   String, P
        movlw   low String      ;
        movwf   PTRL            ;
        movlw   high String     ;
        movwf   PTRH            ;
        goto    P               ;
String  dt      str,0
P       call    PutString       ; print string
        endm
Finally, here's the PutString driver which correctly handles PCLATH and PCL and allows you to place string tables anywhere in memory, even straddling 256 byte boundaries;
Code:
;******************************************************************
;
;  PutString sends a character string through the RS232 port
;
;  Entry: setup PTRL and PTRH to string address before entry
;         string must be terminated with a 00 byte
;
PutString
        call    GetTable        ; get a table character           |B0
        andlw   b'11111111'     ;                                 |B0
        skpnz                   ; 00 byte, last character?        |B0
        return                  ; yes, return, else               |B0
        call    Put232          ; output character                |B0
        incfsz  PTRL,F          ; increment pointer               |B0
        goto    PutString       ;                                 |B0
        incf    PTRH,F          ;                                 |B0
        goto    PutString       ;                                 |B0
;
GetTable
        movf    PTRH,W          ;                                 |B0
        movwf   PCLATH          ;                                 |B0
        movf    PTRL,W          ;                                 |B0
        movwf   PCL             ;                                 |B0
 
Mike, that is a nice Macro ;)
Fortunatelly, with PIC18 there are no problems with paging, so putting strings in ROM is much easier.

William, well, I chose '@', I am sure there are more. Just make a few macros and functions and put some special signs at the beginning of their name and just try if compiler whines...
 
Jay.slovak said:
Mike, that is a nice Macro ;)
Fortunatelly, with PIC18 there are no problems with paging, so putting strings in ROM is much easier.
Hi Jay,

Yes, strings are much easier on the PIC18 and two characters fit nicely in each table entry 'word'.

The PIC18 version macro simply uses a call instruction followed immediately by the in-line string;
Code:
;
;  _Print macro
;
_Print  MACRO   str             ; print in-line string macro
        call    PutString       ;
        db      str,0
        ENDM
;
And here's the simple PIC18 stack based driver I came up with;
Code:
;******************************************************************
;
;  PutString - print in-line string via Stack and TBLPTR
;
;  string must be terminated with a 00 byte and does not need
;  to be word aligned
;
PutString
        movff   TOSH,TBLPTRH    ; copy return address to TBLPTR
        movff   TOSL,TBLPTRL    ;
        clrf    TBLPTRU         ; assume PIC with < 64-KB
PutNext
        tblrd   *+              ; get in-line string character
        movf    TABLAT,W        ; last character (00)?
        bz      PutExit         ; yes, exit, else
        rcall   Put232          ; print character
        bra     PutNext         ; and do another
PutExit
        btfsc   TBLPTRL,0       ; odd address?
        tblrd   *+              ; yes, make it even (fix PC)
        movf    TBLPTRH,W       ; setup new return address
        movwf   TOSH            ; 
        movf    TBLPTRL,W       ;
        movwf   TOSL            ;
        return                  ;
;
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top