|
#include<reg52.h>
#include<ye12864.h>
unsigned char t,flag = 2;
void Time_Count0_Init() //定时器初始化函数
{
TMOD = 0X01; //设置定时器工作方式为1
TH0 = 0X4C; //定时50ms
TL0 = 0X00;
PCON=0X80; //波特率倍频
TR0 = 1;
ET0 = 1;
EA = 1;
}
void xs(uint dd,i,k) //结果显示函数,dd 要显示的函数,k显示的列数位置,i显示行数位置
{
uint temp4,temp5,shu[20];
char j = 0;
if(dd<10)
{
w_shuzi(k,i,0);
w_shuzi(k+1,i,dd);
}
else
{
while(dd)
{
temp4 = dd/10;
temp5 = dd%10;
shu[j++] = temp5;
dd = temp4;
}
for(--j;j>=0;j--)
{
w_shuzi(k++,i,shu[j]);
}
}
}
void calendar() //万年历函数
{
unsigned char yue,ri,shi,fen,miao,temp,i,xq;
unsigned char dyue[] = {1,3,5,7,8,10,12},xyue[4] = {4,6,9,11};
unsigned int nian;
if(flag ==2)
{
nian = 2012;
yue = 12;
ri = 30;
shi = 22;
fen = 58;
miao = 50;
}
if(flag == 1)
{
miao++;
if(yue == 12&&ri == 31&&shi == 23&&fen == 59&&miao == 60)
{
yue = 1;
ri = 1;
shi = 0;
fen = 0;
miao = 0;
xq++;
}
if(miao == 60)
{
fen++;
miao = 0;
}
if(fen == 60)
{
shi++;
fen = 0;
}
if(shi == 24)
{
shi = 0;
ri++;
xq++;
if(xq == 7)
xq = 0;
}
if(ri == 28&&ri == 29&&ri == 30&&ri == 31) //当日期为28,29,30,30,31才判断月份是否加一
{
for(i = 0;i<7;i++)
{
if(yue == dyue[i])
temp = 2;
}
for(i = 0;i<4;i++)
{
if(yue == xyue[i])
temp = 1;
else
temp = 0;
}
}
if(temp == 2) //是大月
if(ri == 31)
yue++;
if(temp == 1) //是小月
if(ri == 30)
yue++;
if(temp == 0) //2月
if (nian%400 == 0 || (nian%4 == 0 && nian%100 != 0)) //是闰年
{
if(ri == 29)
yue++;
}
else if(ri == 28)
yue++;
xs(nian,2,0);
xs(yue,2,6);
xs(ri,2,9);
xs(shi,4,0);
xs(fen,4,3);
xs(miao,4,6);
w_hanzi(8,2,xq+5);
flag = 0;
}
}
void main()
{
LCD_init();
LCD_qingpin(0x00);
delay(10);
Time_Count0_Init(); //定时器初始化
w_hanzi(0,0,0); //显示万年历
w_hanzi(1,0,1);
w_hanzi(2,0,2);
w_hanzi(6,2,3);
w_hanzi(7,2,4);
while(1)
{
calendar();
}
}
void time_count0() interrupt 1
{
TF0 = 0;
TH0 = 0X4C; //定时50ms
TL0 = 0X00;
TR0 = 0;
if(t == 20)
{
t = 0;
flag = 1;
}
t++;
TR0 = 1;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|