r/microcontrollers • • Jun 13 '14

Bit set, reset, toggle and masking in Microcontrollers

http://learningmsp430.wordpress.com/2014/06/13/bit-set-reset-toggle-and-masking-in-microcontrollers/
0 Upvotes

3 comments sorted by

1

u/pzl Jun 13 '14

there is a blurry picture of notes. In an article.

write any of the text portion of those notes in the actual article. register bank could have been done in HTML, at the easiest probably using table.

for the mask figure below that, you should probably create that as an image (photoshop/gimp/paint, or would be nice as a vector->png: Illustrator/Inkscape/etc)


and this is clearly aimed at very beginners, if the concept being explained is bit masking. It's not actually explaining very well for that audience.

x AND 0 = 0

So whatever be the value of x if you AND it with 0 the result is 0.

there are really only two options, wouldn't take much effort to enumerate to make the point very clear.

Truth table if you really want, but if you're explaining simple stuff, you might as well make the extra effort to explain why x&0 will always clear the bit.

1

u/msminhas93 Jun 21 '14

okay I'll try to improve the article by elaborating more thank you for your input

1

u/bradn Jun 13 '14 edited Jun 13 '14

They're right - bit setting, clearing, toggling is such a big deal that I had to make a whole class of instructions to do that when I wrote a virtual machine for PIC18.

It was necessary for the purpose of maintaining their atomic operation - otherwise doing a bit mask would require reading a memory/peripheral register, modifying it, and writing it back (2 or 3 virtual instructions), and in the meantime something else could modify it and screw everything up, especially when dealing with I/O pins.

Side note, if there's any interest in the ICL interpreter code & assembly macros, I could release those. The project I wanted to release them with isn't getting finished, but the actual interpreter is in good shape. The assembly macros work but are not very fun to use in picasm because there is no line number reporting possible for errors.

The useful attributes for this interpreter are: Execute from RAM or flash (or with alteration, external memory), constant execution time (68 cycles), memory write protection on 256 byte page size, multiple threads, 16 bit operations (including stack).