Mercurial > ~darius > hgwebdir.cgi > sprink
comparison 1wire-config.h @ 1:be930b34fcd3
Make it compile, no testing yet.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 26 Jan 2015 23:04:09 +1030 |
parents | 93d4ddff7dd0 |
children |
comparison
equal
deleted
inserted
replaced
0:93d4ddff7dd0 | 1:be930b34fcd3 |
---|---|
1 /* | 1 /* |
2 * 1 wire header | 2 * Example configuration header for 1-wire bus code. |
3 * | 3 * |
4 * This is the user servicable stuff - how to do delays and how to | 4 * This is the user servicable stuff - how to do delays and how to |
5 * frob the IO pins. | 5 * frob the IO pins. |
6 * | 6 * |
7 * Copyright (c) 2004-2009 | 7 * Copyright (c) 2009 |
8 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. | 8 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
9 * | 9 * |
10 * Redistribution and use in source and binary forms, with or without | 10 * Redistribution and use in source and binary forms, with or without |
11 * modification, are permitted provided that the following conditions | 11 * modification, are permitted provided that the following conditions |
12 * are met: | 12 * are met: |
29 * SUCH DAMAGE. | 29 * SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 /* | 32 /* |
33 * Alter these for your configuration | 33 * Alter these for your configuration |
34 * | |
35 * The configuration described here has the 1-wire read on D3, | |
36 * a pulldown transistor on D4 and VPP controlled by D5. | |
34 */ | 37 */ |
35 | 38 |
36 #define OWBUSINIT() | 39 #include <avr/io.h> |
40 #include <avr/pgmspace.h> | |
41 #include <util/delay.h> | |
42 #include "cons.h" | |
37 | 43 |
38 /* Set the IO to input */ | 44 /* Initialise the DDR pins if necessary */ |
45 #define OWBUSINIT() do { \ | |
46 DDRD |= _BV(4); \ | |
47 DDRD &= ~_BV(3); \ | |
48 } while (0) | |
49 | |
50 /* Set the port up to allow reading from the 1 wire bus */ | |
39 #define OWSETREAD() \ | 51 #define OWSETREAD() \ |
40 do { \ | 52 do { \ |
41 __asm__ volatile ("" ::: "memory"); \ | |
42 DDRB &= ~_BV(0); \ | |
43 PORTB &= ~_BV(0); \ | |
44 __asm__ volatile ("" ::: "memory"); \ | |
45 } while (0) | 53 } while (0) |
46 | 54 |
55 | |
47 /* Read the 1-wire bus, non-inverting logic */ | 56 /* Read the 1-wire bus, non-inverting logic */ |
48 #define OWREADBUS() (PINB & _BV(0) ? 1 : 0) | 57 #define OWREADBUS() (PIND & _BV(3) ? 1 : 0) |
49 | 58 |
50 /* Set the 1-wire bus to 0 | 59 /* Set the 1-wire bus to 0 |
51 * Drive output low | 60 * Turns a transistor on to pull it low |
52 */ | 61 */ |
53 #define OWSETBUSLOW() \ | 62 #define OWSETBUSLOW() PORTD |= _BV(4) |
54 do { \ | |
55 __asm__ volatile ("" ::: "memory"); \ | |
56 DDRB |= _BV(0); \ | |
57 PORTB &= ~_BV(0); \ | |
58 __asm__ volatile ("" ::: "memory"); \ | |
59 } while (0) | |
60 | 63 |
61 /* Set the 1-wire bus to 1 | 64 /* Set the 1-wire bus to 1 |
62 * Allow to float, use pullup | 65 * Turn the transistor off to let the pullup do its job |
63 */ | 66 */ |
64 #define OWSETBUSHIGH() \ | 67 #define OWSETBUSHIGH() PORTD &= ~_BV(4) |
65 do { \ | 68 |
66 __asm__ volatile ("" ::: "memory"); \ | 69 /* Turn Vpp on (ie put +12V on the bus |
67 DDRB &= ~_BV(0); \ | 70 * This is optional, if it is undefined OWProgROM always fails */ |
68 __asm__ volatile ("" ::: "memory"); \ | 71 #define OWSETVPPON() PORTD |= _BV(5) |
69 } while (0) | 72 #define OWSETVPPOFF() PORTD &= ~_BV(5) |
70 | 73 |
71 /* _delay_us can only do a delay of 768/clock_freq */ | 74 /* _delay_us can only do a delay of 768/clock_freq */ |
72 #if F_CPU > 16000000 | 75 #if F_CPU > 16000000 |
73 #error F_CPU > 16MHz, delays need adjusting | 76 #error F_CPU > 16MHz, delays need adjusting |
74 #endif | 77 #endif |
82 #define OWDELAY_G /* 0 usec */ | 85 #define OWDELAY_G /* 0 usec */ |
83 #define OWDELAY_H do { _delay_us(48); _delay_us(48); _delay_us(48); \ | 86 #define OWDELAY_H do { _delay_us(48); _delay_us(48); _delay_us(48); \ |
84 _delay_us(48); _delay_us(48); _delay_us(48); _delay_us(48); \ | 87 _delay_us(48); _delay_us(48); _delay_us(48); _delay_us(48); \ |
85 _delay_us(48);_delay_us(48); _delay_us(48); } while (0) /* 480 usec */ | 88 _delay_us(48);_delay_us(48); _delay_us(48); } while (0) /* 480 usec */ |
86 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0) /* 70 usec */ | 89 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0) /* 70 usec */ |
90 #define OWDELAY_J do { _delay_us(41); _delay_us(41); _delay_us(41); \ | |
91 _delay_us(41); _delay_us(41); _delay_us(41); _delay_us(41); \ | |
92 _delay_us(41);_delay_us(41); _delay_us(41); } while (0) /* 410 usec */ | |
87 | 93 |
88 #ifdef OW_DEBUG | 94 #ifdef OW_DEBUG |
89 #define OWPUTS(x) puts_P(x) | 95 #define OWPUTS(x) puts_P(x) |
90 #define OWPUTSP(x) puts_P(x) | 96 #define OWPUTSP(x) puts_P(x) |
91 #define OWPRINTFP(fmt, ...) printf_P(fmt, ## __VA_ARGS__) | 97 #define OWPRINTFP(fmt, ...) printf_P(fmt, ## __VA_ARGS__) |
92 #else | 98 #else |
93 #define OWPUTS(x) | 99 #define OWPUTS(x) |
94 #define OWPUTSP(x) | 100 #define OWPUTSP(x) |
95 #define OWPRINTFP(fmt, ...) | 101 #define OWPRINTFP(fmt, ...) |
96 #endif | 102 #endif |
97 |