我用DS1302做一个电子钟,碰到一个很奇怪的问题。我把小时寄存器的位7置1应该是AM/PM制的,但是程序判断不为0处理成24小时制。我把位7置0,能正常运行在24小时制下。附代码段,高手帮我看看问题出在哪里。 下面这个是我用来判断24制还是12制: if((time[2]&0x80)==0x80)//判断小时寄存器位7是否为1 { if((time[2]&0x20)==0x20)//判断小时寄存器位5是否为1,1为PM,0为AM { displaystring(0,0,"PM"); } else displaystring(0,0,"AM"); displaychar(2,0,number[(time[2]&0x10)>>4]);//进制转换并显示 } else { if((time[2]&0x20)==0x20) displaychar(2,0,number[2]); displaychar(2,0,number[(time[2]&0x10)>>4]); } 这个函数是用来控制时钟开或关和24制或12制。 void settimetype(bit timeoff,bit ampm) { unsigned char temp1; if(timeoff) //1为关闭时钟,0开启时钟 { temp1=read1302(otimeaddress[0]); temp1|=0x80; write1302(0x8e,0x00); write1302(itimeaddress[0],temp1); write1302(0x8e,0x80); } else { temp1=read1302(otimeaddress[0]); temp1&=0x7f; write1302(0x8e,0x00); write1302(itimeaddress[0],temp1); write1302(0x8e,0x80); } if(ampm)//1为12小时制,0为24小时制 { temp1=read1302(otimeaddress[2]); temp1|=0x80; write1302(0x8e,0x00); write1302(itimeaddress[2],temp1); write1302(0x8e,0x80); } else { temp1=read1302(otimeaddress[2]); temp1&=0x7f; write1302(0x8e,0x00); write1302(itimeaddress[2],temp1); write1302(0x8e,0x80); } } |