-----Original Message----- >From: Josh Koffman >Sent: Mar 12, 2015 2:56 PM >To: "Microcontroller discussion list - Public." >Subject: Re: [PIC] Setting Multiple Bits in C > >On Thu, Mar 12, 2015 at 3:17 PM, Charles Craft w= rote: >> If you have the space, why not put all eight bits in the table? > >There are actually only 2 bits that I'm worried about. In this >particular case, they are the two LSB of the PWM value for the CCP/PWM >peripheral. The MSB 8 bits are easy to load as they are a full byte, >the LSB go in a control register that has other functions. So I can't >just overwrite that and expect everything to work. > >> Would if be easier to read if you combine your mask and value into one v= ariable >> then AND that with "target"? > >That wold be cool, but because the starting state of the target >register isn't guaranteed, won't I still end up in a situation where I >need to mask and combine? > >> or define "target" with bit fields and set the field equal to value? >> http://en.wikipedia.org/wiki/Bit_field > >This could be interesting. I hadn't thought about defining a multi-bit >field and just writing to it. If I did the definitions correctly, >would: > >TARGETbits.PWMLSB =3D arrayofvalues[index]; > >work, or would I still need to shift to align the array value with the >bits I'm actually loading? My guess is that I shouldn't have to shift, >but I am unsure. I need to rethink through the first two items. w.r.t. bit fields, K&R says: "Almost everything about fields is implementation-dependent." You'll need to code up a sample and see what the compiler generates under t= he covers. > >Thanks! > >Josh >--=20 >A common mistake that people make when trying to design something >completely foolproof is to underestimate the ingenuity of complete >fools. > -Douglas Adams >--=20 >http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >View/change your membership options at >http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .