Advertisement
Guest User

blinkledtimer

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /*
  2. * GccApplication12.c
  3. *
  4. * Created: 3/26/2019 4:59:06 PM
  5. * Author : dspuser
  6. */
  7. /*
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10.  
  11. void init_led(){
  12. DDRB |= 1<<0; //pb0 as output
  13. }
  14.  
  15. void led_toggle(){
  16. int k=0;
  17.  
  18. while (1) {
  19.  
  20. if(k%2){
  21. PORTB |= 1<<2; //led on
  22. k=0;
  23. }
  24. else{
  25. PORTB &= ~(1<<2); //led off
  26. k=1;
  27. }
  28. }
  29.  
  30. }
  31.  
  32.  
  33. int main(void)
  34. {
  35. init_led();
  36. init_timer();
  37.  
  38. while (1)
  39. {
  40. if(timer_match()){
  41. led_toggle();
  42. clear_flag();
  43. }
  44. }
  45. }*/
  46.  
  47. #include <avr/io.h>
  48.  
  49. #include <avr/interrupt.h>
  50.  
  51.  
  52.  
  53. volatile uint8_t count;
  54.  
  55. int main (void)
  56.  
  57. {
  58.  
  59. DDRB |= (1<<0); //PD6 as output
  60.  
  61. TCNT0 = 0;
  62.  
  63. count = 0;
  64.  
  65. TCCR0 |= (1<<CS02) | (1<<CS00); // PRESCALER 1024
  66.  
  67. TIMSK = (1<<TOIE0);
  68.  
  69. sei();
  70.  
  71. while(1) {}
  72.  
  73. }
  74.  
  75.  
  76.  
  77. ISR (TIMER0_OVF_vect)
  78.  
  79. {
  80.  
  81. if (count == 31)
  82.  
  83. {
  84.  
  85. PORTB ^= (1<<0);
  86.  
  87. count=0;
  88.  
  89. }
  90.  
  91. else
  92.  
  93. count++;
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement