/******************************************************************\

   IOEMUX_N.C
   
   BL11xx/Little Giant with IOE-MUX or IOE-A/D 

   Uses the following functions:
        
   int exp_init_n (int node, int ppia, int ppib, int ppicu, int ppicl, int def);
   int mux_ch_n (int node, int chan, int def);
 
   This example shows the use of the four channel multiplexer on the 
   IOE-MUX and IOE-A/D.  The four channels are changed and then 
   sampled by channel 0 of the BL11xx/Little Giants A/D in unipolar mode. The
   output is displayed in the STDIO window.  If you have the DAC installed
   you can move the output between the different mux channels and observe
   the output.
   
   After displaying the mux channels the PPI ports B and C are read and
   displayed as well as the RDTTL (not available in the IOE-MUX.)
   
\******************************************************************/
struct node_addr na;

main()
{
   int j, k;
   long l;

  /* port A must be output, all others can be I/O, set node 3 as default */
   exp_init_n (3, 0, -1, -1, -1, 1);
   get_def_na (&na);                /* get default addresses */

/*          if you have a DAC you can use the output in this test 
   k = 200;
   wdac (k);
*/
   while(1)
   {
   	hitwd();
/*
      k += 10;
      wdac (k);
*/
      for (j = 0; j < 4; ++j)
      {
      	hitwd();
         mux_ch_n (-1, j, 0);          /* set to channel j, using def addr */
         for (l = 200L; --l;);          /* wait for settle */

         /* change the ad_rd () call to match the converter on your system */
         printf ("Mux Channel %d = %x\n", j, (ad_rd (8) >> 2));
      }
      for (l = 20000L;--l;) hitwd();                /* pause */

      printf ("PPIDB inputs = %x\n", inport(na.ppidb));
      printf ("PPIDC inputs = %x\n", inport(na.ppidc));
      printf ("RDTTL inputs = %x\n\n", inport(na.rdttl)); /* TTL inputs */
      for (l = 20000L;--l;) hitwd();                /* pause */
   }
}

/******************************************* End of IOEMUX_N.C **********/











