标题: STC89C52RC单片机读取DS18B20温度 [打印本页]

作者: ONES    时间: 2017-6-9 09:14
标题: STC89C52RC单片机读取DS18B20温度
  仅供学习使用 不得商用
#include <reg52.h>
#include "ds18b20.h"

//òy½Å¶¨òå:       
sbit SMG_q = P0^0;
sbit SMG_b = P0^1;
sbit SMG_s = P0^2;
sbit SMG_g = P0^3;
unsigned char ly_dis[4];
code unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc6};
                               
unsigned char l_posit=0;
void display(void)
void delay(void);
       
void main()
{
        unsigned int i=0;
        char ltemp;
        while(1){
                if(i==0)                       
                        tmpchange();      
                if(i==100){
                        ltemp=tmp()/16;
                        if(ltemp<0){       
                                ly_dis[0]=0xbf;
                                ltemp=0-ltemp;       
                        }
                        else
                                ly_dis[0]=ltemp/100;
                        ltemp=ltemp%100;
                        ly_dis[1]=ltemp/10;       
                        ly_dis[2]=ltemp%10;       
                        ly_dis[3]=10;       
                }
                i++;
                if(i==3000)                       
                        i=0;
                display();       
                delay();
        }
}
void display()
{
        P2=0XFF;               
        switch(l_posit){
        case 0:       
                SMG_q=0;
                SMG_b=1;       
                SMG_s=1;               
                SMG_g=1;
                P2=table[ly_dis[0]];       
                break;
        case 1:       
                SMG_q=1;
                SMG_b=0;       
                SMG_s=1;               
                SMG_g=1;
                P2=table[ly_dis[1]];
                break;
        case 2:       
                SMG_q=1;
                SMG_b=1;       
                SMG_s=0;               
                SMG_g=1;
                P2=table[ly_dis[2]];
                break;
        case 3:       
                SMG_q=1;
                SMG_b=1;       
                SMG_s=1;               
                SMG_g=0;
                P2=table[ly_dis[3]];
                break;
        }
        l_posit++;       
        if(l_posit>3)
                l_posit=0;       
}

//Ñóê±×óoˉêy,¶ìÔYÑóê±
void delay(void){               
        unsigned char i=10;
        while(i--);
}


例1-读温感DS18B20显示温度值整数.rar

40.97 KB, 下载次数: 9, 下载积分: 黑币 -5


作者: 区叔叔    时间: 2018-6-12 21:25
感谢楼主!!!




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1