Datasheet

Chapter 2: EEPROM Tricks and Program Tips ยท Page 49
temp = temp + 1
WRITE EepromCounter, temp
temp = temp - 1
IF temp = 0 THEN
DEBUG "Since download, you have", CR,
"pressed Reset ", DEC temp,
" times.", CR
ELSE
DEBUG CRSRX, 11, "...", DEC temp,
" times.", CR
ENDIF
END
Your Turn - Distinguishing Odd from Even
You can determine whether the Reset button has been pressed/released an odd or even
number of times by examining the
temp variable as a binary number. When a variable
counts up in binary, the rightmost binary bit (1 or 0) changes every time. Here is an
example:
Decimal Binary
0 %0000
1 %0001
2 %0010
3 %0011
4 %0100
5 %0101
6 %0110
7 %0111
Aside from the fact that it changes every time, notice that the rightmost bit is always 1 for
odd numbers and 0 for even numbers. If you want your program to take action based on
whether a value is odd or even, you'll need to access this rightmost binary bit and use it in
IF...THEN statements.
PBASIC has the
.BIT (pronounced "dot-bit") operator for accessing the individual binary
values in a variable. The rightmost binary value, is accessed with
.BIT0. The second