Home>

I have a question about part of the program below. This part means that lcd_vram2lcd () is executed once every 50 msec x 16 (800 msec), but I don't understand why the following writing makes it once in 16 times. I understand that it is executed when the value of the lower 4 bits is 0, that is, when it is divisible by 16, by using the logical product, but why does it execute once in 16 times? I don't know, so could you please explain it?

if ((g50msecCounter&0xf) == 0)
 {
 lcd_vram2lcd ();
 }
c
  • Answer # 1

    I understand it in the comment of dodox86. Thank you very much.

  • Answer # 2

    Bit AND compares bits at the same position on the left and right sides of the operator,
    Set to "1" only when both bits are "1".

    I will write the flow when adding g50msecCounter below.

    0000000000000000 = 0<--- The value of g50msecCounter.
    0000000000001111 = 15
    ----------------
    0000000000000000 = 00->(Condition match)
    0000000000000001 = 1 Add 1 to the value of g50msecCounter
    0000000000001111 = 15
    ----------------
    0000000000000001 = 01->Mismatch
    0000000000000010 = 2
    0000000000001111 = 15
    ----------------
    0000000000000010 = 2->mismatch
        (Omitted)
    0000000000001110 = 14
    0000000000001111 = 15
    ----------------
    0000000000001110 = 14->mismatch
    0000000000001111 = 15
    0000000000001111 = 15
    ----------------
    0000000000001111 = 15->mismatch
    0000000000010000 = 16
    0000000000001111 = 15
    ----------------
    0000000000000000 = 0->(conditional match)
    0000000000010001 = 17
    0000000000001111 = 15
    ----------------
    0000000000000001 = 1->mismatch
        (Omitted)
    0000000000100000 = 32
    0000000000001111 = 15
    ----------------
    0000000000000000 = 0->(conditional match)