/* Program IO_1.C
**
** Flashes LED on P2.0 at rate determined by input on P2.7.
** If P2.7 is at one, LED flashes at 5 pps.  If at zero, flashes
** every two seconds.
**
** A '.' is printed each time through the loop to prevent Flashlite
** from not responding to ctrl-c.
**
** Illustrates how to read from and write to a port.  This opens up the
** ability to interface with such devices as a TLC2543 11-channel A/D and
** I2C devices.
**
** copyright, Peter H. Anderson, Baltimore, MD, Sept, '00
*/

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

#define SEG 0xf000
#define P2_OFFSET 0xff10

#define P2 0
#define PM2 1
#define PMC2 2

void main(void)
{
   int n, delay_time;
   unsigned char far *p2;

   p2 = MK_FP(SEG, P2_OFFSET);
   *(p2+PMC2) = 0x00; 	/* not special purpose */
   *(p2+PM2) = 0x80;		/* most sig bit is an input */

   while(1)
   {
      printf(".");			/* status and to prevent lockout */
      if (*(p2) & 0x80)	/* if most sig bit a one */
      {
          delay_time = 100;	/* flash quickly */
      }
      else
      {
         delay_time = 1000;
      }
      *p2 = 0x01;		/* flash the LED on least sig bit of p2 */
      delay(delay_time);
      *p2 = 0x00;
      delay(delay_time);
   }
}