};
unsigned char code ku[]={
/*-- 调入了一幅图像:这是哭的的图像 --*/
/*-- 宽度x高度=16x16 --*/
0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x52,0x4A,0x8C,0x31,0x80,0x01,
0x80,0x01,0x81,0x81,0x42,0x42,0x44,0x22,0x20,0x04,0x10,0x08,0x0C,0x30,0x03,0xC0,
/*-- 调入了一幅图像:这是笑的的图像 --*/
/*-- 宽度x高度=16x16 --*/
0x03,0xC0,0x0C,0x30,0x10,0x08,0x20,0x04,0x40,0x02,0x40,0x02,0x8C,0x31,0x92,0x49,
0x80,0x01,0x80,0x01,0x44,0x22,0x42,0x42,0x21,0x84,0x10,0x08,0x0C,0x30,0x03,0xC0
};
/*****************************************************************************
**字库结束
******************************************************************************/
void day();
void time();
void begin();
void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l);
unsigned char hex_bcd(unsigned char hex);
void display_begin();
void display_time(struct time_str time,struct day_str day);
bit leapf(unsigned int year);
void main()
{
begin();
display_begin();
while (1)
{
while (1)
{
time();
day();
if (display_flag)
{
display_flag=0;
display_time(time_now,day_now);
}
if (display_flag)
continue;
if((day_now.month==2)&leap)
{
leap=0;
day_temp=29;
}
}
}
}
/******************************************************
**time()子函数
**参数:second_flay
**
******************************************************/
void time(){
if(second_flag){
display_flag=1;
second_flag=0;
// day_flag=1;
time_now.second++;
if(time_now.second==60){
time_now.second=0;
time_now.minute++;
if(time_now.minute==60){
time_now.minute=0;
time_now.hour++;
if(time_now.hour==24){
time_now.hour=0;
day_flag=1;
}
}
}
}
}
/*********************************************************
**day()子函数
**参数:day_flag日标志;leap润年标志
**
**********************************************************/
void day(){
if(day_flag){
day_flag=0;
day_now.day++;
if(day_now.day==day_temp+1){
day_now.month++;
if((day_now.month==2)&leap){
leap=0;
day_temp=29;
}
else day_temp=day_num[day_now.month-1];
day_now.day=1;
if(day_now.month==13){
day_now.month=1;
day_temp=day_num[day_now.month-1];
day_now.year++;
leap=leapf(day_now.year);
}
}
}
}
/****************************************************************
**begin()子函数系统参数初始化
**
****************************************************************/
void begin(){
//定时器0初始化
TMOD=0x21; //50ms int 12M
TH0=0x3c;
TL0=0xba;
TR0=1;
IE=0x92;
SCON|=0x40;
//状态标志位初始化
//参量初始化
time_now.second=0;
time_now.minute=0;
time_now.hour=0;
day_now.year=1980;
day_now.month=6;
day_now.day=27;
leap=leapf(day_now.year);
day_temp=day_num[day_now.month-1];
}
/****************************************************************
**display()子函数
**参数说明:*cpoint:要显示的字符地址指针
** x_line:横轴坐标(1-16)
** y_line:纵轴坐标(1-16)
** s_l: 1为8*16字体;2为16*16字体
**返回值:无
****************************************************************/
void display(unsigned char *cpoint,unsigned char x_line,unsigned char y_line,unsigned char s_l){
unsigned char xdata *xpoint;
unsigned char i,j;
xpoint=0x8000+x_line+y_line*16;
for(i=0;i<16;i++){
for(j=0;j<s_l;j++){
*xpoint=*cpoint;
cpoint++;
xpoint++;
}
xpoint=xpoint+16-s_l;
}
}
/****************************************************************
**display_begin()子函数显示屏幕的初始值如:
** —————————
** | 1980年09月05日|
** | 23时03分09秒|
** —————————
**调用函数:display()
** display_time()
**
****************************************************************/
//指定位置显示“年,月,日,时,分,秒”
//unsigned char code zhi_loc[]=
//{0x06,0x01,0x0a,0x01,0x0e,0x01,0x06,0x10,0x0a,0x10,0x0e,0x10};
void display_begin(){
unsigned char x_display,y_display,i,j=0;
unsigned char code *p_display;
p_display=&shi;
for (i=0;i<6;i++){
x_display=zhi_loc[j];
j++;
y_display=zhi_loc[j];
j++;
display(p_display,x_display,y_display,2);
p_display=p_display+32;
}
//指定位置显示时间
display_time(time_now,day_now);
}
/****************************************************************
** display_time()显示时间子函数
** 参数:struct time_str time
** struct day_str day
** 返回值:无
** 调用函数:display()
** hex_bcd()
****************************************************************/
void display_time(struct time_str time,struct day_str day){
unsigned char temp,temp1,year,x,y;
unsigned char *p;
//显示哭笑符
if (ku_flag)p=(&ku)+32;
else p=&ku;
x=0;
y=16;
ku_flag=!ku_flag;
display(p,x,y,2);
//显示秒
temp=time.second;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=13;
y=16;
display(p,x,y,1);
x=12;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示分
temp=time.minute;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=9;
y=16;
display(p,x,y,1);
x=8;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示时
temp=time.hour;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=5;
y=16;
display(p,x,y,1);
x=4;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示日
temp=day.day;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=13;
y=0;
display(p,x,y,1);
x=12;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示月
temp=day.month;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=9;
y=0;
display(p,x,y,1);
x=8;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示年
year=day.year/100;
temp=day.year%100;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=5;
y=0;
display(p,x,y,1);
x=4;
p=(&num)+16*temp1;
display(p,x,y,1);
//显示年高位
temp=hex_bcd(year);
temp1=temp>>4;
temp=temp&0xf;
p=(&num)+16*temp;
x=3;
y=0;
display(p,x,y,1);
x=2;
p=(&num)+16*temp1;
display(p,x,y,1);
}
/****************************************************************
本文关键字:暂无联系方式51单片机,单片机-工控设备 - 51单片机