// experi6j.c

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

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

// include header with external prototypes
#include "extern6i.h"

enum
{
  WarningLED,
  MainMotor,
  LeftArmMotor
};

void main(void)
{
  int x;

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

  // make everthing an output
  set_up_ppi(Aout_CUout_Bout_CLout);

  printf("1193180/1000 = %f\n"
  ,1193180/1000);

  set_up_new_timer(1193180/1000);

  printf("frequency = %f\n",get_frequency());

  if(!ConfigureOutput(WarningLED,PA0))
      printf("Error setting up Warning LED = %d port select = %d\n"
	,WarningLED,PA0);

  if(!ConfigureOutput(MainMotor,PA1))
      printf("Error setting up Main Motor = %d port select = %d\n"
	,MainMotor,PA1);

  if(!ConfigureOutput(LeftArmMotor,PA2))
      printf("Error setting up Left Arm Motor = %d port select = %d\n"
	,LeftArmMotor,PA2);

  while(!kbhit())
  {
    if(!TurnOn(WarningLED))
      printf("Can't turn on the Warning LED\n");
    else printf("Turned on the Warning LED\n");
    wait(.1);

    if(!TurnOff(WarningLED))
      printf("Can't turn off the Warning LED\n");
    else printf("Turned off the Warning LED\n");
    wait(.1);

    if(!TurnOn(LeftArmMotor))
      printf("Can't turn on the Left Arm Motor\n");
    else printf("Turned on the Left Arm Motor\n");
    wait(.1);

    if(!TurnOff(LeftArmMotor))
      printf("Can't turn off the Left Arm Motor\n");
    else printf("Turned off the Left Arm Motor\n");
    wait(.1);

    if(!TurnOn(MainMotor))
      printf("Can't turn on the Main Motor\n");
    else printf("Turned on the Main Motor\n");
    wait(.1);

    if(!TurnOff(MainMotor))
      printf("Can't turn off the Main Motor\n");
    else printf("Turned off the Main Motor\n");
    wait(.1);
  }

  portaoff();

  // always free memory!
  FreeOutputControl();

  // always restore the old timer!
  restore_old_timer();
}

// end experi6j.c

