供参考
typedef unsigned char uchar,byte;
enum REAL_TIME_TYPE
{
YEAR = 9,
MONTH = 8,
DAY = 7,
HOUR = 4,
MINUTE = 2,
SECOND = 0,
WEEK = 6
};
typedef struct
{
uchar cYear;
uchar cMon;
uchar cDay;
uchar cHour;
uchar cMin;
uchar cSec;
uchar cWeek;
}REALTIME;
SetRealTime(REALTIME * pRealTime)
{
PBYTE[0x0b] |=0x80;
PBYTE[0x00] =pRealTime-> cSec;
PBYTE[0x02] =pRealTime-> cMin;
PBYTE[0x04] =pRealTime-> cHour;
PBYTE[0x07] =pRealTime-> cDay;
PBYTE[0x08] =pRealTime-> cMon;
PBYTE[0x09] =pRealTime-> cYear;
PBYTE[0x06] =pRealTime-> cWeek;
PBYTE[0x0b] &=0x7f;
}
Init12887()
{
PBYTE[0x0a] =0x2f;
PBYTE[0x0b] =0x06;
// reg b: SET,PIE,AIE,VIE,SQWE,DM,24/12,DSE
}
uchar GetTime(uchar cID)
{
// cID = 9 will get year, 8 will get month...
uchar val;
uint n = 65; // timeout counter, avoid die loop
// if in UIP state,wait
do{
val = PBYTE[0x0b];
}while (--n && ( val & 0x80 ));
val = PBYTE[cID];
return val;
}
发表时间:2005年12月12日10:10:35