Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cezary Zaprawa
- //Jedna dioda swieci 500/2000ms
- //Co kliknięcie przycisku animacja jest wykonywana na kolejnych diodach
- //Częstotliwość: 1MHz
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #define BUTTON_MASK (1<<PD2)
- #define BUTTON_PIN PIND
- #define BUTTON_PORT PORTD
- volatile uint8_t button_down;
- volatile int int0Counter = 1;
- volatile uint8_t counterHolder = 1;
- ISR(TIMER0_OVF_vect) {
- static uint8_t count = 0;
- static uint8_t button_state = 0;
- uint8_t current_state = (~BUTTON_PIN & BUTTON_MASK) != 0;
- if (current_state != button_state) {
- count++;
- if (count >= 4) {
- button_state = current_state;
- if (current_state != 0)
- button_down = 1;
- count = 0;
- }
- } else {
- count = 0;
- }
- }
- ISR(INT0_vect) {
- if(button_down) {
- if(counterHolder != 255) {
- int0Counter *= 2;
- } else {
- int0Counter = 1;
- counterHolder = 1;
- }
- counterHolder |= int0Counter;
- }
- }
- ISR(TIMER1_COMPA_vect) {
- PORTA = 0;
- }
- ISR(TIMER1_OVF_vect) {
- PORTA |= counterHolder;
- }
- void init() {
- cli();
- //+++Konfiguracja wyświetlaczy+++
- DDRA |= 0xFF;
- DDRB |= 0xFF;
- //+++Konfiguracja przerwania INT0+++
- PORTD |= (1 << PD2);
- MCUCR |= (1 << ISC01);
- GICR |= (1 << INT0);
- //+++Konfiguracja timera0+++
- TCCR0 |= (1 << WGM01);
- TIMSK |= (1 << TOIE0);
- OCR0 = 98;
- //+++Konfiguracja Timera1+++
- OCR1A = 7813;
- ICR1 = 31250;
- TCCR1B |= (1 << WGM12) | (1 << WGM13);
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << CS11) | (1 << CS10);
- TIMSK |= (1 << OCIE1A) | (1 << TOIE1);
- sei();
- }
- int main(void) {
- init();
- while(1) {
- PORTB = TCNT0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement