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

📄 51

📁 51单片机典型模块开发
💻
📖 第 1 页 / 共 2 页
字号:
	if(xie1(0x04)!=0){xie_stop();return(0);}//取读小时字节地址
	xie_start();                  			//起始条件
	if(xie1(0xa3)!=0){xie_stop();return(0);}//取器件地址 读
	shi=du1();                 				//读时
	shi&=0x3f;								//屏蔽最高2位
	xie_stop();								//停止条件

	xie_start();                  			//起始条件
	if(xie1(0xa2)!=0){xie_stop();return(0);}//写
	if(xie1(0x05)!=0){xie_stop();return(0);}//取读日期字节地址
	xie_start();                  			//起始条件
	if(xie1(0xa3)!=0){xie_stop();return(0);}//读
	riqi=du1();								//读日期
	riqi&=0x3f;								//屏蔽最高2位
	xie_stop();								//停止条件

	xie_start();                    		//起始条件
	if(xie1(0xa2)!=0){xie_stop();return(0);}//写
	if(xie1(0x07)!=0){xie_stop();return(0);}//取读月份字节地址
	xie_start();                  			//起始条件
	if(xie1(0xa3)!=0){xie_stop();return(0);}//读
	yuefen=du1();							//读月份
	yuefen&=0x1f;							//屏蔽最高3位
	xie_stop();								//停止条件

	xie_start();                  			//起始条件
	if(xie1(0xa2)!=0){xie_stop();return(0);}//写
	if(xie1(0x06)!=0){xie_stop();return(0);}//星期字节地址
	xie_start();                  			//起始条件
	if(xie1(0xa3)!=0){xie_stop();return(0);}//读
	xingqi=du1();							//读星期
	xingqi&=0x07;							//保留低3位
	xie_stop();								//停止条件
	
	xie_start();                  			//起始条件
	if(xie1(0xa2)!=0){xie_stop();return(0);}//写
	if(xie1(0x08)!=0){xie_stop();return(0);}//年份字节地址
	xie_start();                  			//起始条件
	if(xie1(0xa3)!=0){xie_stop();return(0);}//读
	nian=du1();								//读年份	
	xie_stop();								//停止条件
	
	EA=1;									//开总中断
	return(1);
}
uchar xie()
{
	EA=0;	
	xie_start();                   			//起始条件                			
	if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
	if(xie1(0x02)!=0){xie_stop();return(0);}//写秒地址
	if(xie1(miao)!=0){xie_stop();return(0);}//写秒
	xie_stop();								//停止条件
	
	xie_start();                    		//起始条件               			
	if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
	if(xie1(0x03)!=0){xie_stop();return(0);}//写分地址
	if(xie1(fen)!=0){xie_stop();return(0);}	//写分
	xie_stop();
	
	xie_start();                     		//起始条件                  			
	if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
	if(xie1(0x04)!=0){xie_stop();return(0);}//写小时地址
	if(xie1(shi)!=0){xie_stop();return(0);}	//写时	
	xie_stop();
	
	xie_start();                  			//写日期
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x05)!=0){xie_stop();return(0);}
	if(xie1(riqi)!=0){xie_stop();return(0);}
	xie_stop();
	
	xie_start();                  			//写月份
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x07)!=0){xie_stop();return(0);}
	if(xie1(yuefen)!=0){xie_stop();return(0);}
	xie_stop();
	
	xie_start();                  			//写星期
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x06)!=0){xie_stop();return(0);}
	if(xie1(xingqi)!=0){xie_stop();return(0);}
	xie_stop();
	
    xie_start();                  			//写年份
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x08)!=0){xie_stop();return(0);}
	if(xie1(nian)!=0){xie_stop();return(0);}
	xie_stop();
	
	EA=1;
	return(1);
} 
/* uchar xie_dingshi()              		//定时器
{
	xie_start();                  			// 控制中断开关
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x01)!=0){xie_stop();return(0);}
	if(xie1(0x01)!=0){xie_stop();return(0);}
	xie_start();                  			//定时器控制器
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x0e)!=0){xie_stop();return(0);}
	if(xie1(0x82)!=0){xie_stop();return(0);}
	xie_start();                  			//计数器
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x0f)!=0){xie_stop();return(0);}
	if(xie1(5)!=0){xie_stop();return(0);}
	xie_stop();
	return(1);
} */
/* uchar xie_fangbo_dingshi()
{
	xie_start();                  			//方波频率
	if(xie1(0xa2)!=0){xie_stop();return(0);}
	if(xie1(0x0d)!=0){xie_stop();return(0);}
	if(xie1(0x82)!=0){xie_stop();return(0);}
	xie_stop();
	return(1);
} */

/////////////////////以上是PCF8563读写/////////////////////以上是PCF8563读写


/*---------------延时子程序----------------*/
void delay1 (uint ms)
{
	uint i,j;
	for(i=0;i<ms;i++)
		for(j=0;j<1000;j++);
}

/*------------写数据或命令到LCD--------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
	chk_busy ();        			//
	di=dat_comm;        			//命令标志
	rw=0;       					//写
	data_ora=content;				//写数据到LCD的数据端
	e=1; 				   			//下降沿锁定数据
	e=0;
} 

/*--------------读LCD数据---------------*/
/* uchar rd_lcd ()
{
	uchar rddata;
	chk_busy ();
	di=1;
	rw=1;      						//读
	e=1;
	rddata=data_ora;				//读数据
	e=0;				   			//下降沿锁定数据
	return rddata;
} */

void chk_busy()
 {
	data_ora=0xff;					//写1到LCD的数据端
	di=0;
	rw=1;      						//读
	e=1;
	//while(bf||res==1);
	e=0;
}

/*--------------写点阵------------------*/
void lat_disp (uchar data1,uchar data2)
 {
	uchar i,j;
	cs1=0;cs2=0;     				//左右屏幕同时选中
	wr_lcd (comm,disp_on);   		//写命令字,显示开
	for(j=0;j<8;j++)
	{
		wr_lcd (comm,disp_x+j);  	//页地址调整
		wr_lcd (comm,disp_z);  		//指向对应页的0行
		wr_lcd (comm,disp_y);  		//指向对应页的0列
		for(i=0;i<32;i++)  			//写64个数据
		{ 
			wr_lcd (dat1,data1);
			wr_lcd (dat1,data2);
		}
	}
} 

/*--------------显示图片----------------*/ 
/* void img_disp (uchar code *img) 
{
	uchar i,j;
	for(j=0;j<8;j++)
	{
		cs1=0;cs2=1;    					//左半屏幕选中
		wr_lcd (comm,disp_on);   			//写命令字,显示开
		wr_lcd (comm,disp_x+j);  			//页地址调整
		wr_lcd (comm,disp_z);  				//指向对应页的0行
		wr_lcd (comm,disp_y);  				//指向对应页的0列
		for(i=0;i<64;i++)  					//写64个数据
			wr_lcd (dat1,img[j*128+i]);
		cs1=1;cs2=0;   						//右半屏幕选中
		wr_lcd (comm,disp_on);   			//写命令字,显示开
		wr_lcd (comm,disp_x+j);  			//页地址调整
		wr_lcd (comm,disp_z);  				//指向对应页的0行
		wr_lcd (comm,disp_y);  				//指向对应页的0列
		for(i=64;i<128;i++) 				//写64个数据
			wr_lcd (dat1,img[j*128+i]);
 }
} */

/*---指定位置(x,y)显示row_xl行(每行row_yl个)汉字(大小8xl*yl)---*/
void chn_disp (uchar x,uchar y,uchar xl,uchar yl,uchar row_xl,uchar row_yl,uchar code *chn)
{
	uchar i,j,k,l,a;
	wr_lcd (comm,disp_on);   					//写命令字,显示开
	for(l=0;l<row_xl;l++)						//行数循环
	{
		for(k=0;k<row_yl;k++)					//字数循环
		{ 
			for(j=0;j<xl;j++)
			{
				wr_lcd (comm,disp_x+x+l*xl+j);	//行数调整
				wr_lcd (comm,disp_z);			//列数调整
				wr_lcd (comm,disp_y+y+k*yl);	//字数调整
				a=l*xl*yl*row_yl+k*xl*yl+j*yl;
				for(i=0;i<yl;i++)				//写数据
				wr_lcd (dat1,chn[a+i]);
			}
		}
	}
}

/*------------------初始化-----------------*/
void init_lcd ()
{
	//rst=0;
	delay(50);
	//rst=1;
	cs1=0;cs2=0;     							//左右屏幕同时选中
	wr_lcd (comm,disp_off);   					//写命令字,显示关
	wr_lcd (comm,disp_on);   					//写命令字,显示开
}
 
void disp()
{
	cs1=0;cs2=1;								//左半屏幕选中
	chn_disp (0,8,2,8,1,1,tabma[2]);			//固定显示数字“2”
	chn_disp (0,16,2,8,1,1,tabma[0]);			//固定显示数字“0”
	chn_disp (0,24,2,8,1,1,tabma[nian/16]);		//显示年的数字十位
	chn_disp (0,32,2,8,1,1,tabma[nian%16]);		//显示年的数字个位
	chn_disp (0,40,2,16,1,1,nianma);			//固定显示汉字“年”
	chn_disp (0,56,2,8,1,1,tabma[yuefen/16]);	//显示月份的数字十位
		
	cs1=1;cs2=0; 								//右半屏幕选中
	chn_disp (0,0,2,8,1,1,tabma[yuefen%16]);	//显示月份的数字个位
	chn_disp (0,8,2,16,1,1,yuema);				//固定显示汉字“月”
	chn_disp (0,24,2,8,1,1,tabma[riqi/16]);		//显示日期的数字十位
	chn_disp (0,32,2,8,1,1,tabma[riqi%16]);		//显示日期的数字个位
	chn_disp (0,40,2,16,1,1,rima);				//固定显示汉字“日”

	cs1=0;cs2=1;								//左半屏幕选中
	chn_disp (3,8,2,16,1,2,xingqima);			//固定显示汉字“星期”
	chn_disp (3,40,2,16,1,1,tab2ma[xingqi]);	//显示汉字星期几
	chn_disp (6,16,2,8,1,1,tabma[shi/16]);		//显示小时的数字十位
	chn_disp (6,24,2,8,1,1,tabma[shi%16]);		//显示小时的数字个位
	chn_disp (6,32,2,16,1,1,shima);				//固定显示汉字“时”
	chn_disp (6,48,2,8,1,1,tabma[fen/16]);		//显示分钟的数字十位
	chn_disp (6,56,2,8,1,1,tabma[fen%16]);		//显示分钟的数字个位

	cs1=1;cs2=0; 								//右半屏幕选中
	chn_disp (6,0,2,16,1,1,fenma);				//固定显示汉字“分”
	chn_disp (6,16,2,8,1,1,tabma[miao/16]);		//显示秒的数字十位
	chn_disp (6,24,2,8,1,1,tabma[miao%16]);		//显示秒的数字个位
	chn_disp (6,32,2,16,1,1,miaoma);			//固定显示汉字“秒”
}

⌨️ 快捷键说明

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