Using an AND mask to ensure a binary number stays within designated bounds. I want to use an 8-bit microcontroller register to produce numbers between 0 and F hexadecimal (not 0 and FF).

By Julian

Youtuber, shed dweller, solar charge controller aficionado

15 thoughts on “Neopixel led programming: using an and mask”
  1. Avataaar/Circle Created with python_avatars Dream Hound says:

    I've been trying to find videos to learn more about this subject and you seem the only person to explain it so level headed, and easy. Thank you so much for the tutorial and lesson.

  2. Avataaar/Circle Created with python_avatars Alan Powell says:

    I haven't seen assembler since my BBC Micro days.

  3. Avataaar/Circle Created with python_avatars Alan Powell says:

    Julian, OK, you've got me. Please explain the linear feedback shift register. Are you going to add these PIC videos as a sort of primer to your eventual PIC programming series?

  4. Avataaar/Circle Created with python_avatars yagoa says:

    Very clear, wonderful to watch

  5. Avataaar/Circle Created with python_avatars kfishy says:

    Ooh more PIC videos! Keep 'em coming 🙂

  6. Avataaar/Circle Created with python_avatars Edward Jones says:

    Really enjoyable video, Julian. I've ordered that same dev board from eBay and a pixel ring. I've done a lot of assemble coding on the C64 and Dos PC days. This is a good teaching format, as the device has such good visual feedback.

    Keep 'em Coming!

  7. Avataaar/Circle Created with python_avatars beargun42 says:

    Post-it overflows!

    Happens to me too, all the time.

  8. Avataaar/Circle Created with python_avatars オーエン·ピーターPeter says:

    I'm not famliar with PIC but couldn't you and against an immediate value rather that shifting an immediate value into a register and anding against said register?

  9. Avataaar/Circle Created with python_avatars Garth Howe says:

    Wow… now that was an impressive, and instructional video Julian. No wonder we didn't hear from you for a week. Thank you VERY much!

  10. Avataaar/Circle Created with python_avatars James Jinks says:

    Great video! I love learning about this lower level programming.

  11. Avataaar/Circle Created with python_avatars Raymond Heath says:

    Using a real life example made it easier for me to understand

  12. Avataaar/Circle Created with python_avatars Klaus Petersen says:

    Julian – perhaps its not completely your sort of thing I was wondering if you would do a video about triacs controlling high power (200 watts) load. Seems there are not many quality videos about the subject.

  13. Avataaar/Circle Created with python_avatars bwack says:

    I enjoyd this video. Well presented. Regarding the lfsr, if you want next outcome to be less dependent on the previous (hence the random pattern on the ring seems to run a little bit down on each side), you can add a second lfsr and xor them together. Note1: The registers must be of different sizes, for example, a 16bit lfsr running and its lowest 8 bits are xored with your 8 bit lfsr. The statisticall independency between the outcomes are improved. Note: Only a subset of all tap-masks give the longest running sequence for any lfsr. By tapmask i mean the number you xor in at the beginning after rotating. In my video I started out with a fibonacci/external type lfsr (also called simple lfsr) because I didn't understand lfsr yet, so you went on with the computational efficient type (Galois/internal). The theory indicates that the lfsr is rotated right, but in pic assembly I found it easier to rotate left because then you can use carry as the feedback 🙂 (I also had to invert the tap-mask ofcourse.)

  14. Avataaar/Circle Created with python_avatars Nikolay Pelov says:

    Yes, do a video on pseudo random.
    I want to point out another neat trick in assembly language (which I don't use anymore). The destination flag of some instructions can be very helpful. Let's say you use led_position in an interrupt and you don't want the interrupt to see a number >15. You could do all the work in WREG and first instruction does both decrement and copy f -> W:
    decf led_position, w
    andlw 0x0F
    movwf led_position
    Of course you shouldn't change led_position in the interrupt in this case.

  15. Avataaar/Circle Created with python_avatars Aman Mittal says:

    Sry for my grammer…but i would say a simple clue is enough for the clever… LOL.. 😅😅

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.