1 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
\r
2 // All rights reserved.
\r
4 // Redistribution and use in source and binary forms, with or without
\r
5 // modification, are permitted provided that the following conditions are
\r
8 // * Redistributions of source code must retain the above copyright
\r
9 // notice, this list of conditions and the following disclaimer.
\r
10 // * Redistributions in binary form must reproduce the above copyright
\r
11 // notice, this list of conditions and the following disclaimer in the
\r
12 // documentation and/or other materials provided with the
\r
14 // * All advertising materials mentioning features or use of this
\r
15 // software must display the following acknowledgement: This product
\r
16 // includes software developed by tm3d.de and its contributors.
\r
17 // * Neither the name of tm3d.de nor the names of its contributors may
\r
18 // be used to endorse or promote products derived from this software
\r
19 // without specific prior written permission.
\r
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
33 //!!!!!Max Program size 7551 Byte
\r
35 #define F_CPU 8000000UL
\r
37 #include <avr/interrupt.h>
\r
38 #include <util/delay.h>
\r
39 #include <avr/wdt.h>
\r
40 #include <avr/sleep.h>
\r
41 #include <avr/pgmspace.h>
\r
42 #include "../common/owSlave_tools.h"
\r
45 //#define FHEM_PLATINE
\r
48 volatile uint8_t owid1[8]={0x3A, 0x01, 0xDA, 0x84, 0x00, 0x00, 0x05, 0xA3};/**/
\r
49 volatile uint8_t owid2[8]={0x3A, 0x02, 0xDA, 0x84, 0x00, 0x00, 0x05, 0xFA};/**/
\r
50 uint8_t config_info1[26]={0,0,0,0,0,0,0,0,0x02,0,0,0,0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //+2 for CRC
\r
51 uint8_t config_info2[26]={0,0,0,0,0,0,0,0,0x02,0,0,0,0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //+2 for CRC
\r
54 #error "Variable not correct"
\r
67 #if defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__)
\r
68 #define PCINT_VECTOR PCINT0_vect
\r
69 #define PIN_REG PINA
\r
70 #define PIN_DDR DDRA
\r
73 #define PIN_PIOA1 (1<<PINA2)
\r
74 #define PIN_PIOB1 (1<<PINA1)
\r
75 #define PIN_PIOA2 (1<<PINA3)
\r
76 #define PIN_PIOB2 (1<<PINA4)
\r
77 //LEDS
\r#define LPIN_CH2 (1<<PINB0)
\r#define LDD_CH2 DDRB
\r#define LPORT_CH2 PORTB
\r#define LPIN_CH3 (1<<PINA5)
\r#define LDD_CH3 DDRA
\r#define LPORT_CH3 PORTA
\r#define LPIN_CH0 (1<<PINA7)
\r#define LDD_CH0 DDRA
\r#define LPORT_CH0 PORTA
\r#define LPIN_CH1 (1<<PINB1)
\r#define LDD_CH1 DDRB
\r#define LPORT_CH1 PORTB
\r
79 #define LED2_ON LPORT_CH2|=LPIN_CH2;
\r
84 #define PIN_PIOA1 (1<<PINA4)
\r
85 #define PIN_PIOB1 (1<<PINA5)
\r
86 #define PIN_PIOA2 (1<<PINA6)
\r
87 #define PIN_PIOB2 (1<<PINA7)
\r
91 #define PIN_PIOB1 (1<<PINA1)
\r
92 #define PIN_PIOA1 (1<<PINA0)
\r
93 #define PIN_PIOB2 (1<<PINA7)
\r
94 #define PIN_PIOA2 (1<<PINA3)
\r
95 //LEDS
\r#define LPIN_CH0 (1<<PINB1)
\r#define LDD_CH0 DDRB
\r#define LPORT_CH0 PORTB
\r#define LPIN_CH1 (1<<PINB1)
\r#define LDD_CH1 DDRB
\r#define LPORT_CH1 PORTB
\r#define LPIN_CH2 (1<<PINB1)
\r#define LDD_CH2 DDRB
\r#define LPORT_CH2 PORTB
\r#define LPIN_CH3 (1<<PINB1)
\r#define LDD_CH3 DDRB
\r#define LPORT_CH3 PORTB
\r\r
96 #define LED2_ON LPORT_CH2&=~LPIN_CH2;
\r
105 // if (((PIN_REG&PIN_CH2)==0)&&((istat&PIN_CH2)==PIN_CH2)) { counters1.c32[2]++; LED2_ON}
\r
106 //if (((PIN_REG&PIN_CH3)==0)&&((istat&PIN_CH3)==PIN_CH3)) { counters1.c32[3]++;LED2_ON }
\r
107 if ((PIN_REG&PIN_PIOA1)==0) {pin_state1&=~0x1;LED2_ON} else { pin_state1|=0x01;}
\r
108 if ((PIN_REG&PIN_PIOB1)==0) {pin_state1&=~0x4;LED2_ON} else {pin_state1|=0x04;}
\r
109 if ((PIN_REG&PIN_PIOA2)==0) {pin_state2&=~0x1;LED2_ON} else {pin_state2|=0x01;}
\r
110 if ((PIN_REG&PIN_PIOB2)==0) {pin_state2&=~0x4;LED2_ON} else {pin_state2|=0x04;}
\r
111 //Reset Switch on the FHEM_BOARD
\r
112 GIFR|=(1<<PCIF0);
\r\r\r\r
124 #if defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__)
\r
128 #ifndef _CPULLUP_ // pullup
\r
129 PORTA&=~(PIN_PIOA1|PIN_PIOB1);
\r
130 PORTA&=~(PIN_PIOA2|PIN_PIOB2);
\r
133 #ifdef FHEM_PLATINE //LEDs
\r
134 LDD_CH0|=LPIN_CH0;
\r LPORT_CH0&=~LPIN_CH0;
\r LDD_CH1|=LPIN_CH1;
\r LPORT_CH1&=~LPIN_CH1;
\r LDD_CH2|=LPIN_CH2;
\r LPORT_CH2&=~LPIN_CH2;
\r LDD_CH3|=LPIN_CH3;
\r LPORT_CH3&=~LPIN_CH3;
\r
137 LDD_CH2|=LPIN_CH2;
\r LPORT_CH2&=~LPIN_CH2;
\r#endif
\r
141 PCMSK0=(PIN_PIOA1|PIN_PIOB1|PIN_PIOA2|PIN_PIOB2); //Nicht ganz korrekt aber die Bits liegen gleich
\r
150 #ifdef FHEM_PLATINE
\r
152 LPORT_CH0|=LPIN_CH0;
\r _delay_ms(500);
\r LPORT_CH0&=~LPIN_CH0;
\r
162 DDRA&=~(PIN_PIOA1); //Eingang
\r
163 PORTA|=(PIN_PIOA1); //Pullup
\r
166 DDRA|=(PIN_PIOA1); //Ausgang
\r
167 PORTA&=~(PIN_PIOA1); //Gegen masse
\r
172 DDRA&=~(PIN_PIOB1); //Eingang
\r
173 PORTA|=(PIN_PIOB1); //Pullup
\r
175 DDRA|=(PIN_PIOB1); //Ausgang
\r
176 PORTA&=~(PIN_PIOB1); //Gegen masse
\r
181 DDRA&=~(PIN_PIOA2); //Eingang
\r
182 PORTA|=(PIN_PIOA2); //Pullup
\r
184 DDRA|=(PIN_PIOA2); //Ausgang
\r
185 PORTA&=~(PIN_PIOA2); //Gegen masse
\r
189 DDRA&=~(PIN_PIOB2); //Eingang
\r
190 PORTA|=(PIN_PIOB2); //Pullup
\r
193 DDRA|=(PIN_PIOB2); //Ausgang
\r
194 PORTA&=~(PIN_PIOB2); //Gegen masse
\r
197 #ifdef FHEM_PLATINE
\r
198 if (LPORT_CH2&LPIN_CH2) {
\r _delay_ms(50);
\r LPORT_CH2&=~LPIN_CH2;
\r }
\r
199 if (LPORT_CH1&LPIN_CH1) {
\r _delay_ms(50);
\r LPORT_CH1&=~LPIN_CH1;
\r }
\r
202 if ((LPORT_CH2&LPIN_CH2)==0) {
\r _delay_ms(50);
\r LPORT_CH2|=LPIN_CH2;
\r }
\r