Advertisement
Guest User

MS/LAB3/PRB1/FINAL

a guest
Mar 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. /*
  2. * GccApplication7.c
  3. *
  4. * Created: 3/26/2019 3:59:00 PM
  5. * Author : dspuser
  6. */
  7. MAINNNN
  8.  
  9. #include <avr/io.h>
  10. #include <avr/interrupt.h>
  11. #include "timer.h"
  12. int count=0;
  13. //TIFR=0;
  14. void led_toggle(){
  15. if(count%2){
  16. PORTB |= 1<<1;//aprind LED1;
  17. }
  18. else
  19. PORTB &= ~(1<<1);
  20. count++;
  21. }
  22. void init_led(){
  23. DDRB|=(1<<1);//setam PB1 as output ca sa se aprinda primul led
  24. }
  25. int main(void)
  26. {
  27. init_led();
  28. timer_init();
  29. while(1)
  30. {
  31. if (((TIFR & (1 << 4)) != 0))
  32. {
  33. // compare match on channel 1 has occurred
  34. led_toggle();
  35. TIFR |= 1 << 4; // reset flag
  36. }
  37. }
  38. // some code
  39. }
  40.  
  41.  
  42. TIMEEEEEEEEEEEER
  43.  
  44. /*
  45. * timer.c
  46. *
  47. * Created: 3/26/2019 4:04:07 PM
  48. * Author: dspuser
  49. */
  50.  
  51. #include <avr/io.h>
  52. #include "timer.h"
  53.  
  54. void timer_init()
  55. {
  56.  
  57. OCR1AH = (value >> 8) & 0xFF;
  58. OCR1AL = (value & 0xFF);
  59. //set interrupt on compare match
  60. TCCR1B |= (1<<CS12)|(1 << WGM12);//mode 4, Mode of Operation CTC, 0100,prescalar 256,
  61. //sei(); //enable interrupts
  62. }
  63.  
  64.  
  65. HEAAAAAAAAAAAADER
  66. /*
  67. * timer.h
  68. *
  69. * Created: 3/26/2019 4:04:23 PM
  70. * Author: dspuser
  71. */
  72. void timer_init();
  73. #ifndef F_CPU
  74. #define F_CPU 14745600
  75. #endif
  76. #ifndef value
  77. #define value 0x7080
  78. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement