本帖最后由 eehome 于 2013-1-5 09:59 编辑
实在是解决不了 纠结好几天了 !求大神指导!
这是原程序!
#include
#define uchar unsigned char
#define uint unsigned int
***it SCLK=P1^6;
***it SDA=P3^5;
***it REST=P1^7;
***it dula=P3^7;
uchar dat1,dat2;
uchar code Tab_Num[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delayus(uchar xms)
{
uint i;
for(i=xms;i>0;i--);
}
void delayms(uchar xms)
{ uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void writebyte(uchar add)
{
uchar i;
SCLK=0;
delayus(2);
for(i=0;i<8;i++)
{
SDA=add&0x01;
SCLK=1;
delayus(2);
SCLK=0;
add>>=1;
}
}
uchar readbyte()
{
uchar i,dat;
delayus(2);
for(i=0;i<8;i++)
{
dat>>=1;
if(SDA)
dat=dat|0x80;
SCLK=1;
delayus(2);
SCLK=0;
delayus(2);
}
return dat;
}
void write1302(uchar add,uchar dat)
{
SCLK=0;
REST=0;
delayus(2);
REST=1;
writebyte(add);
delayus(2);
writebyte(dat);
delayus(2);
REST=0;
}
uchar read1302(uchar add)
{
uchar temp;
SCLK=0;
REST=0;
delayus(2);
REST=1;
writebyte(add);
delayus(2);
temp=readbyte();
SCLK=1;
REST=0;
return(temp);
}
void init1302()
{
write1302(0x8e,0x00);
write1302(0x80,0x55);
write1302(0x82,0x59);
//write1302(0x84,0x80);
//write1302(0x84,(11/10<<4)|(11%10));//直接用十进制表示传输的数据 十进制转换成16进制!
write1302(0x84,0x15);
write1302(0x8e,0x80);
}
void main()
{
uchar e,b,c,shi,fen,miao;
//uint miaoshi,miaoge;
//if(read1302(0x81)&0x80) //查询1302时钟是否已经启动:如果时钟停止走动,则启动时钟 + 初始化时间;否则跳过。秒寄存器的最高位
//{
init1302();
// }
while(1)
{
shi=read1302(0x85);
delayus(1);
e=shi;
shi=shi>>4;
e=e&0x0f;
dula=1;P0=Tab_Num[shi];dula=0;P2=0x00;delayms(1);
dula=1;P0=Tab_Num[e];dula=0;P2=0x01; delayms(1);
delayms(1);
dula=1;P0=0x40;dula=0;P2=2; delayms(1);
fen=read1302(0x83);
delayus(1);
b=fen;
fen=fen>>4;
b=b&0x0f;
dula=1;P0=Tab_Num[fen];dula=0;P2=0x03; delayms(1);
dula=1;P0=Tab_Num;dula=0;P2=0x04; delayms(1);
delayms(1);
dula=1;P0=0x40;dula=0;P2=5; delayms(1);
miao=read1302(0x81);
delayus(1);
c=miao;
miao=miao>>4;
c=c&0x0f;
dula=1;P0=Tab_Num[miao];dula=0;P2=0x06; delayms(1);
dula=1;P0=Tab_Num[c];dula=0;P2=0x07; delayms(1);
delayms(1);
/* dat1=miao/16; //16进制转换成BCD
dat2=miao%16;
miao=dat1*10+dat2; //转换成10进制数
miaoshi=miao/10;
miaoge=miao%10;
dula=1;P0=Tab_Num[miaoshi];dula=0;P2=0x06; delayms(1);
dula=1;P0=Tab_Num[miaoge];dula=0;P2=0x07; delayms(1); */ //16进制转换成10进制由十进制计算个位与十位
}
}
|