⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds18b20.c

📁 F:程序DS18B20.rar索读取温度
💻 C
字号:
#include <mega16.h>

// 1 Wire Bus functions
/****单总线端口为PORTD.3****/
#asm
   .equ __w1_port=0x12 ;PORTD
   .equ __w1_bit=3
#endasm
#include <1wire.h>

// DS1820 Temperature Sensor functions
#include <ds18b20.h>
#include <delay.h> 
#include<ds18b20_add.h>

// maximum number of DS1820 devices
// connected to the 1 Wire bus
#define MAX_DS1820 8
// number of DS1820 devices
// connected to the 1 Wire bus
unsigned char ds1820_devices;
// DS1820 devices ROM code storage area,
// 9 bytes are used for each device
// (see the w1_search function description in the help)
unsigned char ds1820_rom_codes[MAX_DS1820][9];

// Standard Input/Output functions
#include <stdio.h>

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here

}

// Declare your global variables here

void main(void)
{
// Declare your local variables here
unsigned char i,j;
int temp; 
 

// Global enable interrupts
#asm("sei")
 init_M16();
 
 for (i=0;i<ds1820_devices;)
    if (!ds18b20_init(&ds1820_rom_codes[i++][0],20,30,DS18B20_12BIT_RES))
       {
       printf("Init error for\ndevice #%u",i);
       while (1); /* stop here if init error */
       };
while (1)
      {
      // Place your code here
       for (i=0;i<ds1820_devices;)
          {
          temp=ds18b20_temperature(&ds1820_rom_codes[i][0])*10;
          j='+';
          if (temp<0)
             {
             j='-';
             temp=-temp;
             };
          printf("t%u=%u.%u^C",++i,temp/10,temp%10);
          delay_ms(1800);
          };
      };

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -