1-write

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#asm
.equ __w1_port=0x08 ;PORTC
.equ __w1_bit=6
#endasm
#include <1wire.h>
#include <mega168.h>
#include <stdio.h>
#define DS1990_FAMILY_CODE 1
#define DS2405_FAMILY_CODE 5
#define DS1822_FAMILY_CODE 0x22
#define DS2430_FAMILY_CODE 0x14
#define DS1990_FAMILY_CODE 1
#define DS2431_FAMILY_CODE 0x2d
#define DS18S20_FAMILY_CODE 0x10
#define DS2433_FAMILY_CODE 0x23
#define SEARCH_ROM 0xF0
#define MAX_DEVICES 8
unsigned char rom_code[MAX_DEVICES,9];
void main() {
unsigned char i,j,devices;
unsigned char n=1;
// init UART
//UCR=8;
//UBRR=23; // Baud=9600 @ 3.6864MHz
// print welcome message
printf("1-Wire MicroLan Net demo\n\r");
// detect how many 1 Wire devices are present on the bus
devices=w1_search(SEARCH_ROM,&rom_code[0,0]);
printf("%u device(s) found\n\r",devices);
for (i=0;i<devices;i++)
{
// Acknowledge DS1990 family code.
if (rom_code[i,0]==DS1990_FAMILY_CODE)
printf("DS1990 #%u serial number:",n++);
// Acknowledge DS2405s family code.
else if (rom_code[i,0]==DS2405_FAMILY_CODE)
printf("DS2405 #%u serial number:",n++);
// Acknowledge DS1822s family code.
else if (rom_code[i,0]==DS1822_FAMILY_CODE)
printf("DS1822 #%u serial number:",n++);
// Acknowledge DS2430s family code.
else if (rom_code[i,0]==DS2430_FAMILY_CODE)
printf("DS2430 #%u serial number:",n++);
// Acknowledge DS18S20s family code.
else if (rom_code[i,0]==DS18S20_FAMILY_CODE)
printf("DS18S20 #%u serial number:",n++);
// Acknowledge DS2431 family code.
else if (rom_code[i,0]==DS2431_FAMILY_CODE)
printf("DS2431 #%u serial number:",n++);
// Acknowledge DS2433 family code.
else if (rom_code[i,0]==DS2433_FAMILY_CODE)
printf("DS2433 #%u serial number:",n++);
for (j=1;j<=6;j++)
printf(" %02X",rom_code[i,j]);
printf("\n\r");
}
}