?? ds18b20.c~
字號:
#include <mega16.h>
// 1 Wire Bus functions
#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);
};
};
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -