You could also just use the built-in bitfield selection such as: // Alarm output #define ALARMENABLE port2.out.pin5 = 1 #define ALARMDISABLE port2.out.pin5 = 0
A little clearer than having a macro reference another macro to define a port (ie MakeBit()). I do like the SetBit, ResetBit, RoggleBit, and GetBit macros tho, thanks! -Mark -----Original Message----- From: mspgcc-users-boun...@lists.sourceforge.net [mailto:mspgcc-users-boun...@lists.sourceforge.net] On Behalf Of David Brown Sent: Tuesday, July 04, 2006 3:18 AM To: GCC for MSP430 - http://mspgcc.sf.net Subject: Re: [Mspgcc-users] bitfield code gen questions ----- Original Message ----- From: "Grant Edwards" <gra...@visi.com> To: <mspgcc-users@lists.sourceforge.net> Sent: Tuesday, July 04, 2006 3:52 AM Subject: Re: [Mspgcc-users] bitfield code gen questions > On 2006-07-04, David Smead <sm...@amplepower.net> wrote: > > > You can define all ports and pins in a single file and only need to > > change that file if you move pins around. I always put defines in > > io_pins.h and do the following > > > > > > #define ADC_ENABLE_BIT 0x08 > > #define ADC_PORT P3OUT > > > > #define ADC_ENABLE ( ADC_PORT |= ADC_ENABLE_BIT ) > > #define ADC_DISABLE ( ADC_PORT &= ~(ADC_ENABLE_BIT) ) > > True. For some reason I've always found that clumsy. For one > thing need a third definition for reading the bit: > > #define ADC_ENABLE (ADC_PORT & ADC_ENABLE_BIT) > > Except that conflicts with with the macro you use to set bit. > > > It always seemed so much cleaner to just do this: > > #define ADCEnable P3OUTb.b3 > However you do it, I agree entirely that you want to use a single name for your pins rather than explicitly using both a port address and bit reference in the main code. Personally, I have used a set of macros for many years. They sometimes need modification when I start with a new micro or a new compiler, but I have used the same API for over a decade with something like twenty different compilers and assemblers. #define ledGreen MakeBit(P3OUT, 3) #define inputSwitch MakeBit(P3IN, 5) void foo(void) { SetBit(ledGreen); OutputEnable(ledGreen); while (1) { if (GetBit(inputSwitch)) { ResetBit(ledGreen); }; }; } Generated code is optimal (at least, with optimisation enabled), and since it uses bitmasks at heart, you don't have to worry about the ordering of bits in bitfields. mvh., David // Put this in a common include file. #define pinOffset 0 // Offset from port address for pin inputs #define portOffset 1 // Offset from port address for port outputs #define dirOffset 2 // Offset from port address for pin directions #define _BitPort(add, bitM) add #define BitPort(bitAdd) _BitPort(bitAdd) #define _BitAdd(bitAdd) (unsigned int) &(bitAdd) #define BitAdd(bitAdd) (unsigned int) &BitPort(bitAdd) #define _BitMask(add, bitM) bitM #define BitMask(bitAdd) _BitMask(bitAdd) #define _BitPortDir(add, bitM) *(&add + dirOffset - portOffset) // NB! Only works for output ports #define OutputEnable(bitAdd) _BitPortDir(bitAdd) |= _BitMask(bitAdd) #define OutputDisable(bitAdd) _BitPortDir(bitAdd) &= ~_BitMask(bitAdd) #define MakeBit(port, bitNo) port, (1 << bitNo) #define SetBit(bitAdd) _BitPort(bitAdd) |= _BitMask(bitAdd) #define ResetBit(bitAdd) _BitPort(bitAdd) &= ~_BitMask(bitAdd) #define ToggleBit(bitAdd) _BitPort(bitAdd) ^= _BitMask(bitAdd) #define GetBit(bitAdd) (_BitPort(bitAdd) & _BitMask(bitAdd)) Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users