Skip to content

Bit mathematics

Neomer edited this page Mar 2, 2017 · 4 revisions

Example:

#include <MemMath.h>

int main() {
    setLow(DDRB, 0);
    setHign(PORTB, 0);
    while (1) {
        if (bitIsLow(PINB, 0)) {
             waitLow(PINB, 0);
        }
    }
}

List of all functions:

  • setLow(A, N)

Function sets bit N (zero-based) in variable A to zero. Example:

A = 0x05;
setLow(A, 2); // A == 0x01;
  • setHigh(A, N) Function sets bit N (zero-based) in variable A to one. Example:
A = 0x01;
setHigh(A, 2); // A == 0x05;
  • bitIsHigh(A, N) Function returns TRUE if bit N (zero-based) in variable A is one. Example:
A = 0x05;
bitIsHigh(A, 2); // TRUE;
bitIsHigh(A, 1); // FALSE;
  • bitIsLow(A, N) Function returns TRUE if bit N (zero-based) in variable A is zero. Example:
A = 0x05;
bitIsLow(A, 2); // FALSE;
bitIsLow(A, 1); // TRUE;
  • waitHigh(A, N) Function suspend main program while bit N (zero-based) in variable A is zero. Example:
A = 0x05;
waitHigh(A, 1); // Infinite sleep
  • waitLow(A, N) Function suspend main program while bit N (zero-based) in variable A is one. Example:
A = 0x05;
waitLow(A, 2); // Infinite sleep
Clone this wiki locally