?? time.c
字號:
//===============================================================
// File name : Time.C
//===============================================================
//---------------------------------------------------------------
// Include file and variable
//---------------------------------------------------------------
#include <hms800.h> //
#include "MC80C7208.h" // SFR define
#define USER_EXTERN extern // extern variable define
#include "Variable.h" //
//---------------------------------------------------------------
// external prototype function
//---------------------------------------------------------------
//===============================================================
// task : time wait service
// input : delay_count
//===============================================================
//---------------------------------------------------------------
// N(4~250) mSec interrupt down counter delay
//---------------------------------------------------------------
void Wait_msec(uchar Value)
{
rTimer_4ms[TIME_Wait] = (ushort)Value/4; // N = V ms / 4 ms
while(rTimer_4ms[TIME_Wait]) // down counter in 4 msec interrupt
asm(" nop ");
}
//---------------------------------------------------------------
// N usec delay by 4MHz crystal
//
// (caution!) It is available over 48us delay
//---------------------------------------------------------------
void Wait_uSec(ushort Value)
{
wDly_count = Value-30; // 30 us
asm("
lsr _wDly_count+1 ; 4 1/8
ror _wDly_count ; 4
lsr _wDly_count+1 ; 4
ror _wDly_count ; 4
lsr _wDly_count+1 ; 4
ror _wDly_count ; 4
Rpt_dly:
decw _wDly_count ; 6
nop ; 2
nop ; 2
nop ; 2
bne Rpt_dly ; 4 500ns x 16 = 8us
");
}
//===============================================================
// task : Time clock update
//===============================================================
//---------------------------------------------------------------
// task : Timer0 4mSec time interval interrupt
// input : 4msec cycle
// output: 4mSec x N
//---------------------------------------------------------------
void T0_Int_Handler(void)
{
uchar m;
for(m=0;m<5;m++) //
{ //
if(rTimer_4ms[m]) //
rTimer_4ms[m]--; //
} //
if (!(rTimer_4ms[TIME_Sec])) //
{ rTimer_4ms[TIME_Sec] = 125; // 500ms
if (f_Flicker) //
{ f_Flicker = OFF; //
p_Yellow = OFF; //
}
else //
{ f_Flicker = ON; //
p_Yellow = ON; //
}
f_OnLcd = ON; // LCD Display
} //
}
//===============================================================
// task : Real Time Clock and Calendar Update
//===============================================================
//---------------------------------------------------------------
// 辣斥 棺 1巋1老狼 夸老 (index = 2000 ~ 2099)
//---------------------------------------------------------------
//uchar Year_table[] __attribute__((section (".text"))) =
CODE uchar Year_table[]=
{
0x86, // 2000 辣崔 1巋1老(配夸老)
0x01, //
0x02, //
0x03, //
0x84, // 2004. 辣崔 1巋1老(格夸老)
0x06, //
0x00, // 2006 1巋1老(配夸老)
0x01, // 2007
0x82, // 2008
0x04, //
0x05, //
0x06, //
0x80, // 2012
0x02, //
0x03, //
0x04, //
0x85, // 2016
0x00, //
0x01, //
0x02, //
0x83, // 2020
0x05, //
0x06, //
0x00, //
0x81, // 2024
0x03, //
0x04, //
0x05, //
0x86, // 2028
0x01, //
0x02, //
0x03, //
0x84, // 2032
0x06, //
0x00, //
0x01, //
0x82, // 2036
0x04, //
0x05, //
0x06, //
0x80, // 2040
0x02, //
0x03, //
0x04, //
0x85, // 2044
0x00, //
0x01, //
0x02, //
0x83, // 2048
0x05, //
0x06, //
0x00, //
0x81, // 2052
0x03, //
0x04, //
0x05, //
0x86, // 2056
0x01, //
0x02, //
0x03, //
0x84, // 2060
0x06, //
0x00, //
0x01, //
0x82, // 2064
0x04, //
0x05, //
0x06, //
0x80, // 2068
0x02, //
0x03, //
0x04, //
0x85, // 2072
0x00, //
0x01, //
0x02, //
0x83, // 2076
0x05, //
0x06, //
0x00, //
0x81, // 2080
0x03, //
0x04, //
0x05, //
0x86, // 2084
0x01, //
0x02, //
0x03, //
0x84, // 2086
0x06, //
0x00, //
0x01, //
0x82, // 2090
0x04, //
0x05, //
0x06, //
0x80, // 2094
0x02, //
0x03, //
0x04, //
0x85, // 2098
0x00 // 2099
};
//--------------------------------------------------------------
CODE ushort Month_Day_table[] =
{ // 撈傈巋 鱉瘤 朝樓薦 欽拌
0, // -
0, // 1巋 31
31, // 2巋 28
59, // 3巋 31
90, // 4巋 30
120, // 5巋 31
151, // 6巋 30
181, // 7巋 31
212, // 8巋 31
243, // 9巋 30
273, // 10巋 31
304, // 11巋 30
334, // 12巋 31
365 // -
};
//---------------------------------------------------------------
// task : Search week day
// input : rYear, rMonth, rDate, Month_Day_table, Year_table
// output: rWeek
//---------------------------------------------------------------
void Check_Week_Day(void)
{
i = Year_table[rYear]; // 2000~2099
j = Month_Day_table[rMonth]; // 撈傈巋 鱉瘤 sum of date
if(!(rYear & 0x03)) // 4斥付促 辣斥牢啊?
{ if (rMonth > 2) // 2巋 29老牢啊?
j++; // 366老澇聰促.
} //
j += (ushort)(i & 0x07); // 1巋 1老狼 夸老闌 歹茄促.
j += (ushort)rDate; // 秦寸巋狼 朝樓甫 歹茄促.
rWeek = j % 7; // 醚 老薦 / 7 = 唱贛瘤啊 公郊 夸老撈促.
}
//---------------------------------------------------------------
// maximum day ( index[month] = 1 ~ 12 )
//---------------------------------------------------------------
CODE uchar Month_table[] =
{
0,
31, // 1巋
28, // 2
31, // 3
30, // 4
31, // 5
30, // 6
31, // 7
31, // 8
30, // 9
31, // 10
30, // 11
31 // 12 standard
};
uchar Check_Last_Date(void)
{
i = Month_table[rMonth]; //
if(!(rYear & 0x03)) // 概 4斥付促 辣斥牢啊?
{ if (rMonth == 2) // 辣斥 2巋崔籃 29老澇聰促 !!!
i = 29; //
}
if(rDate > i) return 1; // last day + 1
else return 0; //
}
//---------------------------------------------------------------
// task : Calculate Clock display data
// input : rHour, rMinute
// output:
//---------------------------------------------------------------
void Clock_Hex_Decimal(void)
{
/*
if (f_AmPm) // PM11:59 or 23:59
{ if(rHour > 11) //
{ f_AM = OFF; //
i = rHour - 12; //PM12 ~ PM11
} //
else f_AM = ON; //AM12 ~ AM11
if (i == 0) i = 12; // 00 --> 12
if (i > 9) //
{ rLcd_Buf[0] = 1; //
rLcd_Buf[1] = i - 10; //
}
else //
{ rLcd_Buf[0] = SPACE; //
rLcd_Buf[1] = i; //
} //
}
else
*/
// {
i = rHour; ;
rLcd_Buf[0] = i/10; // 00 ~ 23
rLcd_Buf[1] = i%10; //
// }
rLcd_Buf[2] = rMinute/10; // 00 ~ 59
rLcd_Buf[3] = rMinute%10; //
}
//---------------------------------------------------------------
// task : Calculate Alram display data
// input : rAlram_Hour, rAlram_Minute
// output:
//---------------------------------------------------------------
void Alram_Hex_Decimal(void)
{
i = rAlram_Hour;
rLcd_Buf[0] = i/10; // 00 ~ 23
rLcd_Buf[1] = i%10; //
i = rAlram_Minute;
rLcd_Buf[2] = i/10; // 00 ~ 59
rLcd_Buf[3] = i%10; //
}
//==================================================================
// Melody Control
//==================================================================
// Buzzer sound ( Sound Frequency & Length )
// Melody sound ( 4MHz Oscillator base )
//---------------------------------------------------------------
// [Frequency]
//---------------------------------------------------------------
// 瀾釬 C(檔) D(飯) E(固) F(頗) G(賈) A(扼) B(矯)
// Octave 1 130.810 146.830 164.810 174.610 196.600 220.000 246.940
// Octave 2 261.630 293.660 329.630 349.230 392.000 440.000 493.880
// Octave 3 523.250 587.330 659.260 698.460 783.990 880.000 987.770
// Octave 4 1046.50 1174.70 1318.50 1396.90 1568.00 1760.00 1975.50
//
//---------------------------------------------------------------
// [Length]
//---------------------------------------------------------------
// Largo 4000 = 160 x 25 mSec (Adagio, Rento) 酒林 蠢府霸
// Andante 3700 = 148 x 25 mSec 蠢府霸
// Andantino 3350 = 134 x 25 mSec 煉陛 蠢府霸
// Moderato 3000 = 120 x 25 mSec 焊烹 狐福霸
// Allegretto 2700 = 108 x 25 mSec 煉陛 狐福霸
// Allegro 2350 = 94 x 25 mSec 狐福霸
// Vivache 2000 = 80 x 25 mSec (Presto) 酒林 狐福霸
//
// 柯 瀾釬 : /1
// 2盒瀾釬 : /2
// 4盒瀾釬 : /4
// 8盒瀾釬 : /8
// 16盒瀾釬: /16
// 槳釬 :
//---------------------------------------------------------------
// 25mSec T2 interrupt Count 扁霖 Length
//---------------------------------------------------------------
#define EOT 0xFF // end of table
#define PAUSE 0x0A // PAUSE (槳釬)
/*
#define Largo 160 //
#define Andante 148 //
#define Andantino 134 //
#define Moderato 120 //
#define Allegretto 108 //
#define Allegro 94 //
#define Vivache 80 //
*/
//---------------------------------------------------------------
// 16mSec T2 interrupt Count 扁霖 Length
//---------------------------------------------------------------
#define Largo 250 //
#define Andante 231 //
#define Andantino 210 //
#define Moderato 187 //
#define Allegretto 169 //
#define Allegro 145 //
#define Vivache 125 //
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -