/*****************************************************************
   
      PIODEMO.C
      
      BL11xx/Little Giant, Tiny Giant
       
      PIO interrupt demonstration, PIO interrupts are edge sensitive,
      not level sensitive. Interrupt is generated when PIO line is pulled
      low.

      BL11xx/Little Giant:
         Insert and remove jumper J10 bit 8 port B (33-34) 

      Tiny Giant:
         Insert and remove jumper J9 bit 8 port B (pins 3-4)

************************************************************************/

// If on Tiny Giant
//#define USETG 1


shared int jjj;         /* used by interrupt routine and main */
int kkk;

main()
{

   jjj = kkk = 0;

#ifndef USETG                 /* Tiny Giant does not have KIO
   outport(KIOC,0x9e);        /* set KIO interrupt daisy chain to PIO 1st */
#endif

   outport(PIOCB, 0xcf);       /* parallel port B control register mode 3 */
   outport(PIOCB, 0x80);       /* bit 8 is input, other bits output */
   outport(PIOCB, PIOB_VEC);   /* set vector to PIOB */
 
   /* interrupt control byte, enable INT, OR with mask, INT on low, 
      mask to follow*/
   outport(PIOCB,0x97);        
   outport(PIOCB,0x7f);        /* mask that follows */

   while (1)
   {
      if (jjj != kkk)         /* test for interrupt */ 
      {
         printf( "interrupt"); 
         jjj=kkk;
      }
      hitwd();
   }
}

#INT_VEC PIOB_VEC myint

interrupt reti myint()
{
   jjj++;                     /* change jjj */
}

/*************************************************End of PIODEMO.C *****/
