⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mylcd.c

📁 适合任意点阵的LCD屏幕的液晶时钟显示程序!开发人员只用简单的修改接口定义即刻方便调用!
💻 C
📖 第 1 页 / 共 2 页
字号:
		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,temp_year,temp_x,temp_y;
unsigned char *temp_p;


//显示哭笑符
if (ku_flag)temp_p=(&ku)+32;
else temp_p=&ku;
temp_x=0;
temp_y=16;
ku_flag=!ku_flag;
display(temp_p,temp_x,temp_y,2);

//显示秒
temp=time.second;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=13;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=12;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

//显示分
temp=time.minute;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=9;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=8;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

//显示时
temp=time.hour;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=5;
temp_y=16;
display(temp_p,temp_x,temp_y,1);
temp_x=4;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

//显示日
temp=day.day;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=13;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=12;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

//显示月
temp=day.month;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=9;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=8;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);


//显示年
temp_year=day.year/100;
temp=day.year%100;
temp=hex_bcd(temp);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=5;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=4;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

//显示年高位
temp=hex_bcd(temp_year);
temp1=temp>>4;
temp=temp&0xf;
temp_p=(&num)+16*temp;
temp_x=3;
temp_y=0;
display(temp_p,temp_x,temp_y,1);
temp_x=2;
temp_p=(&num)+16*temp1;
display(temp_p,temp_x,temp_y,1);

}

/****************************************************************
**润年判断leap()子函数
**参数:unsigned int year
**返回字:润年标志leap0为非润年
**内部变量:bit leap1
****************************************************************/
bit leapf(unsigned int year){
bit bdata leap1;
	if(year%4==0){
				if(year%100==0){
					if(year%400==0){
						leap1=1;
						}
					else leap1=0;
					}
				else leap1=1;
				}
			else leap1=0;
return(leap1);
}
/****************************************************************
**hex_bcd()子函数
**参数:hex需要转换的单字节16进制数
**返回字:转换完成的单字节bcd码,高4位为高位低4位为低位
**内部变量:bcd,temp为无符号字符型
****************************************************************/
unsigned char hex_bcd(unsigned char hex){
unsigned char bcd,temp;

bcd=hex%10;
temp=hex/10;
temp=temp<<4;
bcd=bcd|temp;
return (bcd);
}

/****************************************************************
**	key()键盘子函数
**	键盘为两键式一个键
**	参数:
****************************************************************/



/****************************************************************
**	time0()定时器0中断子函数,产生50ms中断
**
****************************************************************/
void time0() interrupt 1 using 1{
TH0=0x3c;						//time0 50ms interrupt
TL0=0xba;
TR0=1;
msecond++;
if (msecond==20){
	second_flag=1;
	msecond=0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -