#include "stc15.h"
#include "delay.h"
#include "ds18b20.h"
sbit Bit_0=P3^1;
sbit Bit_1=P3^0;
sbit DIO=P3^2;
sbit SCLK=P3^3;
sbit RCLK=P3^5;
unsigned char code numtab[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
u16 Temp;
void Timer2Init(void)
{
AUXR |= 0x04;
T2L = 0xA0;
T2H = 0x15;
AUXR |= 0x10;
IE|=0x80;
IE2|=0x04;
}
void LED_ShowNum(u8 tab);
void LED_Display(u8 num);
void main(void)
{
SCLK=0; RCLK=0;
Timer2Init();
Delay800ms();
while(1)
{
Delay800ms();
DS18B20_Start();
Temp=Get_DS18B20_Temp();
Temp>>=4;
}
}
void LED_ShowNum(u8 tab)
{
u8 i;
for(i=0x80;i!=0;i>>=1)
{
DIO=tab&i?1:0;
SCLK=0; SCLK=1;
}
RCLK=0; RCLK=1;
}
void LED_Display(u8 num)
{
static u8 i=0;
if(i==0)
{
Bit_1=0;
Bit_0=1;
LED_ShowNum(numtab[num/10]);
i=1;
}
else
{
Bit_1=1;
Bit_0=0;
LED_ShowNum(numtab[num%10]);
i=0;
}
}
void TIM2_IRQHandler(void) interrupt 12
{
LED_Display(Temp);
}
|