initial commit
This commit is contained in:
46
lib/README
Normal file
46
lib/README
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
78
lib/peripheral/temp.c
Normal file
78
lib/peripheral/temp.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include "temp.h"
|
||||
|
||||
void Delay1ms(uint y) {
|
||||
uint x;
|
||||
for(; y > 0; y--) {
|
||||
for(x = 110; x > 0; x--);
|
||||
}
|
||||
}
|
||||
|
||||
uchar Ds18b20Init(void) {
|
||||
uchar i;
|
||||
DSPORT = 0; // Pull down bus
|
||||
i = 70;
|
||||
while(i--);
|
||||
DSPORT = 1; // Pull up bus
|
||||
i = 0;
|
||||
while(DSPORT) {
|
||||
Delay1ms(1);
|
||||
i++;
|
||||
if(i > 5) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Ds18b20WriteByte(uchar payload) {
|
||||
uint i, j;
|
||||
for(j = 0; j < 8; j++) {
|
||||
DSPORT = 0;
|
||||
i++;
|
||||
DSPORT = payload & 0x01;
|
||||
i = 6;
|
||||
while(i--);
|
||||
DSPORT = 1;
|
||||
payload >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
uchar Ds18b20ReadByte(void) {
|
||||
uchar byte, bi;
|
||||
uint i, j;
|
||||
for(j = 8; j > 0; j--) {
|
||||
DSPORT = 0;
|
||||
i++;
|
||||
DSPORT = 1;
|
||||
i++;
|
||||
i++;
|
||||
bi = DSPORT;
|
||||
byte = (byte >> 1) | (bi << 7);
|
||||
i = 4;
|
||||
while(i--);
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
void Ds18b20ChangTemp(void) {
|
||||
Ds18b20Init();
|
||||
Delay1ms(1);
|
||||
Ds18b20WriteByte(0xCC);
|
||||
Ds18b20WriteByte(0x44);
|
||||
}
|
||||
|
||||
void Ds18b20ReadTempCom() {
|
||||
Ds18b20Init();
|
||||
Delay1ms(1);
|
||||
Ds18b20WriteByte(0xCC);
|
||||
Ds18b20WriteByte(0xBE);
|
||||
}
|
||||
|
||||
int Ds18b20ReadTemp() {
|
||||
int temp = 0;
|
||||
uchar th, tl;
|
||||
Ds18b20ChangTemp();
|
||||
Ds18b20ReadTempCom();
|
||||
temp = th;
|
||||
temp <<= 8;
|
||||
temp |= tl;
|
||||
return temp;
|
||||
}
|
24
lib/peripheral/temp.h
Normal file
24
lib/peripheral/temp.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __TEMP_H
|
||||
#define __TEMP_H
|
||||
|
||||
#include <8052.h>
|
||||
|
||||
#ifndef uchar
|
||||
#define uchar unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef uint
|
||||
#define uint unsigned int
|
||||
#endif
|
||||
|
||||
#define DSPORT P3_7
|
||||
|
||||
void Delay1ms(uint y);
|
||||
uchar Ds18b20Init(void);
|
||||
void Ds18b20WriteByte(uchar com);
|
||||
uchar Ds18b20ReadByte(void);
|
||||
void Ds18b20ChangTemp(void);
|
||||
void Ds18b20ReadTempCom(void);
|
||||
int Ds18b20ReadTemp(void);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user