git-svn-id: https://svn.salfter.gotdns.org/svn/a2bfc/trunk@83 1b90f75b-8b96-4784-87c0-14078182fce6
This commit is contained in:
3
main.c
3
main.c
@@ -6,6 +6,7 @@
|
|||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
unsigned char devid[8]={40,12,203,62,0,0,0,108};
|
unsigned char devid[8]={40,12,203,62,0,0,0,108};
|
||||||
|
short i;
|
||||||
|
|
||||||
// activate temperature sensor
|
// activate temperature sensor
|
||||||
if (ow_reset())
|
if (ow_reset())
|
||||||
@@ -18,6 +19,8 @@ int main (void)
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
for (i=0; i<500; i++)
|
||||||
|
ow_mswait();
|
||||||
printf("%i deg F\n", ow_temp_read(devid, OW_TEMP_FAHRENHEIT));
|
printf("%i deg F\n", ow_temp_read(devid, OW_TEMP_FAHRENHEIT));
|
||||||
}
|
}
|
||||||
while (!kbhit());
|
while (!kbhit());
|
||||||
|
|||||||
11
ow-apple2.s
11
ow-apple2.s
@@ -5,6 +5,7 @@
|
|||||||
.export _ow_read_impl
|
.export _ow_read_impl
|
||||||
.export _ow_reset_impl
|
.export _ow_reset_impl
|
||||||
.export _ow_wait_impl
|
.export _ow_wait_impl
|
||||||
|
.export _ow_mswait_impl
|
||||||
|
|
||||||
; timing loops assume standard ~1 MHz speed for unaccelerated
|
; timing loops assume standard ~1 MHz speed for unaccelerated
|
||||||
; 8-bit Apple IIs
|
; 8-bit Apple IIs
|
||||||
@@ -100,3 +101,13 @@ _ow_wait_impl:
|
|||||||
: bit PB2
|
: bit PB2
|
||||||
bpl :-
|
bpl :-
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; wait 1 ms
|
||||||
|
_ow_mswait_impl:
|
||||||
|
ldy #100 ;100*10=1000 us=1 ms
|
||||||
|
: nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
dey
|
||||||
|
bne :-
|
||||||
|
rts
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
.export _ow_readbyte
|
.export _ow_readbyte
|
||||||
.export _ow_reset
|
.export _ow_reset
|
||||||
.export _ow_wait
|
.export _ow_wait
|
||||||
|
.export _ow_mswait
|
||||||
|
|
||||||
; provided by system-specific routines at link time
|
; provided by system-specific routines at link time
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
.import _ow_read_impl
|
.import _ow_read_impl
|
||||||
.import _ow_reset_impl
|
.import _ow_reset_impl
|
||||||
.import _ow_wait_impl
|
.import _ow_wait_impl
|
||||||
|
.import _ow_mswait_impl
|
||||||
|
|
||||||
.bss
|
.bss
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ owtmp: .res 1
|
|||||||
_ow_send1 := _ow_send1_impl
|
_ow_send1 := _ow_send1_impl
|
||||||
_ow_send0 := _ow_send0_impl
|
_ow_send0 := _ow_send0_impl
|
||||||
_ow_wait := _ow_wait_impl
|
_ow_wait := _ow_wait_impl
|
||||||
|
_ow_mswait := _ow_mswait_impl
|
||||||
|
|
||||||
; reset bus: return 0 if 1-Wire devices present, 1 otherwise
|
; reset bus: return 0 if 1-Wire devices present, 1 otherwise
|
||||||
|
|
||||||
|
|||||||
26
ow-temp.c
26
ow-temp.c
@@ -2,21 +2,26 @@
|
|||||||
|
|
||||||
short ow_temp_read(unsigned char* devid, unsigned char format)
|
short ow_temp_read(unsigned char* devid, unsigned char format)
|
||||||
{
|
{
|
||||||
unsigned char t1, t2;
|
unsigned char data[8];
|
||||||
short rawtemp;
|
short rawtemp;
|
||||||
|
unsigned char i;
|
||||||
|
|
||||||
if (devid[0]!=40)
|
if (devid[0]!=40)
|
||||||
return OW_ERR_INVALIDDEVICE;
|
return OW_ERR_INVALIDDEVICE;
|
||||||
ow_selectdevice(devid);
|
do
|
||||||
ow_writebyte(68); // ask for a temperature reading
|
{
|
||||||
ow_wait(); // wait for operation to complete
|
ow_selectdevice(devid);
|
||||||
ow_selectdevice(devid);
|
ow_writebyte(68); // ask for a temperature reading
|
||||||
ow_writebyte(190); // retrieve the reading
|
ow_wait(); // wait for operation to complete
|
||||||
t1=ow_readbyte();
|
ow_selectdevice(devid);
|
||||||
t2=ow_readbyte();
|
ow_writebyte(190); // retrieve the reading
|
||||||
ow_reset();
|
for (i=0; i<8; i++)
|
||||||
|
data[i]=ow_readbyte();
|
||||||
|
ow_mswait();
|
||||||
|
}
|
||||||
|
while (ow_crc(data,8)!=0); // repeat until we get a valid reading
|
||||||
|
|
||||||
rawtemp=(short)(t1+((int)t2<<8));
|
rawtemp=(short)(data[0]+((int)data[1]<<8));
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case OW_TEMP_FAHRENHEIT:
|
case OW_TEMP_FAHRENHEIT:
|
||||||
@@ -28,3 +33,4 @@ short ow_temp_read(unsigned char* devid, unsigned char format)
|
|||||||
return rawtemp;
|
return rawtemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "ow.h"
|
#include "ow.h"
|
||||||
|
|
||||||
// 1-Wire temperature sensor functions
|
// 1-Wire temperature sensor functions
|
||||||
|
// (works with DS18B20; unknown if it'll work with others)
|
||||||
|
|
||||||
short ow_temp_read(unsigned char* devid, unsigned char format);
|
short ow_temp_read(unsigned char* devid, unsigned char format);
|
||||||
|
|
||||||
|
|||||||
31
ow.c
31
ow.c
@@ -1,5 +1,25 @@
|
|||||||
#include "ow.h"
|
#include "ow.h"
|
||||||
|
|
||||||
|
unsigned char ow_crc_lookup[256]=
|
||||||
|
{
|
||||||
|
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
|
||||||
|
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
|
||||||
|
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
|
||||||
|
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
|
||||||
|
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
|
||||||
|
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
|
||||||
|
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
|
||||||
|
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
|
||||||
|
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
|
||||||
|
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
|
||||||
|
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
|
||||||
|
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
|
||||||
|
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
|
||||||
|
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
|
||||||
|
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
|
||||||
|
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
|
||||||
|
};
|
||||||
|
|
||||||
void ow_selectdevice(unsigned char* devid)
|
void ow_selectdevice(unsigned char* devid)
|
||||||
{
|
{
|
||||||
ow_reset();
|
ow_reset();
|
||||||
@@ -14,3 +34,14 @@ void ow_selectdevice(unsigned char* devid)
|
|||||||
ow_writebyte(devid[7]);
|
ow_writebyte(devid[7]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char ow_crc(unsigned char* data, unsigned char len)
|
||||||
|
{
|
||||||
|
unsigned char crc=0;
|
||||||
|
unsigned char i;
|
||||||
|
|
||||||
|
for (i=0; i<len; i++)
|
||||||
|
crc^=ow_crc_lookup[data[i]];
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
2
ow.h
2
ow.h
@@ -9,10 +9,12 @@ unsigned char __fastcall__ ow_readbit(void);
|
|||||||
unsigned char __fastcall__ ow_readbyte(void);
|
unsigned char __fastcall__ ow_readbyte(void);
|
||||||
unsigned char __fastcall__ ow_reset(void);
|
unsigned char __fastcall__ ow_reset(void);
|
||||||
void __fastcall__ ow_wait(void);
|
void __fastcall__ ow_wait(void);
|
||||||
|
void __fastcall__ ow_mswait(void);
|
||||||
|
|
||||||
// common C routines in ow.c
|
// common C routines in ow.c
|
||||||
|
|
||||||
void ow_selectdevice(unsigned char* devid);
|
void ow_selectdevice(unsigned char* devid);
|
||||||
|
unsigned char ow_crc(unsigned char* data, unsigned char len);
|
||||||
|
|
||||||
// common 1-Wire constants
|
// common 1-Wire constants
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user