fork download
  1. /*
  2. * Hackaday.com AVR Tutorial firmware
  3. * written by: Mike Szczys (@szczys)
  4. * 10/24/2010
  5. *
  6. * ATmega168
  7. * Blinks one LED conneced to PD0
  8. *
  9. * http://h...content-available-to-author-only...y.com/2010/10/25/avr-programming-02-the-hardware/
  10. */
  11.  
  12. #include <avr/io.h>
  13. #include <avr/interrupt.h>
  14.  
  15. int main(void)
  16. {
  17.  
  18. //Setup the clock
  19. cli(); //Disable global interrupts
  20. TCCR1B |= 1<<CS11 | 1<<CS10; //Divide by 64
  21. OCR1A = 15624; //Count 15624 cycles for 1 second interrupt
  22. TCCR1B |= 1<<WGM12; //Put Timer/Counter1 in CTC mode
  23. TIMSK1 |= 1<<OCIE1A; //enable timer compare interrupt
  24. sei(); //Enable global interrupts
  25.  
  26. //Setup the I/O for the LED
  27.  
  28. DDRD |= 0xff; //(1<<0); //Set PortD Pin0 as an output
  29. PORTD = 0xff; //(1<<0); //Set PortD Pin0 high to turn on LED
  30.  
  31. while(1) { } //Loop forever, interrupts do the rest
  32. }
  33.  
  34. ISR(TIMER1_COMPA_vect) //Interrupt Service Routine
  35. {
  36. static uint8_t val = 0;
  37. val ++;
  38.  
  39. PORTD = ~val; // (1<<0); //Use xor to toggle the LED
  40. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty