Anthony Van Herrewege wrote: > Could someone be so kind as to check the following 8 lines of > code? I think I understand how macro's work, but this is only the > 2nd time I'm writing PIC code. What it should do is: I type the > command TRISIO 2, 1 and pin 2 becomes an input. > > Is this code OK for that? It's for a PIC10 and I need BSF en BCF > commands on the TRIS register, but I guess you already figured > that one out. > > TRISIO macro pin, status > if status == 1 ; 1 = Input > BSF RAMTRIS, pin ; Set the pin to input > else > BCF RAMTRIS, pin ; Set the pin to output > endif > MOVFW RAMTRIS > TRIS GPIO ; TRIS the GPIO ports > endm Anthony: Your code will work fine... But it's never a bad idea to put error- checking in your macros: TRISIO MACRO PIN,STATUS IF ((PIN) > 2) ERROR "PIN NUMBER MUST BE 0, 1, OR 2!" ENDIF IF (STATUS) BSF RAMTRIS,(PIN) ELSE BCF RAMTRIS,(PIN) ENDIF MOVF RAMTRIS,W TRIS GPIO ENDM Note that I've also replaced your "IF STATUS == 1" with "IF (STATUS)". That's so "0" will clear the bit and any non-zero value will set it... Which is more-intuitive behavior, I think, than what you had, which would clear the bit on zero and also clear it on any other non-1 value. Note also that I've put parentheses around every "PIN" and "STATUS". I don't know whether MPASM macros are still direct text replacements or values... But putting parentheses around the parameters keeps them safe either way. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === (but open to offers) === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist