📄 ds18b20.c
字号:
/* Multipoint thermometer with LCD display
using the Maxim DS18B20
1 Wire bus temperature sensors
CodeVisionAVR C Compiler
(C) 2000-2005 HP InfoTech S.R.L.
www.hpinfotech.ro
Chip: ATmega8515
Memory Model: SMALL
Data Stack Size: 128 bytes
THE ATmega8515 CLOCK FREQUENCY MUST BE 3.6864 MHz
The DS18B20 sensors are connected to
bit 6 of PORTA of the ATmega8515 as follows:
[DS18B20] [STK500 PORTA HEADER]
1 GND - 9 GND
2 DQ - 7 PA6
3 VDD - 10 +5V
All the temperature sensors must be connected
in parallel
AN 4.7k PULLUP RESISTOR MUST BE CONNECTED
BETWEEN DQ (PA6) AND +5V !
*/
#asm
.equ __w1_port=0x1b
.equ __w1_bit=6
#endasm
/* Use an 2x16 alphanumeric LCD connected
to PORTC as follows:
[LCD] [STK500 PORTC HEADER]
1 GND- 9 GND
2 +5V- 10 VCC
3 VLC- LCD contrast control voltage 0..1V
4 RS - 1 PC0
5 RD - 2 PC1
6 EN - 3 PC2
11 D4 - 5 PC4
12 D5 - 6 PC5
13 D6 - 7 PC6
14 D7 - 8 PC7
*/
#asm
.equ __lcd_port=0x15
#endasm
#include <lcd.h> // LCD driver routines
#include <ds18b20.h>
#include <delay.h>
#include <stdio.h>
char lcd_buffer[33];
main()
{
//unsigned char i,j,devices;
float aa;
lcd_init(16);
lcd_putsf("CodeVisionAVR\n1 Wire Bus Demo");
delay_ms(2000);
lcd_clear();
if(ds18b20_init(0,25,35,DS18B20_12BIT_RES)==0)
{
while (1); /* stop here if init error */
};
while (1)
{
//j=1;
//for (i=0;i<1;i++)
// {
aa=ds18b20_temperature(0);
if(aa>125)
sprintf(lcd_buffer,"t=%+.1f\xdfC",aa-4096);
else
sprintf(lcd_buffer,"t=%+.1f\xdfC",aa);
lcd_clear();
lcd_puts(lcd_buffer);
delay_ms(500);
//};
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -