cde

6
Theo mnh th nu như phi đo xa th nên dng ds18b20 giao tip theo chun 1 wire. Điu đc bit l dng nhiu ds18b20 nhưng ch mt 1 chân điu khin. V l giao tip bng s v vy không s nh hưng bi nhiu. Tng bn code giao tip ds18b20 dng atmega 16 mnh đ test ok trên mch tht. LCD 16x2 ni portA ds18b20 ni portB.7 code np vo l chy. http://codientu.org/threads/giup-e-do-nhiet-do-su-dung-4-lm35-voi-avr- voi.617/page-4 /***************************************************** 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 : 10/31/2012 Author : Company : Comments: Chip type : ATmega16 Program type : Application Clock frequency : 12.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #include <mega16.h> #include <delay.h> #include <stdio.h> // 1 Wire Bus functions #asm .equ __w1_port=0x18 ;PORTB .equ __w1_bit=7 #endasm #include <1wire.h> // DS1820 Temperature Sensor functions #include <ds18b20.h> // maximum number of DS1820 devices

Upload: hieu-le-dinh

Post on 19-Oct-2015

22 views

Category:

Documents


1 download

TRANSCRIPT

Theo minh thi nu nh phai o xa thi nn dung ds18b20 giao tip theo chun 1 wire. iu c bit la dung nhiu ds18b20 nhng chi mt 1 chn iu khin. Vi la giao tip bng s vi vy khng s anh hng bi nhiu.Tng ban code giao tip ds18b20 dung atmega 16 minh a test ok trn mach tht.LCD 16x2 ni portA ds18b20 ni portB.7 code nap vao la chay.http://codientu.org/threads/giup-e-do-nhiet-do-su-dung-4-lm35-voi-avr-voi.617/page-4

/*****************************************************This program was produced by theCodeWizardAVR V2.03.4 StandardAutomatic Program Generator Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.http://www.hpinfotech.com Project :Version :Date : 10/31/2012Author :Company :Comments: Chip type : ATmega16Program type : ApplicationClock frequency : 12.000000 MHzMemory model : SmallExternal RAM size : 0Data Stack size : 256*****************************************************/ #include #include #include // 1 Wire Bus functions#asm .equ __w1_port=0x18 ;PORTB .equ __w1_bit=7#endasm#include // DS1820 Temperature Sensor functions#include // maximum number of DS1820 devices// connected to the 1 Wire bus#define MAX_DS18b20 8// number of DS1820 devices// connected to the 1 Wire busunsigned char ds18b20_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 ds18b20_rom_codes[MAX_DS18b20][9]; // Alphanumeric LCD Module functions#asm .equ __lcd_port=0x1B ;PORTA#endasm#include void lcd_putnum(float so, char x,char y){long t,c,d;long tp1,tp2,tp3,tp4;float temp1,temp2;t=so/100;// lay phan tramc= (so-100*t)/10;// lay hang chucd= so-100*t-10*c;// lay hang don viif(so