Andrew Warren wrote: > Yeah, but isn't #DEFINE a significantly better way to do that? Maybe specifically for flags, but I think Bob has a valid point in that CBLOCK is useful for creating an enumerated list of values. > If you do it with CBLOCK-assigned bit names, you must remember which > register holds each flag (I assume that the awkward "FLAG_" prefix > is there to aid your memory), but if you do it with #DEFINEs, you > don't have to remember anything: > > #DEFINE HAPPY FLAGS,0 > #DEFINE DOPEY FLAGS,1 > #DEFINE DOC FLAGS,2 > #DEFINE SLEEPY FLAGS,3 This makes accessing the flag with something like a BCF/BSF instruction easy, but what happens when you have more than 8 flags and you want to access the byte containing the flags in your code directly, or you need to know its bank? > > BSF HAPPY > BCF DOPEY > BTFSS DOC > BCF SLEEPY > > Hmm... I guess you could combine the two... Put all your flags in a > big CBLOCK list, then do: > > #DEFINE HAPPY FLAGS,FLAG_Happy > #DEFINE DOPEY FLAGS,FLAG_Dopey > #DEFINE DOC FLAGS,FLAG_Doc > #DEFINE SLEEPY FLAGS,FLAG_Sleepy > > It's hard to imagine a scenario in which that would be less trouble > than it was worth, though. That's why I created the /FLAG directive in my preprocessor. You write one line of code like: /FLAG happy and it automatically allocates the next bit in registers names GFL0 - GFLn and defines several symbols: flag_happy - String substition for use with BCF/BSF as above flag_happy_regn - 0-N number of the GFLn variable containing flag flag_happy_reg - Address of the GFLn variable containing flag flag_happy_bit - 0-7 bit number within GFLn variable The preprocessor is part of my PIC development environment available for free at http://www.embedinc.com/pic. You can click on the PREPIC link to see the documentation file for more details on the /FLAG directive and all the other things the preprocessor can do. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist