Searching \ for '[PIC] wot is a macro!!!!!??' 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: 'wot is a macro!!!!!??'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] wot is a macro!!!!!??'
2007\02\25@132702 by picnoob

flavicon
face

hi, i hav been looking at some sample source code, and i keep finding these
macro things, first of all what are they?? i have searched these forums, and
the www for the answer to no avail.
they look extremely useful, but how do i use them?? are they like
subroutines that you can pass values to?

this is annoying.
--
View this message in context: www.nabble.com/wot-is-a-macro%21%21%21%21%21---tf3288237.html#a9146433
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2007\02\25@140936 by Jan-Erik Söderholm

face picon face
RTFM.

MPASM/MPLINK User Guide, Chap 7, page 153.

> this is annoying.

Yes.

Jan-Erik.


picnoob skrev:
> hi, i hav been looking at some sample source code, and i keep finding these
> macro things, first of all what are they?? i have searched these forums, and
> the www for the answer to no avail.
> they look extremely useful, but how do i use them?? are they like
> subroutines that you can pass values to?
>
> this is annoying.

2007\02\25@150429 by Andy Tuthill

picon face
part 1 1453 bytes content-type:text/plain; format=flowed (decoded quoted-printable)

If you don't have the printed version and are using MPlab then look under the help topics index under Macro.  The help files are actually pretty good.   Here is a simple example:

Bank_1                Macro                ;selects bank 1 in Status register
       bsf        STATUS,RP0
       bcf        STATUS,RP1
       ENDM

This allows me to simply type 'Bank_1' in my code for a 16F part instead of the two commands.  I have a standard header file with lots of these kind of things.

If you still aren't clear then post again.

Regards,
Andy

PS - LMAO Jan-Erik!


{Quote hidden}

>

2007\02\25@153851 by =?windows-1252?Q?Jan-Erik S=F6derholm?= n/a

face picon face
Hi.

The example is of course correct, but BANKSEL is better
since you don't have to know if you should use the
Bank_0, Bank_1, Bank_2 or Bank_3 macro.  :-)
With that macro you still have to look-up the SFR
in the datasheet to find the correct bank for it...

Personaly, I think the page-oriented PDF manual
(printed or on-screen) is easier to navigate if
you're not realy sure what you are looking for.
And I see no reaon to *not* download it since
it's on the same webpage as the MPLAB install
kit anyway...

Best Regards,
Jan-Erik.


Andy Tuthill skrev:
{Quote hidden}

>> --

2007\02\25@170919 by Jinx

face picon face
> are they like subroutines that you can pass values to ?

Yes, except that they are generally in-line code. IOW you
don't call or jump to them. The assembler substitutes real
code for the macro label. As Jan-Erik said, there is a manual
for macros in MPLAB and you should read it

On a small PIC like the F84 you should be wary of over-using
macros. They will eat more memory than sub-routines. Some
people just plain don't like macros, for whatever reason, but they
are as useful a construct as sub-routines

Here's something practical. These two macros for addressing
and displaying on a 16x2 LCD, which you should find useful,
as you're using one for your clock (I think). These macros are
good for me because position and text to be typed in (almost)
plain English, well a pseudo-HLL anyway, and saves a lot of
geeky and unnecessary thinking. The simplification also makes
it easier to refer to and edit at a later date

First the macros are defined

lcd_pos  macro litval
        movlw litval-1
        call  address
        endm

disp     macro litval
        movlw litval
        call  write_d
        endm

Constants have also been declared

ln1      set     0x00         ;LCD offset line 1
ln2      set     0x40         ;LCD offset line 2

In use would be something like this (from a solenoid driver for
a stop-motion camera)

        lcd_pos ln1+.16      ;show as paused
        disp    "P"

This displays "P" in the bottom right corner of a 16x2

In memory after assembly you'd see

MOVLW 0xf
CALL 0xd56
MOVLW 0x50
CALL 0xd62

If print position is already set, and LCD is auto-incrementing

show75   disp    "7"
        disp    "5"

You could write a string-handling macro for text/numbers

Note that the parameter in the lcd_pos definition is litval-1. That's
because line 1 character 1 of the LCD is actually address 00, but
I like to think 1-16 for the physical display. You'll see in the hex
above that the text '16' has become 0x0f (15)

The address routine called is part of the 4-bit interface on PortA

;===============================================
;        LCD commands
;================================================

line1    movlw  0x00          ;line 1, column 0
        call   address
        return

line2    movlw  0x40          ;line 2, column 0
        call   address
        return

address  addlw  0x80          ;set high bit of address command
        call   write_c
        return

write_c  bcf    rs            ;write command
        bra    d_out

write_d  bsf    rs            ;write data

d_out    movwf  temp          ;store 8-bit value
        movf   porta,w       ;read port
        andlw  0xf0          ;clear LSN
        movwf  bshad         ;0000 xxxx
        movf   temp,w        ;add temp MSN to bshad
        andlw  0xf0
        swapf  wreg,w        ;add into low nybble
        addwf  bshad,w
        movwf  porta         ;write to port

        bcf    rw
        nop
        bsf    en
        nop
        bcf    en

        movf   porta,w       ;read port
        andlw  0xf0          ;clear LSN
        movwf  bshad         ;0000 xxxx
        swapf  temp,w        ;add LSN to bshad
        andlw  0xf0
        swapf  wreg,w        ;add into low nybble
        addwf  bshad,w
        movwf  porta         ;write to port

        bcf    rw
        nop
        bsf    en
        nop
        bcf    en

        call   getbusy
        return

getbusy  bsf    rw            ;set LCD RW for Read
        usec
        bcf    rs

        movlw  b'00011000'   ;make a3 (d7) an input
        movwf  trisa

;NB, Busy Flag can be polled before attempting to write to LCD
;if timing does not permit excessive time looping here

        bsf    en
rdbusy   btfsc  busy          ;loop until Busy Flag clear
        bra    rdbusy
        bcf    en
        usec
        bcf    rw

        movlw  b'00010000'   ;a3 (d7) as output again
        movwf  trisa

        return

2007\02\25@172710 by Dario Greggio

face picon face
>>are they like subroutines that you can pass values to ?

Yep: think of a macro as a "fast subroutine" or inline-function
(to some extent).

That is, use them in place of a subroutine when you *need* speed, or
when size of macro-code would be as small as the calling-code itself.

--
Ciao, Dario

2007\02\25@173507 by Jinx

face picon face
BTW 'noob, the bra mnemonics in the code are because it was for
an 18F. Use goto for the 16F

Yes, guilty, I was a naughty boy and didn't use LAT for that routine.
It was copied over from an 877

I'd like 7 other coding offences taken into consideration

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