/* Title: CV test signal generator Author: Satoshi "Chuck" Takagi Date: Jan., 02, 2006 Jul., 22, 2006 Software: WinAvr Target: ATtiny2313 */ #include #include #include #include #define SW_SEL PB7 #define SW_OCT1 PB6 #define SW_OCT2 PB5 volatile struct { uint8_t cmd; uint8_t stat; uint8_t filt; } gCntl; SIGNAL(SIG_TIMER0_OVF) { uint8_t a, b; TCNT0 = 256 - 125; a = ~PINB & (_BV(SW_SEL)|_BV(SW_OCT1)|_BV(SW_OCT2)); if (a == gCntl.filt) { b = gCntl.stat; gCntl.stat = a; b = (b ^ a) & a; if (b) { gCntl.cmd = b; } } gCntl.filt = a; } void init_io(void) { DDRD = 0xff; // Port D output for LED PORTD = 0; DDRB = 0x1F; // Port B PB765 input for SW, PB2 output for OC0A PORTB = 0xE0; // timer0 TCCR0A = 0x00; // for timer1 setting TCCR0B = 0x03; // CS1[2:0] = 011b clk/64 TCNT0 = 256 - 125; TIMSK = (1< 5) ptr = 0; OCR1A = tbl[ptr].pwm; PORTD = tbl[ptr].led; gCntl.cmd = 0; } else if ( gCntl.stat & _BV(SW_OCT1) ) { OCR1A = tbl[ptr + 1].pwm; PORTD = tbl[ptr + 1].led; gCntl.cmd = 0; } else if ( gCntl.stat & _BV(SW_OCT2) ) { OCR1A = tbl[ptr + 2].pwm; PORTD = tbl[ptr + 2].led; gCntl.cmd = 0; } else { OCR1A = tbl[ptr].pwm; PORTD = tbl[ptr].led; } } }