Wenn wir mal davon ausgehen, dass der Code funktioniert, ist für dich
nur das Header File interessant.
Einfach mal aufmachen und lesen.
Da steht
1 | ...
|
2 | // AVR clock frequency
|
3 | #ifndef F_CPU
|
4 | #define F_CPU 1000000UL // 1 MHz
|
5 | #endif
|
6 | ...
|
ist das für dich relevant.
Ja, doch. Ich würde sagen ja. Es sagt dir, dass du F_CPU korrekt setzen
musst. Persönlich bin ich davon abgekommen, F_CPU mit einem Default Wert
zu belegen, aber da es sich hier im vorhandenen Code handelt würde ich
den zunächst mal nicht zu sehr ändern und da die Taktfrequenz des
Prozessors eintragen.
Weiter
1 | ...
|
2 | // Pin defines
|
3 |
|
4 | #define DALLAS_PORT PORTB
|
5 | #define DALLAS_PORT_IN PINB
|
6 | #define DALLAS_DDR DDRB
|
7 | #define DALLAS_PIN 0
|
8 | ...
|
Oh ja.! Ich würde sagen das ist ja wohl sehr relevant. An welchem Pin
ist der 1820 angeschlossen. Also tragst du da deine Belegung ein.
1 | ...
|
2 | // The number of devices on the bus.
|
3 | #define DALLAS_NUM_DEVICES 1
|
4 | ...
|
wieviele Sensoren hast du angeschlossen?
Ab da kannst du dann den Rest überspringen, bis du bei
1 | ...
|
2 | ///////////////
|
3 | // Functions //
|
4 | ///////////////
|
5 |
|
6 | // Writes the LSB of the argument to the bus.
|
7 | void dallas_write(uint8_t);
|
8 |
|
9 | // Write a byte to the bus.
|
10 | void dallas_write_byte(uint8_t);
|
11 |
|
12 | // Write the specified number of bytes to the bus from the supplied buffer.
|
13 | void dallas_write_buffer(uint8_t * buffer, uint8_t buffer_length);
|
14 |
|
15 | // Read a bit from the bus and returns it as the LSB.
|
16 | uint8_t dallas_read(void);
|
17 |
|
18 | // Reads a byte from the bus.
|
19 | uint8_t dallas_read_byte(void);
|
20 |
|
21 | // Reads the specified number of bytes from the bus into the supplied buffer.
|
22 | void dallas_read_buffer(uint8_t * buffer, uint8_t buffer_length);
|
23 |
|
24 | // Resets the bus. Returns...
|
25 | // 1 - if a device or devices indicate presence
|
26 | // 0 - otherwise
|
27 | uint8_t dallas_reset(void);
|
28 |
|
29 | // Powers the bus from the AVR (max 40 mA).
|
30 | void dallas_drive_bus(void);
|
31 |
|
32 | // Sends a MATCH ROM command to the specified device. Automatically resets the
|
33 | // bus.
|
34 | void dallas_match_rom(DALLAS_IDENTIFIER_t *);
|
35 |
|
36 | // Sends a SKIP ROM command. Automatically resets the bus.
|
37 | void dallas_skip_rom(void);
|
38 |
|
39 | // Populates the identifier list. Returns...
|
40 | // 0 - if devices were found and there was no error
|
41 | // 1 - if there was a bus error
|
42 | // 2 - if there were more devices than specified by DALLAS_NUM_DEVICES
|
43 | uint8_t dallas_search_identifiers(void);
|
44 |
|
45 | // Returns the list of identifiers.
|
46 | DALLAS_IDENTIFIER_LIST_t * get_identifier_list(void);
|
angelangt bist.
Welche der Funktionen wirst du brauchen und wie wird das alles wohl
funktionieren. Lies die Funktionsnamen, lies die Beschreibungen, denk an
das Prinzip wie das wohl verwendet werden wird
1 | int main()
|
2 | {
|
3 | ...
|
4 |
|
5 | Initialisierung, d.h. auch feststellen welche Bausteine da sind
|
6 |
|
7 | while( 1 ) {
|
8 |
|
9 | Baustein auslesen
|
10 |
|
11 | Wert verarbeiten
|
12 | }
|
13 | }
|
und dann sollte sich eigentlich schon fast von alleine ergeben, welche
Funktionen du brauchst und wie sie angesteuert werden.
Und wenn nicht: ich bin mir fast sicher, dass dort, wo du den Code
gefunden hast, es auch ein Beispiel gibt, dass den Code in Aktion zeigt.
Also: im Header File die notwendigen Anpassungen machen, das C-File (und
das Header File) zum Projekt mit dazu nehmen (damit es auch compiliert
wird) und dein Programm schreiben.