Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Current setup (1000000UL) will result in delays longer than a minute. During testing I used TCNT1 > 5000 and if(extra_time == 1)
- * which resulted in 10 second delays before PORTD update.
- */
- #ifndef F_CPU
- #define F_CPU 1000000UL
- #endif
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- volatile int extra_time=0;
- volatile int num_presses=0;
- int main(void)
- {
- DDRD = 0b11111111;
- PORTD = 0b10000000;
- DDRB = 0b00000000;
- PORTB = 0b00000000;
- char button_state = 0;
- TCCR1B |= (1 << CS12) | (1 << CS10);
- while(1)
- {
- if (bit_is_clear(PINB, 0)) //button is pressed
- {
- if (button_state==0) //was previously not pressed)
- {
- num_presses++;
- }
- button_state=1;
- }
- else
- {
- if (button_state==1) //was previously pressed
- { }
- button_state=0;
- }
- if (TCNT1 >= 15625)
- {
- if (extra_time == 5 )
- {
- switch(num_presses)
- {
- case 0:
- PORTD = 0b10010000;
- break;
- case 1:
- PORTD = 0b10000000;
- break;
- case 2:
- PORTD = 0b01000000;
- break;
- case 3:
- PORTD = 0b11000000;
- break;
- case 4:
- PORTD = 0b00100000;
- break;
- case 5:
- PORTD = 0b10100000;
- break;
- default:
- PORTD =0b11110000;
- break;
- }
- extra_time = 0;
- num_presses = 0;
- }
- else
- {
- ++extra_time;
- }
- TCNT1 = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement