/*
DateTime.c : User can read and write the date & time of RTC.

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: DateTime.c                                                               
         ..\Lib\(8000.Lib, 8000E.lib)   
                                                                               
Hardware: 8000

Detail description:
                    * Press 'd' to set date;
                    't' to set time;
                    'q' to quit this program.

[15 Nov,2005] by Bill
----------------------------------------------------------------------
*/
#include <stdio.h>
#include"..\Lib\vh2k.h"

void main(void)
{ 
    int iyear,imonth,iday,ihour,imin,isec,iRET;
    int oyear,omonth,oday,ohour,omin,osec;
    char cTemp[10];
    int quit=0,type,ver;
    
    InitLib();

    Print("/*****************************************/");
    Print("\r\n/* Press 'd' to set date(month/day/year) */");
    Print("\r\n/* Press 't' to set time(hour/min/sec)   */\n");               
    Print("/*****************************************/");

    while(!quit)
    {
        if(Kbhit())
        {
            switch(Getch())
            {
                case 'q':
                    quit=1;
                    break;
                case 'd':
                    Print("\r\nPlease input Month:");
                    LineInput(cTemp,10);
                    sscanf(cTemp,"%d",&imonth);
                    
                    Print("Please input Day:");    
                    LineInput(cTemp,10);             
                    sscanf(cTemp,"%d",&iday);  
                    
                    Print("Please input Year:");
                    LineInput(cTemp,10);       
                    sscanf(cTemp,"%d",&iyear);  
                    SetDate(iyear,imonth,iday);
                    
                    break;
                case 't':
                    Print("\n\rPlease input Hour:");
                    LineInput(cTemp,10);
                    sscanf(cTemp,"%d",&ihour);
                    
                    Print("Please input Min:");    
                    LineInput(cTemp,10);             
                    sscanf(cTemp,"%d",&imin);  
                    
                    Print("Please input Sec:");
                    LineInput(cTemp,10);       
                    sscanf(cTemp,"%d",&isec);  
                    
                    SetTime(ihour,imin,isec);
                    break;
            }
            GetDate(&oyear,&omonth,&oday);
            Print("Date: %d/%d/%d \n\r",omonth,oday,oyear);
            
            GetTime(&ihour,&imin,&isec);
            Print("Time: %d:%d:%d\n\r",ihour,imin,isec);
            Print("Press 'q' to quit this program.\n\r");
        }
                       
    }
}
