//*********************************************************************
//*  HI-TECH C SOURCE CODE FOR TOGGLER MODULE
//*********************************************************************
void main()
{
 unsigned int x,y;
	
 TRIS = 0b00001000;	//GP3 input : all others output
 FOSC4 = 0;		//GP2 is an I/O pin
 CMCON  = 0b11110111;	//comparator off:pullups off:wakeup off
 OPTION = 0b11001111;	//prescaler assigned to WDT
 while(1)
 {
  ++GPIO;		//increment output pin set GP0, GP1, GP2	
  for(x=0;x<0xFFFF;++x)	//delay by incrementing y 65534 times
   ++y;			//increment y
 }//while(1)		//loop forever
}//main TOGGLER

//*********************************************************************
//*  HI-TECH C SOURCE CODE FOR 2-INPUT AND GATE MODULE 
//*********************************************************************
void main()
{
 TRIS = 0b11111011;	//GP2=output:all other GPIO=input
 FOSC4 = 0;		//GP2 is an I/O pin
 CMCON  = 0b11110111;	//comparator off:pullups off:wakeup off
 OPTION = 0b11001111;	//prescaler assigned to WDT
	
 while(1)
 {
  switch (GPIO & 0b00000011)
  {
   case 0b00000000:	//GP0 = LOW:GP1=LOW
    GP2 = 0;		//GP2 = LOW
    break;
   case 0b00000001:	//GP0 = HIGH:GP1=LOW
    GP2 = 0;		//GP2 = LOW
    break;
   case 0b00000010:	//GP0 = LOW:GP1=HIGH
    GP2 = 0;		//GP2 = LOW
    break;
   case 0b00000011:	//GP0 = HIGH:GP1=HIGH
    GP2 = 1;		//GP2 = HIGH
    break;
  }//switch
 }//while(1)
}//main

//*********************************************************************
//*  HI-TECH C SOURCE CODE FOR 2-INPUT AND GATE MODULE OPTIMIZED
//*********************************************************************
void main()
{
 TRIS = 0b11111011;	//GP2=output:all other GPIO=input
 FOSC4 = 0;		//GP2 is an I/O pin
 CMCON  = 0b11110111;	//comparator off:pullups off:wakeup off
 OPTION = 0b11001111;	//prescaler assigned to WDT
	
 while(1)
 {
  switch (GPIO & 0b00000011)
  {
   case 0b00000011:	//GP2=HIGH only if both GP0 and GP1 are HIGH
    GP2 = 1;
    break;
   default:
    GP2 = 0;
    break;
  }//switch
 }//while(1)
}//main

//*********************************************************************
//*  HI-TECH C SOURCE CODE FOR D FLIP-FLOP MODULE 
//*********************************************************************
void main()
{
 TRIS = 0b11111100;		//GP0=Q:GP1=NOT-Q:GP2=CLK:GP3=D
 FOSC4 = 0;
 CMCON  = 0b11110111;
 OPTION = 0b11001111;
				//power-up clear operation
 while(GP2);			//wait for CLK to go LOW 
 GP0 = 0;			//set Q
 GP1 = 1;			//clr Q

 while(1)
 {
  while(!GP2);			//wait for CLK to go HIGH
  switch (GPIO & 0b00001000)
  {
   case 0b00000000:		//D = 0
    GP0 = 0;			//clr Q
    GP1 = 1;			//set NOT-Q
    break;
   case 0b00001000:		//D = 1
    GP0 = 1;			//set Q
    GP1 = 0;			//clr NOT-Q
    break;
   }//switch
   while(GP2);			//wait for clock to go LOW
  }//while(1)			//loop forever
}//main
