#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
uchar temp1,temp2,temp,A;
uchar sb[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0x00};
sbit DQ=P1^0;
void delay(uint t)
{
uint j,k;
for(j=t;j>0;j--)
for(k=115;k>0;k--);
}
void display_1820(uchar x)
{
uint i,ge,shi,bai;
bai=x/100;
shi=x%100/10;
ge=x%10;
P0=sb[ge];
for(i=0;i<4;i++)
{
if(i==0){P0=0x00;P0=sb[0];P2=0xfe;delay(10);}
if(i==0){P0=0x00;P0=sb[bai];P2=0xfd;delay(10);}
if(i==0){P0=0x00;P0=sb[shi];P2=0xfb;delay(10);}
if(i==0){P0=0x00;P0=sb[ge];P2=0xf7;delay(10);}
}
}
void delay_18b20(uint i)
{
for(;i>0;i--);
}
void init()
{
uchar x=0;
DQ=1;
delay_18b20(8);
DQ=0;
delay_18b20(80);
DQ=1;
delay_18b20(14);
x=DQ;
delay_18b20(20);
}
uchar read()
{
uchar i=0;
uchar dat=0;
for(i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)dat|=0x80;
delay_18b20(4);
}
return dat;
}
void write(uchar dat)
{
uchar i=0;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay_18b20(5);
DQ=1;
dat>>=1;
}
}
uchar read1()
{
uchar a=0,b=0,t=0;
init();
write(0xcc);
write(0x44);
delay_18b20(100);
init();
write(0xcc);
write(0xbe);
delay_18b20(100);
a=read();
b=read();
temp1=b<<4;
temp1+=(a&0xf0)>>4;
temp2=a&0x0f;
temp=((b*256+a)>>4);
return temp;
}
void main()
{
while(1)
{
A=read1();
display_1820(A);
}
}
|