您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > PCF8563实时时钟日历6位数码管显示
#includeat89s52.h#defineuintunsignedint#defineucharunsignedchar#definePORT_DuanP0//数码管段显#definePORT_WeiP2//数码管位显ucharSec_8563,Min_8563,Hou_8563,Day_8563,Week_8563,Mon_8563,Year_8563;//时钟全局变量//---PCF8563端口位定义---------------------------------sbitsda_8563=P1^0;sbitscl_8563=P1^1;//----函数声明-------------------------------voidstart_8563(void);voidstop_8563(void);voidwrite_8563(uchardata_8563);ucharread_8563(void);voidInit_8563(void);voidRead_data_8563(void);voidDisplay_8563(uchartime_1,uchartime_0);voidDisplay_Int(uintdat);/******************************************/uchardat[6];//用户数据输入口ucharcodeDSY_d[]={//字型码(段选码)0-9,低电平有效0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};ucharcodeDSY_w[]={//低电平有效0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选信号//计数函数/*动态扫描函数*/ucharnum;voidSEG_DSY(void)//数码管显示函数{PORT_Wei=PORT_Wei;//屏蔽高两位PORT_Duan=0Xff;//消隐PORT_Duan=DSY_d[dat[num]];//显示段PORT_Wei=0XFF;//消隐PORT_Wei=DSY_w[num];//3位数码管if(++num==6)num=0;}voidTIME_T1(void){TMOD=0X10;TH1=(65536-2000)/256;//2msTL1=(65536-2000)%256;EA=1;ET1=1;TR1=1;}//---PCF8563驱动//--------------------------------------------------------------------------//函数名称:start_8563()//函数功能:8563启动时序//其他说明://--------------------------------------------------------------------------voidstart_8563(void)//启动8563{sda_8563=1;scl_8563=1;sda_8563=0;}//--------------------------------------------------------------------------//函数名称:stop_8563()//函数功能:8563停止时序//其他说明://--------------------------------------------------------------------------voidstop_8563(void)//停止8563{sda_8563=0;scl_8563=1;sda_8563=1;}//--------------------------------------------------------------------------//函数名称:write_8563(uchardata_8563)//函数功能:8563写一个字节//其他说明://--------------------------------------------------------------------------voidwrite_8563(uchardata_8563)//写一位数据8563{uchari;for(i=0;i8;i++){scl_8563=0;if(data_8563&0x80){sda_8563=1;}elsesda_8563=0;scl_8563=1;data_8563=1;scl_8563=0;//最后拉低电平完成一个完整脉冲(error)}sda_8563=1;scl_8563=1;scl_8563=0;}//--------------------------------------------------------------------------//函数名称:read_8563()//函数功能:8563读一个字节//其他说明://--------------------------------------------------------------------------ucharread_8563(void)//读一位数据8563{uchari,temp;for(i=0;i8;i++){scl_8563=0;temp=1;scl_8563=1;if(sda_8563==1){temp|=0x01;}}sda_8563=1;scl_8563=0;scl_8563=1;scl_8563=0;return(temp);}//--------------------------------------------------------------------------//函数名称:Read_data_8563()//函数功能:读8563时间数据(BCD码)//其他说明://--------------------------------------------------------------------------voidRead_data_8563(void)//读取8563时间{uchari;uchardata_from_8563[7];for(i=0;i7;i++){start_8563();write_8563(0xa2);//写入写指令write_8563(0x02+i);//写入地址start_8563();write_8563(0xa3);//写入读指令data_from_8563[i]=read_8563();}stop_8563();Sec_8563=data_from_8563[0];//秒Min_8563=data_from_8563[1];//分Hou_8563=data_from_8563[2];//时Day_8563=data_from_8563[3];//日Week_8563=data_from_8563[4];//星期Mon_8563=data_from_8563[5];//月Year_8563=data_from_8563[6];//年}voidsegvalue(void){dat[0]=Sec_8563&0x0f;//秒dat[1]=(Sec_85634)&0x0f;//十秒dat[2]=Min_8563&0x0f;//分dat[3]=(Min_85634)&0x0f;//十分dat[4]=Hou_8563&0x0f;//时dat[5]=(Hou_85634)&0x0f;//十时}//--------------------------------------------------------------------------//函数名称:Init_8563()//函数功能:8563初始化//其他说明://--------------------------------------------------------------------------voidInit_8563(void)//初始化8563{uchari;uchardata_8563[7]={0x55,0x59,0x07,0x18,0x03,0x08,0x88};//初始化时钟设置(秒~分~时~周~星期~月~年)for(i=0;i7;i++){start_8563();write_8563(0xa2);//写入写指令write_8563(0x02+i);//写地址write_8563(data_8563[i]);}stop_8563();}//主程序voidmain(void){Init_8563();//8563初始化显示时钟07:59:55TIME_T1();while(1){Read_data_8563();//读8563时间数据segvalue();}}/*中断服务函数*/voidtimeT1()interrupt3{TH1=(65536-2000)/256;//定时2msTL1=(65536-2000)%256;SEG_DSY();//数码管显示}
本文标题:PCF8563实时时钟日历6位数码管显示
链接地址:https://www.777doc.com/doc-2225672 .html