蓝桥杯 DS18B20

#include "reg52.h"
#include "absacc.h"
#include "onewire.h"


unsigned int temp=0;

unsigned char SMGNoDot[10]={0xc0,0xf9,0xa4,0xb0,0x99,
                              0x92,0x82,0xf8,0x80,0x90};
unsigned char SMGDot[10]={0x40,0x79,0x24,0x30,0x19,
                            0x12,0x02,0x78,0x00,0x10};

void DisplaySMG_Bit(unsigned char pos,unsigned char dat)
{
    XBYTE[0xE000]=0xff;
    XBYTE[0xC000]=0x01<<pos;
    XBYTE[0xE000]=dat;
}

void Display_All(unsigned char dat)
{
    XBYTE[0xC000]=0xff;
    XBYTE[0xE000]=dat;
}

void DelaySMG(unsigned char t)
{
    while(t--);
}

void DisplaySMG_Temp()
{
    DisplaySMG_Bit(7,SMGNoDot[temp%10]);
    DelaySMG(100);
    DisplaySMG_Bit(6,SMGDot[(temp/100)%10]);
    DelaySMG(100);
    DisplaySMG_Bit(5,SMGNoDot[temp/100]);
    DelaySMG(100);
    DisplaySMG_Bit(4,0xff);
    DelaySMG(100);
  DisplaySMG_Bit(3,0xff);
    DelaySMG(100);
    DisplaySMG_Bit(2,0xff);
    DelaySMG(100);
    DisplaySMG_Bit(1,0xff);
    DelaySMG(100);
    DisplaySMG_Bit(0,0xff);
    DelaySMG(100);
  Display_All(0xff);
    DelaySMG(100);
}

void Delay(unsigned int t)
{
    while(t--)
    {
        DisplaySMG_Temp();
    }
}
void Read_DS18B20_temp()
{
    unsigned char LSB,MSB;
    init_ds18b20();
    Write_DS18B20(0xcc);
    Write_DS18B20(0x44);
    
    Delay(1000);
    
    init_ds18b20();
    Write_DS18B20(0xcc);
    Write_DS18B20(0xbe);
    
    LSB=Read_DS18B20();
    MSB=Read_DS18B20();
    
    temp=MSB;
    temp=(temp<<8)+ LSB;
    
    temp*=0.625;
}

void main()
{
    XBYTE[8000]=0xff;
    
    while(1)
    {
        Read_DS18B20_temp();
        DisplaySMG_Temp();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值