Advertisement
Guest User

Untitled

a guest
Oct 28th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. void setup()
  2. {
  3.     DDRB |= 0x01;  //pin D8 is output for LED
  4.     TCCR1A = 0x00; //normal timer1 operation
  5.     TCCR1B = 0x00; // "
  6.     TCCR1B |= (1 << CS12); //prescalar set to 256, 256/16E6 = 16 us per timer count
  7. }
  8.  
  9. void loop()
  10. {
  11.   TCNT1 = 0;
  12.   while(PINB & 0x02) //while pin D9 is high
  13.   {  
  14.     if(TCNT1 >= 31250) //16us * 31250 = 500 ms elapsed
  15.     {
  16.       if(PINB & 0x01)  //toggle LED
  17.       {
  18.         PORTB &= ~0x01;  //led off
  19.       }else
  20.        {
  21.         PORTB |= 0x01;  //led on
  22.        }
  23.      TCNT1 = 0;  //reset timer to 0
  24.     }
  25.   }
  26.   PORTB &= ~0x01;  //led off
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement