//******************************************************************************
// IH17-12 Toggle Flip-Flop				S215  09 0809
// *****************************************************************************
#include "s215-header8.h" 

#pragma code
void main (void)
{
unsigned char le, q=0;
InitPorts();


//----------------------------------
while (1==1)
{
//||||||||||||||||||| Main Loop |||||||||||||||||||||||||||

le = PBdl();  //When PB is pressed it creates a leading edge
              //This line calls the PBdl function and returns 
              //status of the pushbutton to the le variable.
              
LED1 = le;    //Assigns value of "le" to LED1. If the pushbutton 
              //has been pressed, a "1" in "le" will cause the
              //LED to turn on. The pushbutton is the clock for
              //for the positive edge triggered FF.

if (le == 1)  //If a leading edge is detected toggle the output q.
              //Each time the PB is pressed, q will toggle.  
{ 
    if (q == 0) q = 1;  //Toggle output q
    else q = 0;
}


LED0 = q;
//|||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||
}
}