-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·70 lines (64 loc) · 1.45 KB
/
main.c
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
65
66
67
68
69
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>
#define TRANS_PIN PB3
#include "rc.h"
#define INPUT_PIN PB4
#define SWITCH_ID "100010100111100010011010"
unsigned n;
volatile char state;
static void config_hardware(void) {
// disable interrupts globally
cli();
//power reduction
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
// turn off peripherals not in use
PRR |= _BV(PRUSI) | _BV(PRADC);
// Configure TRANS_PIN as output
DDRB |= (1 << TRANS_PIN);
// Set INPUT_PIN as Input
DDRB &= ~(1 << INPUT_PIN);
// Enable PCINT0 (PB0) and PCINT1 (PB1) interrupt / triggers PCINT0_vect
PCMSK |= (1<<PCINT4);
// Set TRANS_PIN low
PORTB &= ~(1 << TRANS_PIN);
/* crude delay to allow PIR sensor to initialize */
n = 0;
while (n <= 9)
{
_delay_ms(5000);
n++;
}
// pin change interrupt
GIMSK |= (1<<PCIE);
// turn on interrupts / GLORY time!!
sei();
}
int main(void)
{
config_hardware();
while (1){
sleep_mode();
}
}
ISR (PCINT0_vect)
{
//if( !(PINB & (1 << INPUT_PIN)) ) {
// state = 1;
//}
//} else if ( !(PINB & (1 << INPUT_PIN1)) ) {
// state = 0;
//}
//byte counter =0x00;
//byte data = 0x10 | (++counter & 0x0F);
cli();
n = 0;
while (n <= 9)
{
// _delay_ms(1000);
sendStream();
n++;
}
sei();
}