我用DS1302做一个电子钟,碰到一个很奇怪的问题。就是我把小时寄存器的位7置1应该是AM/PM制的,但是我用程序判断下来他还是0,小时显示有问题。我把位7置0,能正常运行在24小时制下。附代码段,高手帮我看看问题出在哪里。 下面这个是我用来判断24制还是12制: if((time[2]&0x80)==0x80) { if((time[2]&0x20)==0x20) { 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) { 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) { 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); } }
|