有谁用过CVAVR里面的DS18B20啊
这个库应该怎么用啊,网上大多是DS1820的不是DS18B20的.有这几个函数:
unsigned char ds18b20_select(unsigned char *addr);
unsigned char ds18b20_read_spd(unsigned char *addr);
float ds18b20_temperature(unsigned char *addr);
unsigned char ds18b20_init(unsigned char *addr,signed char temp_low,signed char temp_high,
unsigned char resolution);
具体怎么用啊.
假如传感器接在PORTA.0;
是不是
.equ __w1_port=0x1b //PORTA
.equ __w1_bit=1
然后程序里面在
ds18b20_init(0,1,90,DS18B20_12BIT_RES);
temp=ds18b20_temperature(0);
这样就行了???
反正我这样没读出来.. 为什么ds18b20_init的返回总是0呢.... 俄...没人用过么.. 不行就自己 写下 不是很难 10莫元估计米有达人来回答,我给你个例程吧:我自己编的
cvavr2.039 1602液晶显示的,4线
============================
/*****************************************************
file name : use codewizardAVR to complete 1602 and ds18b20
Chip type : ATmega16L
Program type : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
hardware connect :
// ----------------- //
// /|\| PA.5|-->ds18b20 //
// | | PB.0|-->RS //
// --|RST PB.1|-->RW //
// | PB.2|-->E //
// | PB.4|-->DB4 //
// | PB.5|-->DB5 //
// |RST PB.6|-->DB6 //
// | PB.7|-->DB7 //
// ----------------- //
*****************************************************/
#include <mega16.h>
#include <delay.h>
unsigned char rom_code;
unsigned char alarm_rom_code;
flash unsigned char dis_str[]="0123456789";
// 1 Wire Bus functions
#asm
.equ __w1_port=0x1B ;PORTA
.equ __w1_bit=5
#endasm
#include <1wire.h>
// DS1820 Temperature Sensor functions
#include <ds18b20.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTB
#endasm
#include <lcd.h>
// Declare your global variables here
void main(void)
{
unsigned char i,devices;
float temp1;
int temp2,temp3,temp4;
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
MCUCSR=0x00;
TIMSK=0x00;
ACSR=0x80;
SFIOR=0x00;
// 1 Wire Bus initialization
w1_init();
// LCD module initialization
lcd_init(16);
lcd_clear();
while (1)
{
devices=w1_search(0xf0,rom_code);
lcd_gotoxy(0,0);
lcd_putsf("num:");
lcd_gotoxy(4,0);
lcd_putchar(dis_str);
temp1=ds18b20_temperature(&rom_code);
temp1*=10;
lcd_gotoxy(0,1);
lcd_putchar(dis_str[(int)temp1/100]);
lcd_gotoxy(1,1);
lcd_putchar(dis_str[(int)temp1%100/10]);
lcd_gotoxy(2,1);
lcd_putchar(dis_str[(int)temp1%10]);
temp2=ds18b20_temperature(&rom_code);
temp2*=10;
lcd_gotoxy(4,1);
lcd_putchar(dis_str[(int)temp2/100]);
lcd_gotoxy(5,1);
lcd_putchar(dis_str[(int)temp2%100/10]);
lcd_gotoxy(6,1);
lcd_putchar(dis_str[(int)temp2%10]);
temp3=ds18b20_temperature(&rom_code);
temp3*=10;
lcd_gotoxy(8,1);
lcd_putchar(dis_str[(int)temp3/100]);
lcd_gotoxy(9,1);
lcd_putchar(dis_str[(int)temp3%100/10]);
lcd_gotoxy(10,1);
lcd_putchar(dis_str[(int)temp3%10]);
temp4=ds18b20_temperature(&rom_code);
temp4*=10;
lcd_gotoxy(12,1);
lcd_putchar(dis_str[(int)temp4/100]);
lcd_gotoxy(13,1);
lcd_putchar(dis_str[(int)temp4%100/10]);
lcd_gotoxy(14,1);
lcd_putchar(dis_str[(int)temp4%10]);
for(i=0;i<4;i++)
{
if (ds18b20_init(&rom_code,20,28,DS18B20_12BIT_RES)&&devices==4)
{
lcd_gotoxy(6,0);
lcd_putsf("ok^_^");
}
else
{
lcd_gotoxy(6,0);
lcd_putsf("error");
}
}
lcd_gotoxy(12,0);
lcd_putsf("FL:");
lcd_gotoxy(15,0);
lcd_putchar(dis_str);
};
}
上面的例程是读一根线上的4个18B20 zhaoxukiller 发表于 2012-9-12 18:33 static/image/common/back.gif
10莫元估计米有达人来回答,我给你个例程吧:我自己编的
cvavr2.039 1602液晶显示的,4线
============= ...
你好,我想问问,一定要执行1wire init()么,还有问什么不执行ds18b20_init()呢?
页:
[1]