Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include <avr/sleep.h>
- #define LED PB0
- #define LED_PORT PORTB
- #define LED_DDR DDRB
- #define BUTTON PD2
- #define BUTTON_PIN PIND
- #define BUTTON_PORT PORTD
- #define LED_ON() do {(LED_PORT |= _BV(LED)); } while(0)
- #define LED_OFF() do {(LED_PORT &= ~_BV(LED)); } while(0)
- #define BUTTON_ON() bit_is_clear(BUTTON_PIN, BUTTON)
- void initTimer(void) {
- //timer1
- TCCR1B |= (1 << WGM12); // TC1 CTC top at OCR1A
- TCCR1B |= (1 << CS11) ; //cpu/8
- // initialize counter
- TCNT1 = 0;
- // initialize compare value (10ms)
- OCR1A = 19999;
- // enable compare interrupt
- TIMSK1 |= (1 << OCIE1A);
- // enable global interrupts
- sei();
- }
- volatile uint8_t bufor[100] = {0};
- volatile uint8_t index = 0;
- ISR (TIMER1_COMPA_vect)
- {
- LED_OFF();
- if (bufor[index])
- {
- LED_ON();
- bufor[index] = 0;
- }
- if (BUTTON_ON())
- bufor[index] = 1;
- if (index == 99)
- index = 0;
- index++;
- }
- int main()
- {
- //sleep mode select - IDLE
- set_sleep_mode(SLEEP_MODE_IDLE);
- //port setup
- LED_DDR = (1 << LED);
- BUTTON_PORT |= (1 << BUTTON);
- initTimer();
- while (1)
- {
- sleep_mode();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement