Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 20th September 2006, 05:36 PM   (permalink)
Default MPASM macros, simple move (movlf)

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?
__________________
Bill
Home of the
Firefly PIC Tutor
Inchworm ICD2

http://www.blueroomelectronics.com
William At MyBlueRoom is offline   Reply With Quote
Old 20th September 2006, 09:51 PM   (permalink)
Default

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.
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline   Reply With Quote
Old 20th September 2006, 11:19 PM   (permalink)
Default

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
williB is offline   Reply With Quote
Old 20th September 2006, 11:42 PM   (permalink)
Default

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.
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline   Reply With Quote
Old 22nd September 2006, 02:11 PM   (permalink)
Default

Quote:
Originally Posted by Jay.slovak
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 _
__________________
Bill
Home of the
Firefly PIC Tutor
Inchworm ICD2

http://www.blueroomelectronics.com
William At MyBlueRoom is offline   Reply With Quote
Old 22nd September 2006, 04:54 PM   (permalink)
Default

Quote:
Originally Posted by William At MyBlueRoom

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, K8LH is offline   Reply With Quote
Old 22nd September 2006, 09:07 PM   (permalink)
Default

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...
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline   Reply With Quote
Old 22nd September 2006, 11:17 PM   (permalink)
Default

Quote:
Originally Posted by Jay.slovak
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 by Mike, K8LH; 23rd September 2006 at 07:08 AM.
Mike, K8LH is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
SIMPLE ADC PROBLEM neelam29 Micro Controllers 2 9th March 2006 08:46 AM



All times are GMT. The time now is 09:02 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.