4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
23 #include <avr/interrupt.h>
24 #include <avr/sleep.h>
26 // for linker, emulator, and programmer's sake
27 #include "avr_mcu_section.h"
28 AVR_MCU(F_CPU, "atmega48");
31 /* ------------------------------------------------------------------------- */
32 static int uart_putchar(char c, FILE *stream) {
34 uart_putchar('\r', stream);
35 loop_until_bit_is_set(UCSR0A, UDRE0);
40 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
45 volatile uint32_t tickCount;
47 ISR(TIMER2_COMPA_vect) // handler for Output Compare 1 overflow interrupt
58 // needs to do that before changing the timer registers
59 // ASYNC timer using a 32k crystal
61 TCCR2A = (1 << WGM21);
62 // use CLK/8 prescale value, clear timer/counter on compareA match
68 (clock/prescaler/hz)-1:63 -- */
70 TIMSK2 |= (1 << OCIE2A);
73 volatile uint8_t pressed = 0;
77 pressed = (PINC & (1 << PC0)) ? 0 : 1;
78 // wouldn't do that on real hardware, but it's a demo...
79 printf("PCINT1_vect %02x\n", PINC);
84 DDRB=0xff; // all PORT B output
85 DDRC = 0; // make PORT C input
86 // enable pin change interrupt for PORT C pin 0
87 PCMSK1 |= (1 << PCINT8); // C0
88 PCICR |= (1 << PCIE1);