#include #include
#define uint unsigned int
#define uchar unsigned char
***it ds=P2^2;
***it dula=P2^6;
***it wela=P2^7;
uint temp;
float f_temp;
uchar code num1[] = {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6F} ;
uchar code num2[] = {0xBF , 0x86 , 0xDB , 0xCF , 0xE6 , 0xED , 0xFD , 0x87 , 0xFF , 0xEF} ;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init(void)
{
char i;
unsigned char x = 0;
ds=1;
i=8;
while(i>0)i--;
ds=0;
i=80;
while(i>0)i--;
ds=1;
i=14;
while(i>0)i--;
x=ds;
i=20;
while(i>0)i--;
}
bit tempreadbit(void)
{
uint i;
bit dat;
ds=0; i++;
ds=1;i++;i++;
dat=ds;
i=8; while(i>0)i--;
return(dat);
}
uchar tempread(void)
{
uchar i,j,dat;
dat=0;
for(i=0;i<=8;i++)
{
j=tempreadbit();
dat=(j<<7)|(dat>>1);
}
return(dat);
}
void tempwritebyte(uchar dat)
{
uchar i = 0;
for (i = 8; i>0; i--)
{
ds=0;
ds=dat&0x01;
delay(5);
ds=1;
dat>>=1;
}
delay(4);
}
void tempchange(void)
{ init();
delay(1);
tempwritebyte(0xcc);
tempwritebyte(0x44);
}
uint get_temp()
{
uchar a,b;
init();
delay(1);
tempwritebyte(0xcc);
tempwritebyte(0xbe);
a=tempread();
b=tempread();
temp=b;
temp<<=8 ;
temp=temp|a;
f_temp=temp*0.0625;
temp=f_temp*10+0.5;
f_temp=f_temp+0.05;
return temp;
}
void LED(uint temp)
{
uchar a,b,c;
a=temp/100 ;
b=temp%100/10 ;
c=temp%10 ;
P0=0xfe ;
wela=1 ;
wela=0 ;
P0=num1[a] ;
dula=1 ;
dula=0 ;
delay(5) ;
P0=0xfd ;
wela=1 ;
wela=0 ;
P0=num2[b] ;
dula=1 ; dula = 0 ;
delay(5) ;
P0=0xfb ;
wela=1 ;
wela=0 ;
P0=num1[c] ;
dula=1 ;
dula=0 ;
delay(1) ;
}
void main()
{
while(1)
{wela=0 ;
dula=0 ;
tempchange() ;
LED(get_temp) ;
}
}
|