Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- int extratime=0;
- int num_presses=0;
- int main(void)
- {
- DDRD = 0b11111111;
- PORTD = 0b00000000;
- DDRB = 0b11110000;
- PORTB = 0b00000000;
- char button_state;
- 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)
- {
- PORTD = num_presses;
- extra_time = 0;
- }
- else
- {
- ++extra_time;
- }
- TCNT1 = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement