2012-09-20 20:55:19 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/interrupt.h>
|
2012-10-01 21:39:25 +02:00
|
|
|
#define __DELAY_BACKWARD_COMPATIBLE__
|
2012-09-20 20:55:19 +02:00
|
|
|
#include <util/delay.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
#define ever (;;)
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
#define follow(from_port, from_pin, to_port, to_pin) { if(from_port & (1 << from_pin)) to_port &= ~(1 << to_pin); else to_port |= 1 << to_pin; }
|
|
|
|
#define not_follow(from_port, from_pin, to_port, to_pin) { if(from_port & (1 << from_pin)) to_port |= 1 << to_pin; else to_port &= ~(1 << to_pin); }
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 04:15:23 +02:00
|
|
|
ISR(TIMER0_COMPA_vect) {
|
|
|
|
PORTD ^= 1 << 2;
|
|
|
|
}
|
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
int main(void) {
|
|
|
|
uint8_t vib_delay = 0;
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// init and stuff
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
PORTB |= (1 << 6) | (1 << 7);
|
|
|
|
PORTC |= (1 << 0) | (1 << 2) | (1 << 3);
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
DDRB |= (1 << 6) | (1 << 7);
|
|
|
|
DDRC |= (1 << 0) | (1 << 2) | (1 << 3);
|
|
|
|
DDRD |= (1 << 2) | (1 << 4);
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// pullups
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
PORTB |= (1 << 0) | (1 << 1) | (1 << 2);
|
|
|
|
PORTC |= (1 << 4) | (1 << 5);
|
2013-08-15 04:15:23 +02:00
|
|
|
PORTD |= (1 << 5) | (1 << 6) | (1 << 7);
|
|
|
|
|
2013-08-15 04:41:58 +02:00
|
|
|
// we need to get real fast (8MHz) to handle 38kHz IR frequency ...
|
2013-08-15 04:15:23 +02:00
|
|
|
|
2013-08-15 04:41:58 +02:00
|
|
|
CLKPR = 0b10000000;
|
|
|
|
CLKPR = 0b00000000;
|
2013-08-15 04:15:23 +02:00
|
|
|
|
|
|
|
// initialize timer
|
|
|
|
|
|
|
|
TIMSK0 |= (1 << OCIE0A);
|
2013-08-26 20:40:02 +02:00
|
|
|
OCR0A = 105;
|
2013-08-15 04:15:23 +02:00
|
|
|
|
|
|
|
// no prescaler
|
2012-09-24 19:45:51 +02:00
|
|
|
|
2013-08-15 04:15:23 +02:00
|
|
|
sei();
|
2012-09-24 19:45:51 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// looping
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
for ever {
|
2013-08-15 04:15:23 +02:00
|
|
|
// LED by button
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 04:15:23 +02:00
|
|
|
not_follow(PIND, 5, PORTD, 4);
|
|
|
|
|
|
|
|
// LED by IR
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
not_follow(PIND, 3, PORTC, 2);
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// vibration
|
2012-09-20 20:55:19 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
follow(PINC, 4, PORTB, 6);
|
2012-09-20 21:20:51 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// higher buzzer
|
2012-09-24 19:45:51 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
if(!(PINC & (1 << 5))) {
|
|
|
|
PORTB ^= 1 << 7;
|
|
|
|
} else {
|
|
|
|
PORTB &= ~(1 << 7);
|
2012-09-24 19:45:51 +02:00
|
|
|
}
|
2012-09-27 18:45:02 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// lower buzzer
|
2012-09-25 20:19:14 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
vib_delay ^= 1;
|
2012-09-25 20:19:14 +02:00
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
if(!(PIND & (1 << 7))) {
|
|
|
|
if(vib_delay) {
|
|
|
|
PORTC ^= 1 << 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PORTC &= ~(1 << 0);
|
2012-09-24 19:45:51 +02:00
|
|
|
}
|
2012-09-20 21:20:51 +02:00
|
|
|
|
2013-08-15 04:15:23 +02:00
|
|
|
// send IR
|
|
|
|
|
|
|
|
if(!(PIND & (1 << 6))) {
|
2013-08-26 20:40:02 +02:00
|
|
|
TCCR0A = (1 << WGM01);
|
2013-08-15 04:15:23 +02:00
|
|
|
TCCR0B = (1 << CS00);
|
|
|
|
} else {
|
|
|
|
TCCR0B = 0;
|
|
|
|
PORTD &= ~(1 << 2);
|
|
|
|
}
|
|
|
|
|
2013-08-15 02:12:41 +02:00
|
|
|
// wait
|
|
|
|
|
|
|
|
_delay_ms(1);
|
2012-09-20 20:55:19 +02:00
|
|
|
}
|
2013-08-15 02:12:41 +02:00
|
|
|
|
2012-09-20 20:55:19 +02:00
|
|
|
/* never return 0; */
|
2012-09-25 07:23:14 +02:00
|
|
|
return 0;
|
2012-09-20 20:55:19 +02:00
|
|
|
}
|