Use Output Compare A for LED blinking

This commit is contained in:
Olaf Rempel 2006-05-26 17:35:21 +02:00
parent bfd813f22d
commit 465b0926f2
2 changed files with 10 additions and 12 deletions

View File

@ -69,4 +69,4 @@ esrec: $(PRG)_eeprom.srec
install: text install: text
# uisp -dprog=stk200 --erase --upload if=$(PRG).srec --verify # uisp -dprog=stk200 --erase --upload if=$(PRG).srec --verify
avrdude -p m16 -c butterfly -b 115200 -U flash:w:$(PRG).srec avrdude -p m16 -c butterfly -b 19200 -U flash:w:$(PRG).srec

View File

@ -51,7 +51,7 @@ uint8_t lastcmd = 0, lastval = 0, pollcode = 0xFF;
uint8_t page_buf[256]; uint8_t page_buf[256];
ISR(SIG_INPUT_CAPTURE1) ISR(SIG_OUTPUT_COMPARE1A)
{ {
// toggle LED // toggle LED
PORTB ^= (1<<PORTB3); PORTB ^= (1<<PORTB3);
@ -103,19 +103,17 @@ void led_mode(uint8_t mode)
} else if (mode == LED_FAST) { } else if (mode == LED_FAST) {
// 100ms reload // 100ms reload
ICR1H = 0x2D; OCR1A = 0x2D00;
ICR1L = 0x00;
// timer1 prescaler 64, CTC mode via Input Capture // timer1 prescaler 64, CTC mode via OutputCompare A
TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS11) | (1<<CS10); TCCR1B = (1<<WGM12) | (1<<CS11) | (1<<CS10);
} else if (mode == LED_SLOW) { } else if (mode == LED_SLOW) {
// 250ms reload // 250ms reload
ICR1H = 0x70; OCR1A = 0x7080;
ICR1L = 0x80;
// timer1 prescaler 64, CTC mode via Input Capture // timer1 prescaler 64, CTC mode via OutputCompare A
TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS11) | (1<<CS10); TCCR1B = (1<<WGM12) | (1<<CS11) | (1<<CS10);
} }
oldmode = mode; oldmode = mode;
} }
@ -212,8 +210,8 @@ int main(void)
// SPI enabled, Master mode, F_OSC/4 // SPI enabled, Master mode, F_OSC/4
SPCR = (1<<SPE) | (1<<MSTR); SPCR = (1<<SPE) | (1<<MSTR);
// enable timer1 input capture interrupt (CTC hit) // enable timer1 OutputCompare A interrupt (CTC hit)
TIMSK = (1<<TICIE1); TIMSK = (1<<OCIE1A);
sei(); sei();
// disable reset // disable reset