feat: onewire and ds18b20 driver
This commit is contained in:
18
lib/ds18b20/ds18b20.c
Normal file
18
lib/ds18b20/ds18b20.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include "ds18b20.h"
|
||||
#include "onewire.h"
|
||||
|
||||
void DS18B20_startConvert(void) {
|
||||
OneWire_init();
|
||||
OneWire_writeByte(DS18B20_SKIP_ROM);
|
||||
OneWire_writeByte(DS18B20_CONVERT_TEMP);
|
||||
}
|
||||
|
||||
int DS18B20_readTemperature(void) {
|
||||
OneWire_init();
|
||||
OneWire_writeByte(DS18B20_SKIP_ROM);
|
||||
OneWire_writeByte(DS18B20_READ_SCRATCHPAD);
|
||||
uchar T_LSB = OneWire_readByte();
|
||||
uchar T_MSB = OneWire_readByte();
|
||||
int temp = T_MSB << 8 | T_LSB;
|
||||
return temp;
|
||||
}
|
20
lib/ds18b20/ds18b20.h
Normal file
20
lib/ds18b20/ds18b20.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __TEMP_H
|
||||
#define __TEMP_H
|
||||
|
||||
#ifndef uchar
|
||||
#define uchar unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef uint
|
||||
#define uint unsigned int
|
||||
#endif
|
||||
|
||||
#define DS18B20_SKIP_ROM 0xCC
|
||||
#define DS18B20_CONVERT_TEMP 0x44
|
||||
#define DS18B20_READ_SCRATCHPAD 0xBE
|
||||
|
||||
void DS18B20_startConvert(void);
|
||||
|
||||
int DS18B20_readTemperature(void);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user