<ignore_js_op>
<img src="https://www.xiaopingtou.net/data/attach/2001/5u5fgme5y3xijc6wf75zr59qnfowjcge.jpg"> </ignore_js_op><p><br>
<br>
程序用数码管显示是没问题的,调整分的时候小时会变成0,然后又恢复正常了,分钟调整是没问题的<br><br>
<br>
#include <regx52.h><br>
#define WRITE_SECOND 0x80<br>
#define WRITE_MINUTE 0x82<br>
#define WRITE_HOUR 0x84<br>
#define READ_SECOND 0x81<br>
#define READ_MINUTE 0x83<br>
#define READ_HOUR 0x85<br>
#define WRITE_PROTECT 0x8E<br>
sbit ACC_7=ACC^7;//位寻址寄存器定义<br>
sbit SCLK=P2^0; // DS1302时钟信号 7脚<br>
sbit DIO=P2^1; // DS1302数据信号 6脚<br>
sbit CE=P2^2; // DS1302片选 5脚<br>
unsigned char Hour_10_bit,Hour_0_bit,Min_10_bit,Min_0_bit,Sec_10_bit,Sec_0_bit,g_bSystemTime2Ms,Hour,Min,Sec;<br>
void Write1302 ( unsigned char addr,dat ) //地址、数据发送子程序 <br>
{<br>
unsigned char i,temp;<br>
CE=0; //CE引脚为低,数据传送中止<br>
SCLK=0; //清零时钟总线<br>
CE = 1; //CE引脚为高,逻辑控制有效//发送地址<br>
for ( i=8; i>0; i-- ) //循环8次移位<br>
{ <br>
SCLK=0;//上升沿准备<br>
temp=addr;<br>
DIO=(bit)(temp&0x01);//每次传输低字节<br>
addr>>= 1;//右移一位<br>
SCLK=1;//形成上升沿<br>
}<br>
<br>
for ( i=8; i>0; i-- ) <br>
{ <br>
SCLK=0;//上升沿准备<br>
temp=dat;<br>
DIO=(bit)(temp&0x01); <br>
dat>>=1; <br>
SCLK=1;//形成上升沿<br>
}<br>
CE=0; <br>
}<br>
unsigned char Read1302 (unsigned char addr )//数据读取子程序<br>
{<br>
unsigned char i,temp,dat1,dat2; <br>
CE=1; <br>
<br>
for ( i=8; i>0; i-- ) //发送地址 //循环8次移位<br>
{ <br>
SCLK=0;//上升沿准备<br>
temp=addr;<br>
DIO=(bit)(temp&0x01);//每次传输低字节<br>
addr>>=1;//右移一位<br>
SCLK=1; //形成上升沿<br>
}<br>
<br>
for ( i=8;i>0;i--) <br>
{<br>
ACC_7=DIO;<br>
SCLK=1;//下降沿准备<br>
ACC>>=1;<br>
SCLK=0;//形成下降沿<br>
} <br>
CE=0;<br>
dat1=ACC;<br>
dat2=dat1/16; //数据进制转换<br>
dat1=dat1%16; //十六进制转十进制<br>
dat1=dat1+dat2*10; <br>
return (dat1);<br>
<br>
}<br>
void Initial_DS1302( )//初始化DS1302 <br>
{ <br>
Write1302(WRITE_PROTECT,0X00); //关写保护<br>
Write1302(WRITE_SECOND,0x40); //秒位初始化<br>
Write1302(WRITE_MINUTE,0x59); //分钟初始化<br>
Write1302(WRITE_HOUR,0x02); //小时初始化<br>
Write1302(WRITE_PROTECT,0x80); //开写保护<br>
}<br>
void Read_1302( )<br>
{<br>
if(g_bSystemTime2Ms>30)<br>
{ <br>
TR0=0; <br>
g_bSystemTime2Ms=0;<br>
TR0=1;<br>
Hour=Read1302(READ_HOUR);//读取时 <br>
Min=Read1302(READ_MINUTE);//读取分<br>
Sec=Read1302(READ_SECOND);//读取秒 <br>
Hour_10_bit=Hour/10;<br>
Hour_0_bit=Hour%10;<br>
Min_10_bit=Min/10;<br>
Min_0_bit=Min%10;<br>
Sec_10_bit=Sec/10;<br>
Sec_0_bit=Sec%10;<br>
}<br>
} </regx52.h></p><p><br></p><p></p>
case (4)://减
ucKeySec=0;
switch(Display_Variable)
{
case (11):
Clock_min_change=Min;
if(Clock_min_change==0)
Clock_min_change=60;
Clock_min_change--;
c=BCD_BIN(Clock_min_change);
//Write1302(WRITE_PROTECT,0X00); //关写保护
Write1302(WRITE_MINUTE,c); //分钟初始化
//Write1302(WRITE_PROTECT,0x80); //开写保护
break;
//Write1302(WRITE_PROTECT,0X00); //关写保护
Write1302(WRITE_MINUTE,c); //分钟初始化
//Write1302(WRITE_PROTECT,0x80); //开写保护
只要执行了Write1302这个函数就会出问题
显示程序没问题,走时正常的
一周热门 更多>