At 12:50 PM 4/25/2012, Jan-Erik Soderholm wrote: > > > > setbsrbit MACRO target, bnum ;bit > > movlb (target>>7) ;get bank bits > > CURRBANK set ((target>>7)<<7) ; > > endm > > > >OK. I'm lost... :-) > >What does the bnum parameter do ? Its a throw-away parameter. My include files are all in the form of: ; INTCON Register Bits rb 0 #define _IOCIF INTCON,0 ; InterruptOnChange flag rst in= sw #define _INTF INTCON,1 ; RB0 INT interrupt flag rst in= sw #define _T0IF INTCON,2 ; TMR0 overflow int flag rst in= sw #define _IOCIE INTCON,3 ; InterruptOnChange Enable active= hi #define _INTE INTCON,4 ; INTF interrupt enable active= hi #define _T0IE INTCON,5 ; TMR0 interrupt enable active= hi #define _PEIE INTCON,6 ; Peripheral Interrupt Enable active= hi #define _GIE INTCON,7 ; global interrupt enable active= hi INT_INIT EQU b'11000000' ;GIE, PEI enabled INT_SLEEP EQU b'00011000' ;wake up from i/p & pin change (no GIE) This allows me to manipulate bits without ever knowing or caring in=20 which register the bit belongs to. For example: bsf _GIE ;next line of code Another example, this time using the above macro: ;EECON1 rb 3 #define _RD EECON1,0 ; Read: 1=3D initiate read #define _WR EECON1,1 ; Write: 1=3D initiate write #define _WREN EECON1,2 ; Erase/Write enable: 1=3Denable #define _WRER EECON1,3 ; Erase/Write error: 1=3Derror #define _FREE EECON1,4 ; Erase/Write select: 1=3DErase, 0=3DWrite #define _LWLO EECON1,5 ; Ld Wr Latches Only =3D1; 0=3D Write all = data #define _CFGS EECON1,6 ; Config Select =3D1; 0=3D access Program = memory #define _EEPGD EECON1,7 ; movlw MAGIC_VALUE_ADDRESS setbsr EEADRL movwf RB(EEADRL) clrf RB(EEADRH) ;somewhere later in the code, now I want to read that value. I have=20 no idea of what value BSR contains, so I need to set up the BSR=20 register. Because I'm lazy, I don't want to go and find out what=20 register the "_RD" bit belongs to. So I use the macro: setbsrbit (_RD) bsf BB(_RD) Note how "_RD" expands to EECON1,0 - this means that the macro has=20 two parameters passed to it. Since all I want is the bank in which=20 the register belongs to, I simply throw away the second=20 parameter. But the macro has to be written to accept that second=20 parameter, else the assembler gets mad at you and throws a fatal error. [RANT ON] Why doesn't everyone write code using #define statements like I've=20 shown above. It seems, to me, to be completely ridiculous that=20 people have to string register names and bit names together to do a=20 simple bit manipulation. This is the new millennium, for gosh sakes! One of the smartest people I've ever had the pleasure to learn from=20 (Andrew Warren) showed me the above technique and I've been using it=20 ever since. That's back to the late '80s, early '90s. [RANT OFF] dwayne --=20 Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax www.trinity-electronics.com Custom Electronics Design and Manufacturing --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .