feat: onewire and ds18b20 driver

This commit is contained in:
2024-11-28 02:35:59 +08:00
parent 31482c9a70
commit 8edaf36a1a
9 changed files with 141 additions and 105 deletions

18
lib/ds18b20/ds18b20.c Normal file
View 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;
}