Macros for useing Motorola ASM code in MPASM (!)
http://electronics.stackexchange.com/questions/8723/bit-position-to-bitmask-conversion-using-mpasm-directives ("Bit position to bitmask conversion using MPASM directives")
What is a good way to define at the top of my source code which pin is connected to the red LED, the green LED, etc.? When (not if!) they get re-connected to some other pin, I want to tweak that one place at the top of my code and it will Just Work -- rather than painstakingly finding and changing each and every line that ever touches the red or green LED. (Where is the page in the MassMind that already covers this, if any?)
Olin Lathrop says:
In this same, spirit I've made my own macros for handling bank switching and lots of other stuff public. My "standard" macros come in two include files, which are probably too large to attach to this message. I've set up a web site at http://www.embedinc.com/pic to eventually make most of my PIC development environment available to everyone.
John [jsand at PIXIE.CO.ZA] says:
After disabling interrupts i.e.bcf intcon,gie
complete safety is not assured unless you check the global enable bit to see that it *really* is as expected (clear, that is).
My trouble with this magically vanished when I started to use macros for int. enable/disable:int_off MACRO ;disables all interrupts bcf intcon,gie btfsc intcon,gie ;make sure bit cleared (int could ;have occurred 1/2way thru instruction) goto $-2 ENDM int_on MACRO ;re-enable interrupts bsf intcon,gie ENDM
Simon Niel says:
...this might help avoid a few headaches with the '877 series...; Bank[3:0] variables - 16 bytes accessible in all banks cblock 0x70 lo_save_w ; must be here as bank not known when interrupt occurs program_status ; flags for program operation ; end_global_vars:0 endc if end_global_vars > 0x80 error "Global variable space overrun" endif ; Bank 0 variables - Must not extend above 0x6F cblock 0x20 some_variable ; end_bank_0_vars:0 endc if end_bank_0_vars > 0x70 error "Bank0 variable space overrun" endif ; Bank 1 variables cblock 0xA0 more_variables:16 ; end_bank_1_vars:0 endc if end_bank_1_vars > 0xf0 error "Bank1 variable space overrun" endif ; Bank 2 variables cblock 0x20 you_probably_get_the_point_now ; end_bank_2_vars:0 endc if end_bank_2_vars > 0x70 error "Bank2 variable space overrun" endif ; Bank 3 variables cblock 0xA0 oh_never_mind_then ; end_bank_3_vars:0 endc if end_bank_3_vars > 0xf0 error "Bank3 variable space overrun" endif
OK, I hate unnecessary typing. I like little macros. These are some I use. Others will tell you of their distaste for macros. Don't listen to them !! ;-))) But you do need to be careful ... although a macro name is just one line in the editor, it could be several instructions, depending on what it does of course, and that affects things like GOTO $+. If you GOTO labels or can actually count the embedded instructions (on your fingers will do), you'll be OK. Use them just as normal mnemonics
For example, an awful lot of code behind these four lines. But the macros have been written so that these four easily-typed "instructions" really speed up development and minimise typos;============== ;pr_v0 lcd_pos ln1+.06 ;position 6 on line 1 ; disp 0x7f ;<- on LCD ; sec1 ;1 second delay ; clrscrn ;clear LCD ;============== mov macro litval,file ;eg mov .57,temp = load temp with dec 57 movlw litval movwf file endm movfw macro litval ;eg movfw temp = copy temp to W movf litval,w endm skpnc macro btfsc carry endm skpc macro btfss carry endm clrc macro ;clear C bcf status,0 endm clrz macro ;clear Z bcf status,2 endm setz macro bsf status,2 endm skpz macro ;skip if Z is set btfss status,2 endm skpnz macro btfsc status,2 endm usec macro ;1us delay movff temp,temp movff temp,temp movff temp,temp movff temp,temp movff temp,temp endm usec10 macro ;10us delay mov .08,cnt1 usec ;one macro inside another decfsz cnt1 bra $-16 endm
Here's an example of what to watch for re gotos#define switch portb,6 ;switch input
For not-the-18 seriessw_on macro ;if switch = 1, then switch is on, leave loop btfss switch goto $-1 ;loop back to the btfss endm
On the 18 seriessw_on macro btfss switch bra $-2 endm
I get to modify someone else's PIC code. They have a single .asm program separated into 2 pages by ORG statements. I think I have figured out the usage for PCLATH, but wish it were easier. It seems there are linker directives such as BANKSEL that do this work for me, but I need to have linker and object files. I used the standard linker file from Microchip for my part; the compiler complains that directives such as CODE and UDATA can only be used when creating object files?? Any help on using MPLINK and "code sections" would be appreciated. Thanks!
...I am a newcomer to Assembly Language (MPASM). What puzzles me is those "equ" equates. How does one differentiate a register file location in "ram" from a register file VALUE! For example indf equ 0x00 c equ 0x00 . Does MPASM have reserved names for fixed registers so that equates automatically refer to a location in Ram and not an actual value? Thanks for any reply.
Answer: It doesn't! or rather, it does only by context. For example the program counter is register number 2 and so a reference like movfw 2 would result in W being loaded with the value of PC while at the same time movwl 2 will load w with the value 2 rather than the value of register 2. The equates are only to help humans read the code... to the machine, its all just numbers anyway.
|file: /Techref/microchip/mpasm.htm, 11KB, , updated: 2011/1/11 17:46, local time: 2014/10/22 02:33,
|©2014 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/microchip/mpasm.htm"> MPASM</A>
|Did you find what you needed?|
PICList 2014 contributors:
o List host: MIT, Site host massmind.org, Top posters @20141022 RussellMc, Richard R. Pope, IVP, John Gardner, alan.b.pearce, David C Brown, James Cameron, Bob Blick, Isaac Marino Bavaresco, Josh Koffman,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!