Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup()
- {
- DDRB |= 0x01; //pin D8 is output for LED
- TCCR1A = 0x00; //normal timer1 operation
- TCCR1B = 0x00; // "
- TCCR1B |= (1 << CS12); //prescalar set to 256, 256/16E6 = 16 us per timer count
- }
- void loop()
- {
- TCNT1 = 0;
- while(PINB & 0x02) //while pin D9 is high
- {
- if(TCNT1 >= 31250) //16us * 31250 = 500 ms elapsed
- {
- if(PINB & 0x01) //toggle LED
- {
- PORTB &= ~0x01; //led off
- }else
- {
- PORTB |= 0x01; //led on
- }
- TCNT1 = 0; //reset timer to 0
- }
- }
- PORTB &= ~0x01; //led off
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement