#include "reg52.h"
#include "absacc.h"
#include "onewire.h"
unsigned int temp=0;
unsigned char SMGNoDot[10]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
unsigned char SMGDot[10]={0x40,0x79,0x24,0x30,0x19,
0x12,0x02,0x78,0x00,0x10};
void DisplaySMG_Bit(unsigned char pos,unsigned char dat)
{
XBYTE[0xE000]=0xff;
XBYTE[0xC000]=0x01<<pos;
XBYTE[0xE000]=dat;
}
void Display_All(unsigned char dat)
{
XBYTE[0xC000]=0xff;
XBYTE[0xE000]=dat;
}
void DelaySMG(unsigned char t)
{
while(t--);
}
void DisplaySMG_Temp()
{
DisplaySMG_Bit(7,SMGNoDot[temp%10]);
DelaySMG(100);
DisplaySMG_Bit(6,SMGDot[(temp/100)%10]);
DelaySMG(100);
DisplaySMG_Bit(5,SMGNoDot[temp/100]);
DelaySMG(100);
DisplaySMG_Bit(4,0xff);
DelaySMG(100);
DisplaySMG_Bit(3,0xff);
DelaySMG(100);
DisplaySMG_Bit(2,0xff);
DelaySMG(100);
DisplaySMG_Bit(1,0xff);
DelaySMG(100);
DisplaySMG_Bit(0,0xff);
DelaySMG(100);
Display_All(0xff);
DelaySMG(100);
}
void Delay(unsigned int t)
{
while(t--)
{
DisplaySMG_Temp();
}
}
void Read_DS18B20_temp()
{
unsigned char LSB,MSB;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay(1000);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
LSB=Read_DS18B20();
MSB=Read_DS18B20();
temp=MSB;
temp=(temp<<8)+ LSB;
temp*=0.625;
}
void main()
{
XBYTE[8000]=0xff;
while(1)
{
Read_DS18B20_temp();
DisplaySMG_Temp();
}
}