Bread board Challenge 2012
[BC12-03] IR Com Hotaru
#1 BASE-Module
(1) Parts
(2) Layout
(3) Schematic
1
E
A
ATTINY2313V
A
ATTINY2313V
IR-LED
LED3
LED1
(4) Firmware Source Code
// Infrared Communication Hotaru
// INT1 : Falling Edge Int. by Aux Input (Infrared Opt-Transistor) // PD0 : Buzzer
// PD1 : Aux.Signal Output ( InfraRed-LED) // PB0, PB1, PB2 : LED1,2,3 1:OFF 0:ON
#include <avr/io.h>
#include <avr/interrupt.h>
// Light Pattern ID #define P_STANDBY 0x00
#define P_SHIFT 0x01 #define P_BLINK 0x02
// Buzzer Control ID #define ON 0x01 #define OFF 0x00
// Initial Light Pattern
volatile int PATTERN = P_STANDBY;
void wait(volatile long i) {
while (i-- > 0); }
void buz(char c) // buzzer control {
switch (c) { case ON:
PORTD |= (1<<PD0); break;
case OFF:
PORTD &= ~(1<<PD0); break;
} }
void beep(int length, int height) // beep !
{
volatile long i, j;
for ( i = 0; i <length; i++) {
buz(ON);
for ( j = 0; j < height; j++); buz(OFF);
for ( j = 0; j < height; j++); }
}
void led(int led1, int led2, int led3) // led light on / off
// led1,2,3 : 0...OFF, 1...ON {
PORTB |= (1<<PB0) | (1<<PB1) | (1<<PB2) ;
PORTB &= ~( (led1<<PB0) | (led2<<PB1) | (led3<<PB2) ); }
void auxout(void)
// Output Auxiliary Signal {
PORTD |= (1<<PD1); wait(100); PORTD &= ~(1<<PD1); wait(10000); }
void pattern(int no) // Light Pattern Control {
int i;
switch (no) {
case P_SHIFT:
led(1, 0, 0); wait(10000); led(1, 1, 0); wait(10000); led(1, 1, 1); wait(10000); led(1, 1, 0); wait(10000); led(1, 0, 0); wait(10000); led(0, 0, 0); wait(10000); break;
case P_BLINK:
for ( i = 0; i < 3; i++) { led(0, 0, 0); wait(20000); led(1, 1, 1); wait(20000); }
break; default:
led(0, 0, 0); wait(200000); }
}
ISR(INT1_vect)
// Interrupt 1 : Arrival Auxiliary Signal from Another Module {
beep(50, 5); switch (PATTERN) {
case P_STANDBY:
PATTERN = P_SHIFT; break;
case P_SHIFT:
PATTERN = P_BLINK; break;
case P_BLINK:
PATTERN = P_SHIFT; break;
}
pattern(PATTERN); auxout();
}
int main(void) {
// Initialize I/O Port PORTD = 0xff;
DDRD = (1<<PD0) | (1<<PD1);
DDRB = (1<<PB0) | (1<<PB1) | (1<<PB2);
// Intialize Interrupt MCUCR |= (1<<ISC11); MCUCR &= ~(1<<ISC10); GIMSK |= (1<<INT1);
// STANDBY
led(1, 1, 1); wait(10000);
// Interrupt Enable sei();
// Start Sequence beep(400, 2); auxout(); while (1); return 0; }