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

📄 万微电子-- pcf8563驱动c51源程序.htm

📁 fft的工业级的EP9315的开发板的所有驱动程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0034)http://wyde.51.net/WEB/pcf8563.htm -->
<HTML><HEAD><TITLE>万微电子-- pcf8563驱动C51源程序</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE>.a {
	COLOR: #0099ff; TEXT-DECORATION: none
}
.a:hover {
	COLOR: #000000; TEXT-DECORATION: none
}
.b {
	COLOR: #000000; TEXT-DECORATION: none
}
.b:hover {
	COLOR: #0066ff; TEXT-DECORATION: none
}
固定网页字体 P {
	FONT-SIZE: 9pt
}
TD {
	FONT-SIZE: 9pt
}
LI {
	FONT-SIZE: 9pt
}
SELECT {
	FONT-SIZE: 9pt
}
</STYLE>

<SCRIPT language=JavaScript><!--function MM_openBrWindow(theURL,winName,features) { //v2.0  window.open(theURL,winName);}//--></SCRIPT>

<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<STYLE fprolloverstyle>A:hover {
	FONT-WEIGHT: bold; COLOR: #ff0000
}
</STYLE>
</HEAD>
<BODY onresize=fix() onscroll=fix() text=#000000 bgColor=#ffffff topMargin=0 
onload=fix()>
<SCRIPT src="万微电子-- pcf8563驱动C51源程序.files/header.htm"></SCRIPT>

<TABLE height=509 cellSpacing=0 cellPadding=0 width=778 align=center 
bgColor=#000000 border=0>
  <TBODY>
  <TR>
    <TD vAlign=top bgColor=#ffffff height=508>
      <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 cellSpacing=0 
      cellPadding=0 width="100%" border=1>
        <TBODY>
        <TR>
          <TD bgColor=#000000 height=1></TD></TR>
        <TR>
          <TD bgColor=#e0e0e0 height=20>
            <P align=center>
            <MARQUEE scrollDelay=100 width=774 
            bgColor=#e0e0e0>所有程序源码,经本人经本人验证!--仅供参考</MARQUEE></P></TD></TR>
        <TR>
          <TD bgColor=#e0e0e0 
            height=20>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            pcf8563驱动C51源程序</TD></TR>
        <TR>
          <TD bgColor=#000000 height=1></TD></TR></TBODY></TABLE>
      <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 height=138 
      cellSpacing=0 cellPadding=0 width="100%" border=1>
        <TBODY>
        <TR></TD></TR>
        <TR>
          <TD vAlign=top align=left width=572 height=1>
            <P align=right>&nbsp;文章编号:4----加入日期:2004-8-26</P></TD></TR>
        <TR>
          <TD vAlign=top width=572 height=253>
            <P>#include &lt;reg52.h&gt;<BR>#include &lt;intrins.h&gt;<BR>#define 
            uchar unsigned char<BR>sbit SDA=P3^4;<BR>sbit SCL=P3^5;<BR>sbit 
            P10=P1^0;
            <P>uchar g8563_Store[4]; /*时间交换区,全局变量声明*/<BR>uchar code 
            c8563_Store[4]={0x00,0x59,0x07,0x01}; /*写入时间初值:星期一 
            07:59:00*/<BR><BR>/********************************************<BR>内部函数,延时1<BR>********************************************/<BR>void 
            Delay()<BR>{<BR>&nbsp;&nbsp; // 
            {P10=1;_nop_();P10=0;}<BR>&nbsp;&nbsp;&nbsp; 
            _nop_();<BR>&nbsp;&nbsp; _nop_(); 
            /*根据晶振频率制定延时时间*/<BR>}<BR>/********************************************<BR>内部函数,I2C开始<BR>********************************************/<BR>void 
            Start()<BR>{&nbsp; EA=0;<BR>&nbsp;&nbsp; SDA=1;<BR>&nbsp;&nbsp; 
            SCL=1;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            SDA=0;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            SCL=0;<BR>}<BR>/********************************************<BR>内部函数,I2C结束<BR>********************************************/<BR>void 
            Stop()<BR>{<BR>&nbsp;&nbsp; SDA=0;<BR>&nbsp;&nbsp; 
            SCL=0;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            SCL=1;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            SDA=1;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            EA=1;<BR>}<BR>/********************************************<BR>内部函数,输出ACK 
            ,每个字节传输完成,输出ack=0,结束读书据,ack=1;<BR>********************************************/<BR>void 
            WriteACK(uchar ack)<BR>{<BR>&nbsp;&nbsp; SDA=ack;<BR>&nbsp;&nbsp; 
            Delay();<BR>&nbsp;&nbsp; SCL=1;<BR>&nbsp;&nbsp; 
            Delay();<BR>&nbsp;&nbsp; 
            SCL=0;<BR>}<BR>/********************************************<BR>内部函数,等待ACK<BR>********************************************/<BR>void 
            WaitACK()<BR>{&nbsp; uchar errtime=20;<BR>&nbsp;&nbsp; 
            SDA=1;<BR>&nbsp;&nbsp; Delay(); /*读ACK*/<BR>&nbsp;&nbsp; 
            SCL=1;<BR>&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            while(SDA)<BR>&nbsp;&nbsp; {&nbsp; 
            errtime--;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!errtime) 
            Stop();<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; SCL=0;<BR>&nbsp;&nbsp; 
            Delay();<BR>}<BR>/********************************************<BR>内部函数.输出数据字节<BR>入口:B=数据<BR>********************************************/<BR>void 
            writebyte(uchar wdata)<BR>{<BR>&nbsp;&nbsp; uchar i;<BR>&nbsp;&nbsp; 
            for(i=0;i&lt;8;i++)<BR>&nbsp;&nbsp; 
            {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(wdata&amp;0x80) 
            SDA=1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 
            SDA=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            wdata&lt;&lt;=1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            SCL=1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            Delay();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            SCL=0;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; 
            WaitACK();&nbsp;&nbsp;&nbsp;&nbsp; 
            //I2C器件或通讯出错,将会退出I2C通讯<BR>}<BR>/********************************************<BR>内部函数.输入数据<BR>出口:B<BR>********************************************/<BR>uchar 
            Readbyte()<BR>{<BR>&nbsp;&nbsp; uchar i,bytedata;<BR>&nbsp;&nbsp; 
            SDA=1;<BR>&nbsp;&nbsp; for(i=0;i&lt;8;i++)<BR>&nbsp;&nbsp; 
            {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SCL=1; 
            <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            bytedata&lt;&lt;=1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            bytedata|=SDA;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            SCL=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Delay();<BR>&nbsp;&nbsp; 
            }<BR>&nbsp;&nbsp; 
            return(bytedata);<BR>}<BR>/********************************************<BR>输出数据-&gt;pcf8563<BR>********************************************/<BR>void 
            writeData(uchar address,uchar mdata)<BR>{<BR>&nbsp;&nbsp; 
            Start();<BR>&nbsp;&nbsp; writebyte(0xa2); /*写命令*/<BR>&nbsp;&nbsp; 
            writebyte(address); /*写地址*/<BR>&nbsp;&nbsp; writebyte(mdata); 
            /*写数据*/<BR>&nbsp;&nbsp; 
            Stop();<BR>}<BR>/********************************************<BR>输入数据&lt;-pcf8563<BR>********************************************/<BR>uchar 
            ReadData(uchar address) /*单字节*/<BR>{&nbsp; uchar 
            rdata;<BR>&nbsp;&nbsp; Start();<BR>&nbsp;&nbsp; writebyte(0xa2); 
            /*写命令*/<BR>&nbsp;&nbsp; writebyte(address); /*写地址*/<BR>&nbsp;&nbsp; 
            Start();<BR>&nbsp;&nbsp; writebyte(0xa3); /*读命令*/<BR>&nbsp;&nbsp; 
            rdata=Readbyte();<BR>&nbsp;&nbsp; WriteACK(1);<BR>&nbsp;&nbsp; 
            Stop();<BR>&nbsp;&nbsp; return(rdata);<BR>}<BR>void ReadData1(uchar 
            address,uchar count,uchar * buff) /*多字节*/<BR>{&nbsp; uchar 
            i;<BR>&nbsp;&nbsp; Start();<BR>&nbsp;&nbsp; writebyte(0xa2); 
            /*写命令*/<BR>&nbsp;&nbsp; writebyte(address); /*写地址*/<BR>&nbsp;&nbsp; 
            Start();<BR>&nbsp;&nbsp; writebyte(0xa3); /*读命令*/<BR>&nbsp;&nbsp; 
            for(i=0;i&lt;count;i++)<BR>&nbsp;&nbsp; 
            {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            buff[i]=Readbyte();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            if(i&lt;count-1) WriteACK(0);<BR>&nbsp;&nbsp; 
            }<BR>&nbsp;&nbsp;WriteACK(1);<BR>&nbsp;&nbsp; 
            Stop();<BR>}<BR>/********************************************<BR>内部函数,读入时间到内部缓冲区<BR>********************************************/<BR>void 
            P8563_Read()<BR>{&nbsp;&nbsp; uchar time[7];<BR>&nbsp;&nbsp;&nbsp; 
            ReadData1(0x02,0x07,time);<BR>&nbsp;&nbsp;&nbsp; 
            g8563_Store[0]=time[0]&amp;0x7f; /*秒*/<BR>&nbsp;&nbsp;&nbsp; 
            g8563_Store[1]=time[1]&amp;0x7f; /*分*/<BR>&nbsp;&nbsp;&nbsp; 
            g8563_Store[2]=time[2]&amp;0x3f; /*小时*/<BR>&nbsp;&nbsp;&nbsp; 
            g8563_Store[3]=time[4]&amp;0x07; 
            /*星期*/<BR>}<BR>/********************************************<BR>读入时间到内部缓冲区----外部调用 
            <BR>********************************************/<BR>void 
            P8563_gettime()<BR>{<BR>&nbsp;&nbsp;&nbsp; 
            P8563_Read();<BR>&nbsp;&nbsp;&nbsp; 
            if(g8563_Store[0]==0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            P8563_Read(); 
            /*如果为秒=0,为防止时间变化,再读一次*/<BR>}<BR>/********************************************<BR>写时间修改值<BR>********************************************/<BR>void 
            P8563_settime()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; uchar 
            i;<BR>&nbsp;&nbsp;&nbsp;&nbsp; for(i=2;i&lt;=4;i++) { 
            writeData(i,g8563_Store[i-2]); }<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
            writeData(6,g8563_Store[3]);<BR>}<BR>/********************************************<BR>P8563的初始化-----外部调用<BR>********************************************/<BR>void 
            P8563_init()<BR>{<BR>&nbsp;&nbsp;&nbsp; uchar 
            i;<BR>&nbsp;&nbsp;&nbsp; if((ReadData(0xa)&amp;0x3f)!=0x8) 
            /*检查是否第一次启动,是则初始化时间*/<BR>&nbsp;&nbsp;&nbsp; 
            {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(i=0;i&lt;=3;i++) 
            g8563_Store[i]=c8563_Store[i]; 
            /*初始化时间*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            P8563_settime();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            writeData(0x0,0x00);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            writeData(0xa,0x8); 
            /*8:00报警*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            writeData(0x1,0x12); 
            /*报警有效*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            writeData(0xd,0xf0);<BR>&nbsp;&nbsp;&nbsp; 
        }<BR>}<BR>//注意区分大小写</P></TD></TR></TBODY></TABLE>
      <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#111111 height=35 
      cellSpacing=0 cellPadding=0 width="100%" bgColor=#000000 border=1>
        <TBODY>
        <TR>
          <TD bgColor=#000000 height=1>
            <P align=right></P></TD></TR>
        <TR>
          <TD bgColor=#e0e0e0 height=18>
            <DIV align=center>Copyright 2004 - 2005 万微电子工作室 
        版权所有.</DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!--浮动菜单-->
<SCRIPT language=javascript><!--function stat(){     var a = pageYOffset+window.innerHeight-document.bar.document.height-15     document.bar.top = a     setTimeout('stat()',2)}function fix(){     nome=navigator.appName    if(nome=='Netscape')    {        stat()    }    else    {       var a=document.body.scrollTop+document.body.clientHeight-document.all.bar.offsetHeight+15       bar.style.top = a    }}--></SCRIPT>
<SPAN id=bar 
style="Z-INDEX: 9; LEFT: 796px; WIDTH: 170px; POSITION: absolute; TOP: 231px; HEIGHT: 246px">
<DIV align=center>
<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#000000 height=1 
cellSpacing=0 cellPadding=0 width=170 bgColor=#ffffff border=0 hspace="1">
  <TBODY>
  <TR align=middle>
    <TD width=195 height=1><INPUT onclick=window.close() type=button value=关闭窗口 name=close>&nbsp;<SPAN 
      id=bar0><INPUT onclick="window.open('http://wyde.51.net/')" type=button value="首  页" name=close></SPAN></TD></TR></TBODY></TABLE></DIV></SPAN><!--浮动菜单-->
<SCRIPT src="万微电子-- pcf8563驱动C51源程序.files/footer.htm"></SCRIPT>
</BODY></HTML>

⌨️ 快捷键说明

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