以下代码如果只获取秒,或分是可以的,但是SUBF分别获取时分秒,就会乱码,请各位帮看看,困扰已久,非常感谢!
#include <reg51.h>
#include <intrins.h>
unsigned char i,c,k,flag;
sbit CLC=P0^2;
sbit DAT=P0^1;
sbit RES=P0^0;
sbit LED=P2^4;
void botelv()
{
EA=1;
ES=1;
TMOD=0x20;
//SCON=0x50;
SM0=0;SM1=1; REN=1;
TH1=0xfd;
TL1=0xfd;
TR1=1;
}
void delay(unsigned int t)
{
while (--t);
}
read(unsigned char dz)
{
unsigned char value,t,i;
RES=1;
for(i=0;i<8;i++)
{
CLC=0;
DAT=dz&0x01;
dz=dz>>=1;
CLC=1;
}
for(i=0;i<8;i++)
{
CLC=0;
t=DAT;
t=t<<=i;
value=value|t;
CLC=1;
}
P2=value;
RES=0;
return value;
}
void main()
{
char m,s,h;
botelv();
//while(1)
{
s=read(0x81);
m=read(0x83);
h=read(0x85);
delay(55555);
SBUF=m;
while(TI==0);
TI=0;
SBUF=s;
while(TI==0);
TI=0;
}
}
void fasong() interrupt 4
{
//TI=0;
flag=1;
}
|