// experi5b.c

#include <conio.h>
#include <stdio.h>
#include <bios.h>

// include header with constants
#include "const5a.h"

// include header with external declarations
#include "extern5a.h"

void main(void)
{
  long on,off=5000L,r,c;

  get_port(); // get the port number and establish register locations

  // make A an output and B and C inputs
  set_up_ppi(Aout_CUin_Bin_CLin); // uses the new enumeration

  while(1) // stay in loop forever
  { 
    for(on=1000L; on<=10000L; on+=100L)
    {
      // "keyboard hit" is a function that checks
      // to see if a key has been pressed.
      if(kbhit())
        break;// A key was pressed -- break out of the loop
      printf("on=%5ld off=%5ld total = %12.6f -- on = %9.6f percent of total\n"
      ,on,off,(double)on+(double)off,100.0*((double)on/((double)on+(double)off)));
      motor(on, off);
    }
    if(on<10000L)
      break;// A key was pressed -- break out of the loop

    for(on=10000L; on>1000L; on-=100L)
    {
      // "keyboard hit" is a function that checks
      // to see if a key has been pressed.
      if(kbhit())
        break;// A key was pressed -- break out of the loop
      printf("on=%5ld off=%5ld total = %12.6f -- on = %9.6f percent of total\n"
      ,on,off,(double)on+(double)off,100.0*((double)on/((double)on+(double)off)));
      motor(on, off);
    }
    if(on>1000L)
      break;// A key was pressed -- break out of the loop

  } // end while(1)

  portaoff();

} // end experi5b.c

