S215  09 0911    rev. 10-7 

II11-03 The JK Flip-Flop
20 points

OEES 215

Back to Main Page
 
The example programs below are 2 input AND gate programs.  Nested if statements used in the first AND gate program can be replaced by the && (logical And) operator.

We'll be using the && operator when we modify the toggle flip-flop program to create a program that acts like a JK flip-flop.


 EXAMPLE --  AND GATE
if (SW0 == 1)
    if  (SW1 == 1)
         LED0 = 1;
    else
         LED0 = 0;
else
 LED0 = 0;

This can be replaced with:

if((SW0 == 1) &&  (SW1 == 1))    //if SWO and SW1 are equal to 1,
    LED0 = 1;                    //turn LED0 on,
else                             //otherwise
    LED0 = 0;                    //turn LED0 off.

In this example, the use of the && (logical AND) operator allows us to use just a single if statement instead of two if statements with nesting.


Modify the examples and run a new program
1. Edit the existing toggle flip flop program.
2. Create an if statement  that replaces if (le == 1)  with if (PBdl () == 1).
3. Remove the le character (char) variable. Add  j and k char variables.
4. Create an if statement for each of the 4 possible input combination for the JK Flip-Flop (under the if (PBdl == 1 statement). The if statement for the toggle condition has already been written.
5  Don't use nested if statements for each of the 4 possible input combinations. Use the && (logical AND) operator instead.