?? time.h
字號:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (c) 2007 by Qu chun lei watt@vip.163.com
*
* Filename: TIME.H
* Module: 0404C
* Language: ANSI C
* $Revision: 16 $
*
* DEFINITION
* This is a set of math functions that deal with time. The functions accept
* 4-digit time values and 4-digit time of day values. Time values are
* interpreted as hours-minutes and are valid if all digits are numeric and
* 9 or less, except the second-to-last digit must be 5 or less. Time of day
* values are valid if they conform to normally accepted clock values of
* 1:00 to 12:59 for a 12-hour clock or 00:00 to 23:59 for a 24-hour clock.
*
* CONSTRAINTS
* None
*
* ACCESS FUNCTIONS
* TimeValid Validates all numeric, < 99:59
* TimeOfDayValid All numeric, 00:00-23:59 or 01:00-12:59
* TimeCorrectFormat Correct the minutes if > 59
* TimeAdd Adds two time values
* TimeSubtract Subtracts two time values
* TimeOfDayAdd Add time to time of day
* TimeOfDaySubtract Subtract time from time of day
* TimeToBinary Convert time value to binary value
* TimeFromBinary Convert binary value to time value
* Time12ToBinary Convert time value to binary value for 12-hour
* clock configuration
* Time12FromBinary Convert binary value to time value
* clock configuration
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef TIME_H
#define TIME_H
#include "dac.h"
/*------------------*
| Module Options
*-----------------*/
#define TIME_OF_DAY_ADD TRUE
#define TIME_OF_DAY_SUBTRACT TRUE
#define TIME_ADD TRUE
#define TIME_SUBTRACT TRUE
#define TIME_CORRECT_FORMAT TRUE
#define TIME_VALID TRUE
#define TIME_OF_DAY_VALID TRUE
#define TIME_TO_BINARY TRUE
#define TIME_FROM_BINARY TRUE
#define TIME_12_TO_BINARY TRUE
#define TIME_12_FROM_BINARY TRUE
/*-------------*
| Constants
*-------------*/
#define TIME_ERROR 0xFFFF
/*---------*
| Types
*---------*/
typedef UINT8 TTimeOfDayFormat;
#define TIME_12_HOUR (TTimeOfDayFormat)0
#define TIME_24_HOUR (TTimeOfDayFormat)1
typedef UINT16 TTime;
typedef UINT16 TTimeOfDay;
/*-----------------------*
| Public Functions |
*-----------------------*/
/*---------------------------------------------------------------------------*
| TimeOfDayAdd result = t1 + t2
|
| Add a bcd time value to a time of day value and return a time of day value.
|
| On Entry: t1 is the first time value to add
| t2 is the second time value to add
| tt is the type (12/24)
|
| On Exit: Returns the 4-digit sum
*---------------------------------------------------------------------------*/
#if TIME_OF_DAY_ADD
TTimeOfDay TimeOfDayAdd(TTimeOfDay t1, TTime t2, TTimeOfDayFormat tt);
#endif
/*---------------------------------------------------------------------------*
| TimeOfDaySubtract result = t1 - t2
|
| Subtract time from a time of day value and return a time of day value
| result = t1 - t2
|
| On Entry: t1 is the first time value to subtract
| t2 is the second time value to subtract
| tt is the type (12/24)
|
| On Exit: Returns the 4-digit difference
*---------------------------------------------------------------------------*/
#if TIME_OF_DAY_SUBTRACT
TTimeOfDay TimeOfDaySubtract(TTimeOfDay t1, TTime t2, TTimeOfDayFormat tt);
#endif
/*---------------------------------------------------------------------------*
| TimeAdd result = t1 + t2
|
| Add two bcd time values and return a time value.
|
| On Entry: t1 is the first time value to add
| t2 is the second time value to add
|
| On Exit: Returns the 4-digit sum
*---------------------------------------------------------------------------*/
#if TIME_ADD
TTime TimeAdd(TTime t1, TTime t2);
#endif
/*---------------------------------------------------------------------------*
| TimeSubtract result = t1 - t2
|
| Subtract time from a time value and return a time value
| result = t1 - t2
|
| On Entry: t1 is the first time value to subtract
| t2 is the second time value to subtract
|
| On Exit: Returns the 4-digit difference
*---------------------------------------------------------------------------*/
#if TIME_SUBTRACT
TTime TimeSubtract(TTime t1, TTime t2);
#endif
/*---------------------------------------------------------------------------*
| TimeCorrectFormat
|
| Converts a time, stored as packed BCD, whose LSB may not be in modulo 60
| format, to modulo 60 format by adding to the MSB. Result overwrite the
| original time value.
|
| On Entry: Time value, stored as packed BCD
|
| On Exit: Corrected time value or TIME_ERROR
*---------------------------------------------------------------------------*/
#if TIME_CORRECT_FORMAT
TTime TimeCorrectFormat(TTime timeValue);
#endif
/*---------------------------------------------------------------------------*
| TimeValid
|
| Determines whether a time is numeric bcd, less than 99:59
|
| On Entry: Time value, stored as packed BCD
|
| On Exit: TRUE or FALSE
*---------------------------------------------------------------------------*/
#if TIME_VALID
BOOLEAN TimeValid(TTime timeValue);
#endif
/*---------------------------------------------------------------------------*
| TimeOfDayValid
|
| Determines whether a time of day is numeric bcd, less than
| 23:59 if 24 hour, between 01:00 and 12:59 if 12 hour
|
| On Entry: Time of day value, stored as packed BCD
| Time type (12/24)
|
| On Exit: TRUE or FALSE
*---------------------------------------------------------------------------*/
#if TIME_OF_DAY_VALID
BOOLEAN TimeOfDayValid(TTimeOfDay timeValue, TTimeOfDayFormat tt);
#endif
/*---------------------------------------------------------------------------*
| TimeToBinary
|
| Convert an hr-min (or min-sec) time value to a binary value
|
| On Entry: Time: 16-bit BCD hr-min (or min-sec)
|
| On Exit: Time: 16-bit total minutes (or seconds)
*---------------------------------------------------------------------------*/
#if TIME_TO_BINARY
UINT16 TimeToBinary(TTime bcdTime);
#endif
/*---------------------------------------------------------------------------*
| TimeFromBinary
|
| Convert an hr-min (or min-sec) time value to a binary value
|
| On Entry: Time: 16-bit total minutes (or seconds)
|
| On Exit: Time: 16-bit BCD hr-min (or min-sec)
*---------------------------------------------------------------------------*/
#if TIME_FROM_BINARY
TTime TimeFromBinary(UINT16 binaryTime);
#endif
/*---------------------------------------------------------------------------*
| Time12ToBinary
|
| Convert an hr-min (or min-sec) time value to a binary value
|
| On Entry: Time: 16-bit BCD hr-min (or min-sec)
|
| On Exit: Time: 16-bit total minutes (or seconds)
*---------------------------------------------------------------------------*/
#if TIME_12_TO_BINARY
UINT16 Time12ToBinary(TTime bcdTime);
#endif
/*---------------------------------------------------------------------------*
| Time12FromBinary
|
| Convert an hr-min (or min-sec) time value to a binary value
|
| On Entry: Time: 16-bit total minutes (or seconds)
|
| On Exit: Time: 16-bit BCD hr-min (or min-sec)
*---------------------------------------------------------------------------*/
#if TIME_12_FROM_BINARY
TTime Time12FromBinary(UINT16 binaryTime);
#endif
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -