请列出下列程序的每一条命令的意思(要尽可能详细点):

#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar baizhi=0;
sbit DQ=P1^3;
uchar code disp[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code num[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};

void delay(uint i)
{while(i--);}

void init()
{
DQ=1;
_nop_();
DQ=0;
delay(60);
DQ=1;
delay(10);

if(DQ==0){baizhi=1;delay(20);DQ=1;}
//if(DQ==1){baizhi=1;delay(20);DQ=1;}
}

uchar read_date(void)
{
uchar temp,i;
for(i=0;i<8;i++)
{
DQ=1;
_nop_();
_nop_();
DQ=0;
_nop_();
_nop_();
_nop_();
DQ=1;
_nop_();
temp>>=1;
if(DQ==1){temp=temp|0x80;}
delay(5);
}
return temp;
}

void write_date(uchar date)
{
uchar i;
for(i=0;i<8;i++)
{
DQ=0;
_nop_();
_nop_();
DQ=date&0x01;
delay(5);
DQ=1;
date>>=1;
}
}

uint dcwdsj(void)
{
uchar themh=0;
uchar theml=0;
uint tem=0;

init();
if(baizhi==1)
{
write_date(0x0cc);
write_date(0x44);
delay(100);
}
init();
if(baizhi==1)
{
write_date(0x0cc);
write_date(0x0be);
theml=read_date();
themh=read_date();
}
tem=(themh*256+theml)*25;
tem=tem>>2;
return tem;
}

void main()
{
uint them;
uchar com=20;
them=dcwdsj();
while(1)
{
com--;
if(com==0)
{
them=dcwdsj();
com=20;
}
P2=0XFF;
P0=disp[them%1000%100%10];
P2=0xdf;
delay(100);

P2=0XFF;
P0=disp[them%1000%100/10];
P2=0xef;
delay(100);

P2=0XFF;
P0=num[them%1000/100];
P2=0xf7;
delay(100);

P2=0XFF;
P0=disp[them/1000%10];
P2=0xfb;
delay(100);
}
}

第1个回答  2012-01-03
这么长一串程序 才给20分 打字都不止20min
相似回答