//***********************************************
//******** 东东西西电子工作室**************
//******** 个人主页:http://hi.baidu.com/hujiaabc *****
//程序名称:DS18B20温度显示程序
//******** MCU: STC89C52 晶振:12Mhz ***********
//简要说明:使用4位共阴数码管,数据口接P0口
//寄存器选择信号端RS-P2.0、读写信号端R/W-P2.1、使能信号端EP-P2.2
//***********************************************
#include "at89x52.h"
#include "intrins.h" //_nop_();延时函数用
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P3^2; //温度输入口
sbit DIN=P0^7; //LED小数点控制
uchar code tab1[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
/* 共阳LED段码表 "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "不亮" "-" */
//*******温度小数部分用查表法**********//
uchar code tab2[16]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};
uchar data temp_data[2]={0x00,0x00}; // 读出温度低8位,高8位
uchar t0,t1,t2,t3,t4;//显示单元数据,共4个数据,t4运算暂存用
/***********11微秒延时函数**********/
void delay1(uint t)
{
for(;t>0;t--);
}
/***********显示扫描函数**********/
void scan()
{
P0=tab1[t3];
P2_0=0;
delay1(90);
P2=0xff;
P0=tab1[t2];
P2_1=0;
delay1(90);
P2=0xff;
P0=tab1[t1];
DIN=1;
P2_2=0;
delay1(90);
P2=0xff;
P0=tab1[t0];
P2_3=0;
delay1(90);