2.13. Applications

2.3. Logic tables

1. Write the truth table for NOR, NAND. Are they equivalent to any of the previously presented truth tables? Optional: draw their Venn diagrams. 2. Prove De Morgan’s laws:

a. (¬ (p ∧ q)) ↔ ((¬p) ∨ (¬q))
b. (¬ (p ∨ q)) ↔ ((¬p) ∧ (¬q))

3. Demonstrate the logical equivalence: (p → q) = (¬p ∨ q).

2.4. Bitwise operators

1. Write a C function show_bits (declared as below) that prints out the bits of the binary number. Use bit manipulation techniques.

void show_bits(unsigned char n)
{
  // Write your code here
}

int main(int argc, char* argv[])
{
  unsigned char n = 0b11001110;

  printf("\n\nThe number given is: ");
  show_bits(n);

  return 0;
}

2. Write a function that outputs the value of a binary number affected by the negation operator (”!”) and, secondly, the value modified by the complement operator (”~”). Use the show_bits function defined at exercise 1.

3. Write a function that exemplifies the use of the union, intersection and substraction constructs. Use the show_bits function defined at exercise 1.

4. Write a function that exemplifies the use of the set bit, clear bit and toggle bit constructs. Use the show_bits function defined at exercise 1.

5. Write a C function that takes a positive integer “x” as a parameter. Return “1” if x is a power of 2 and “0” otherwise.

a. Do this exercise in two ways: with and without bit manipulation. 
b. What do you observe regarding the complexity (number of operations executed) of each approach? Which one is faster?

2.5. Atmel Studio

1. Write a program that lights up a LED on the 3PI.

2.11. Timers

1. Use timer 1 to toggle the state of a led on the 3PI each 0.2 seconds.

Solutions

roboticsisfun/chapter2/ch2_13_applications.txt · Last modified: 2012/11/09 14:25 by silvia.stegaru