#include <reg52.h>
#include <function.h> //详见第六章第8讲
#include <timer.h> //详见第八章第11讲
#include <uart.h> //详见第十章第4讲
#include <ds18b20.h> //详见第十三章第5讲
u8 flag1s = 0;
void
main()
{
u32 x=1;
u8 str[13];
u16 temp;
EA = 1;
LED_Init();
Start18B20();
TIM0_Init(1000,33);
ConfigUART(9600);
while
(1)
{
if
(flag1s)
{
flag1s = 0;
if
( TEMP_CONV(&temp,str)==1
{
printf_str(
"第"
);
printf_num(x);
x++;
printf_str(
"秒:"
);
printf_str(str+temp_i);
printf_str(
"度"
);
printf_rn();
temp_i=0;
LedBuff[0]=LedChar[str[4]-
'0'
];
LedBuff[1]=0x7F;
LedBuff[2]=LedChar[str[2]-
'0'
];
if
(str[0]==
'-'
)
{
if
(str[1]==
'0'
)
{
LedBuff[3]=0xBF;
LedBuff[4]=0xFF;
}
else
{
LedBuff[3]=LedChar[str[1]-
'0'
];
LedBuff[4]=0xBF;
}
}
else
{
if
(str[1]==
'0'
)LedBuff[3]=0xFF;
else
LedBuff[3]=LedChar[str[1]-
'0'
];
if
(str[0]==
'0'
)LedBuff[4]=0xFF;
else
LedBuff[4]=LedChar[str[0]-
'0'
];
}
}
Start18B20();
}
}
}
void
TIM0_IRQHandler() interrupt 1
{
static
u16 tmr1s = 0;
TH0 = T0RH;
TL0 = T0RL;
tmr1s++;
SEG_Scan();
if
(tmr1s >= 1000)
{
tmr1s = 0;
flag1s= 1;
}
}
void
InterruptUART() interrupt 4
{
if
(RI)
{
RI = 0;
}
}