/* 
SystemKey.c : User can operate systemkey simple and easily.

Compiler: BC++ 3.1,                                                            
          Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum)
          MSC 6.0,                                                             
          MSVC 1.52.                                                           
                                                                               
Compile mode: large                                                            
                                                                               
Project: SystemKey.c                                                               
         ..\Lib\(8000.Lib, 8000E.lib)   
                                                                               
Hardware: 8000

Detail description:
                    UP button   ==> Increasing value.  
                    DOWN button ==> Decreasing Value.
                    Set  ==> Selecting 7-seg LED's postion. 
                    Mode ==> Selecting 7-seg LED's postion.

[15 Nov,2005] by Bill
*/

#include"..\..\LIB\8000a.h"

void main(void)
{ 
    int quit=0;
    int iTimes[4]={0};
    unsigned char oldKeyStatus=0xff;
    
    InitLib();
    Init5DigitLed();
    
    ClearSystemKey();
    
    while(!quit)
    {
        if(IsSystemKey())
        {   
            switch(GetSystemKey())
            {
               case SKEY_UP:
                       Print("UP KEY\n\r");
                       if(oldKeyStatus & SKEY_UP_DOWN)    
                       {                                  
                           iTimes[0]++;                      
                           Print("Keyin the Times of UP Key: %d\n\r",iTimes[0]);
                       }                                                                         
                       break;
               case SKEY_DOWN:
                       Print("DOWN KEY\n\r");
                       if(oldKeyStatus & SKEY_DOWN_DOWN)  
                       {                                  
                           iTimes[1]++;                      
                           Print("Keyin the Times of Down Key: %d\n\r",iTimes[1]);
                       }
                       break;
               case SKEY_SET:
                       Print("SET KEY\n\r");
                       if(oldKeyStatus & SKEY_SET_DOWN) 
                       {                                              
                            iTimes[2]++;  
                            Print("Keyin the Times of SET Key: %d\n\r",iTimes[2]);
                       }                                              
                       break;
               case SKEY_MODE:
                       Print("MODE KEY\n\r");
                       if(oldKeyStatus & SKEY_MODE_DOWN)
                       {                                
                            iTimes[3]++;                  
                            Print("Keyin the Times of SET Key: %d\n\r",iTimes[3]);
                       }                                
                       break;
            }
        }
        if(Kbhit())
        {
            if(Getch()=='q') quit=1;
        }
    }
}