|
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
?Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2010-8-13
Author :
Company :
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#define MAX_DEVICES 8
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h> // DS1820 Temperature Sensor functions
#include <ds18b20.h>
#include <lcd.h>
#asm
.equ __lcd_port=0x15
#endasm
// 1 Wire Bus functions
#include <1wire.h>
#asm
.equ __w1_port=0x1b
.equ __w1_bit=0
#endasm
unsigned char ds18b20_devices;
//number of DS1820 devices connected to the 1 Wire bus
unsigned char rom_code[MAX_DEVICES][9]; //DS18B20 devices ROM code storage area
//定义18B20检测
void DS18B20_cfg(void)
//Search DS18B20 Device and Configure each DS18B20 device;
{
unsigned char i;
// detect how many DS18B20 devices are connected to the 1 Wire bus
ds18b20_devices=w1_search(DS18B20_SEARCH_ROM_CMD,rom_code);
// configure each DS18B20 device for 12 bit temperature measurement resolution
for (i=0;i<ds18b20_devices;i++)
ds18b20_init(&rom_code[i++][0],10,30,DS18B20_12BIT_RES);
}
void main(void)
{
w1_init();
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
DS18B20_cfg(); //检测DS18B20是否存在
if(ds18b20_devices)
{
lcd_putsf("Init Successful");
}
else
{
lcd_putsf("ERROR !!!");
lcd_gotoxy(0,1);
lcd_putsf("Out of connect!");
while(1);
}
while(1)
{
lcd_gotoxy(1,1);
lcd_putchar(ds18b20_temperature(&rom_code[0][0])); //显示温度
delay_ms(300);
};
} |
|