/* 
DEMO92.c: Shows how to use the StopWatch function on channel 0 to switch the LED ON or OFF.

Compiler: BC++ 3.1, 
          Turbo C++ 1.01(3.01) (free from http://cc.codegear.com/free/cpp)
          MSC 6.0,
          MSVC 1.52.

Compile mode: Large

Project: DEMO92.c
         ..\..\Lib\(8000e.Lib, 7188el.Lib or 7186el.Lib)

Hardware: i-7188/uPAC-7186/i-8000

Note: Function used:
      TimerOpen --> begin to use uPAC-7186 timer
      TimerClose --> stop to use timer
      StopWatchStart  --> start to count time interval
      StopWatchReadValue -->to decide if time is up.
      Use StopWatch to count 500ms(0.5s) to turn LED ON or OFF.

[Oct 30, 2008] by Liam
*/

#include <stdio.h>
#include "..\..\lib\7186e.h"

void main(void)
{
    int LedMode=0;
    unsigned long value;
    int quit=0;
    
    InitLib();
    
    Print("Test StopWatch ...\r\n");
    Print("Now LED must flash once every second\r\n");
    Print("\r\nPress 'q' to quit\r\n");
    
    TimerOpen();
    LedOff();
    StopWatchStart(0);
    while(!quit)
    {
        if(Kbhit())
        {
            switch(Getch())
            {
                case 'q':
                    quit=1;
                    break;
            }
        }
        
        StopWatchReadValue(0, &value);
        if(value>=500)
        {
            StopWatchStart(0);
            if(LedMode)
            {
                LedMode=0;
                LedOff();
            }
            else
            {
                LedMode=1;
                LedOn();
            }
        }
    }
    
    TimerClose();
    LedOn();
}

