WR Home      Topic Home      Chapter:  1  2 
<Previous Next>

Chapter 02

Blinking the LEDs in a more controlled way !

Page 9



The function inportb(port_address) returns the data on port. The data which was sent last time and which got latched on the port, can be retrived by this function.

The main use of this function is to get input data from a give port, but if a port is an "output-only" port, then this function returns the last value sent to the port, which was latched.

old_data = inportb(PP);

will give us the data sent last time.

Using this function can you modify the previous program, to add a third option for the user.
Give 3 options to the user for each LED

Now, develop a program, which asks eight questions:
  1. Do You want to switch ON LED# 1 ? Yes/No/Toggle
  2. Do You want to switch ON LED# 2 ? Yes/No/Toggle
  3. Do You want to switch ON LED# 3 ? Yes/No/Toggle
  4. ....
  5. ....
  6. ....
  7. ....
  8. Do You want to switch ON LED# 8 ? Yes/No/Toggle



By using the third option the user can change the state of the LED.
Here Toggle means invert the previous state of LED:
Switch it ON if it was OFF
Switch it OFF if it was ON
But the user might even don’t know whether it was ON or OFF

The solution is given on next page
HINT:
  1. Remember XOR ?
  2. AND is used to forcibly "zero-out" a bit
  3. OR  is used to forcibly "set" a bit
  4. XOR is used to forcibly "complement" a bit



WR Home      Topic Home      Chapter:  1  2 
<Previous Next>