#include <reg52.h>
#include <intrins.h>
typedef unsigned char INT8U;
typedef unsigned char uchar;
typedef unsigned int INT16U;
typedef unsigned int uint;
sbit DS = P3^6;
//sbit DU = P1;
//sbit WE = P2;
uchar code table[]={
//0 1 2 3 4 5 6 7 8
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80,
//9 A B C D E F - . 關顯示
0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E, 0xBF, 0x7F, 0xFF};
uchar code T_COM[] = {0xfe, 0xfd, 0xfb, 0xf7,};//數碼管位碼
/*us延時函數,執行一次US--所需6.5us進入一次函數需要11.95us*/
void Delay_us(uchar us)
{
while(us--);
}
/*====================================
函數 : delay(uint z)
參數 :z 延時毫秒設定,取值范圍0-65535
返回值 :無
描述 :12T/Fosc11.0592M毫秒級延時
====================================*/
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}
void Display(INT16U Value)
{
P1 = 0XFF;
P2 = T_COM[1];
P1 = table[Value/100];
delay(5);
P1 = 0XFF;
P1 = 0XFF;
P2 = T_COM[2];
P1 = table[Value%100/10]&0x7f;
delay(5);
P1 = 0XFF;
P1 = 0XFF;
P2 = T_COM[3];
P1 = table[Value%10];
delay(5);
P1 = 0XFF;
}
bit ds_init()
{
bit i;
DS = 1;
_nop_();
DS = 0;
Delay_us(75);
DS = 1;
Delay_us(4);
i = DS;
Delay_us(20);
DS = 1;
_nop_();
return(i);
}
void write_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DS = 0;
_nop_();
DS = 1;
DS = dat & 0x01;
Delay_us(10);
DS = 1; //釋放總線準備下一次數據寫入
_nop_();
dat >>= 1;
}
}
uchar read_byte()
{
uchar i, j, dat;
for(i=0;i<8;i++)
{
DS = 0;
_nop_();
DS = 1;
_nop_();
j = DS;
Delay_us(10);
DS = 1;
_nop_();
dat = (j<<7)|(dat>>1);
}
return (dat);
}
void main()
{
uint i=0;
uchar L, M;
/* ds_init();
write_byte(0xcc);
write_byte(0x4e);
write_byte(0x7f);
write_byte(0xf7);
write_byte(0x1f);
ds_init();
write_byte(0xcc);
write_byte(0x48);*/
while(1)
{
ds_init();
write_byte(0xcc);
write_byte(0x44);
ds_init();//初始化DS18B20
write_byte(0xcc);
write_byte(0xbe);
L = read_byte();
M = read_byte();
i = M;
i <<=8;
i |= L;
i = i * 0.0625 * 10 + 0.5;
}
{
Display(i); delay(10);
}
}
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_DISPLAY?WHENG
Program Size: data=11.1 xdata=0 code=1193
creating hex file from "1"...
"1" - 0 Error(s), 1 Warning(s).
|