#include "reg52.h"
#include "onewire.h"
unsigned char code SMGdaima[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
unsigned char code distab[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
unsigned char temp=0x0000;
void Select573(unsigned int n)
{
switch(n)
{
case 5: P2=(0x1f & P2) | 0xa0;break;
case 6: P2=(0x1f & P2) | 0xc0;break;
case 7: P2=(0x1f & P2) | 0xe0;break;
}
}
void delay(unsigned char t)
{
while(t--);
}
void displySMG_bit(unsigned char pos,unsigned char value)
{
Select573(6);
P0=0x01<<pos;
Select573(7);
P0=value;
}
void displySMG_temp()
{
displySMG_bit(7,SMGdaima[temp%10]);
delay(500);
displySMG_bit(6,distab[temp%100/10]);
delay(500);
displySMG_bit(5,SMGdaima[temp/100]);
delay(500);
displySMG_bit(4,SMGdaima[10]);
delay(500);
displySMG_bit(3,SMGdaima[10]);
delay(500);
displySMG_bit(2,SMGdaima[10]);
delay(500);
displySMG_bit(1,SMGdaima[10]);
delay(500);
displySMG_bit(0,SMGdaima[10]);
delay(500);
}
void delay1(unsigned char t)
{
while(t--);
}
void readtemp()
{
unsigned char LSB,MSB;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
delay1(1000);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
LSB=Read_DS18B20();
MSB=Read_DS18B20();
temp=MSB;
temp=(temp<<8)|LSB;
if(temp & 0xfe00 == 0x0000)
{
temp>>=4;
temp=temp*10;
temp=temp+(LSB&0x0f)*0.625;
}
}
void init_buzz()
{
Select573(5);
P0=0x00;
}
void main()
{
init_buzz();
while(1)
{
readtemp();
displySMG_temp();
}
} |