Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Passing a bit as a macro argument'
2001\10\04@223027
by
TH
|
What is the proper way of passing a bit as an argument in a macro ?
For example, the following code generates a macro that sets "bit1" and
clears "bit2" when "Last_Key" is equal to a given constant :
; TEXT SUBSTITUTION DEFINITIONS
#define BNK STATUS,RP0
#define ZERO STATUS,Z
#define CARRY STATUS,C
#define GREEN_LED PORTA,5
#define RED_LED PORTA,3
#define ESC 0x00
#define BS 0x01
#define DEL 0x08
#define HOME 0x04
#define PGUP 0x05
#define PGDN 0x06
#define END 0x07
; VARIABLE DEFINITIONS
cblock 0x20
Last_key
TmpStr
String : 16
endc
; MACRO DEFINITIONS
KEY_TOG macro key, bit1, bit2
movlw key
xorwf Last_Key,w
btfss ZERO
goto $+3
bsf bit1
bcf bit2
endm
- snipped -
; MAIN PROGRAM LOOP
Start
KEY_TOG PGUP,GREEN_LED, RED_LED
goto Start
end
The compiler doesn't differentiate the comma for bit #5 in the GREEN_LED
definition from the argument seperator in the Macro declaration. So it says
I supplied too many arguments thinking I meant to pass 5 arguments to the
macro as if : KEY_TOG 0x05,PORTA,5,PORTA,3 when what I actually meant was
KEY_TOG 0x05,(PORTA,5),(PORTA,3).
I know this is just how text substitution IS supposed to work but is there
any other way around it ?
--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
2001\10\04@224055
by
TH
DOH!
Posted to the list too fast again it seems ... The answer jumped at me
seconds after pressing SEND.
Obviously, just add a file before each bit in the macro's argument list.
Such as :
#define GREEN_LED PORTA,5
#define RED_LED PORTA,3
KEY_TOG macro key, FILE1, bit1, FILE2, bit2
movlw key
xorwf Last_Key,w
btfss ZERO
goto $+3
bsf FILE1,bit1
bcf FILE2,bit2
endm
KEY_TOG 0x05, GREEN_LED, RED_LED
This seems to have satisfied the compiler =)
thanks anyway and sorry for the wasted bandwidth,
TH
{Original Message removed}
2001\10\05@073200
by
Olin Lathrop
> The compiler doesn't differentiate the comma for bit #5 in the GREEN_LED
> definition from the argument seperator in the Macro declaration. So it
says
> I supplied too many arguments thinking I meant to pass 5 arguments to the
> macro as if : KEY_TOG 0x05,PORTA,5,PORTA,3 when what I actually meant was
> KEY_TOG 0x05,(PORTA,5),(PORTA,3).
>
> I know this is just how text substitution IS supposed to work but is there
> any other way around it ?
You can't pass two macro parameters, then use them with one name inside the
macro. Fortunately, you can still call the macro the way you are doing, but
the macro itself will have to be written to receive all 5 arguments,
something like:
key_tog macro key, bit1_reg, bit1_bit, bit2_reg, bit2_bit
This isn't that bad since the main code will still look the way you want it
to, just the macro will look a bit different.
********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, spam_OUTolinTakeThisOuT
embedinc.com, http://www.embedinc.com
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2001\10\05@074058
by
Bob Ammerman
Try:
KEY_TOG macro key p1,b1,p2,b2
movlw key
xorwf Last_Key,w
btfss ZERO
goto $+3
bsf p1,b1
bcf p2,b2
endm
Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)
{Original Message removed}
More... (looser matching)
- Last day of these posts
- In 2001
, 2002 only
- Today
- New search...