Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. /* Michał Grzegorczyk sprawozdanie- timer.
  2. */
  3.  
  4. //Zadanie 1. Tryb normal (odczyt flagi TOV0)
  5.  
  6. /*
  7. #include <avr/io.h>
  8.  
  9. #define LED1 (1<<PA7) //definicja LED1, podłączonego do pinu PA7
  10.  
  11. void timer0()
  12. {
  13. TCCR0 |= (1<<CS00); //Ustawienie timera bez preskalera
  14. TCNT0=0; //ustawienie countera
  15. }
  16.  
  17. void main(void)
  18. {
  19. DDRA |= LED1; //Ustawienie pinu sterującego diodą jako wyjście
  20. timer0(); //Ustawienie timera
  21. while(1)
  22. {
  23. if(TCNT0>=243)
  24. {
  25. PORTA ^= LED1;
  26. TCNT0=0;
  27. }
  28. }
  29. }
  30. */
  31.  
  32.  
  33. //Zadanie 1b. tryb ctc
  34. #include <avr/io.h>
  35. #define LED1 (1<<PA7) //definicja LED1, podłączonego do pinu PA7
  36.  
  37. void main(void)
  38. {
  39. DDRA |= LED1; //Ustawienie pinu sterującego diodą jako wyjście
  40. OCR0 = 243; // Ustawienie częstotliwości timera do około 4Hz
  41. TCCR0 |= (1<<CS02)|(1<<CS00)|(1<<WGM01)|(1<<COM00); //Ustawienie timer0 z preskalerem 64 w trybie CTC
  42. while(1); //nieskończona pętla
  43.  
  44. }
  45.  
  46. //Zadanie 2.
  47. /*
  48. #include <avr/io.h>
  49. #include <util/delay.h>
  50.  
  51. int main(void) {
  52. DDRB = (1<<PB3) //Ustawienie PB3 jako wyjście.
  53. TCCR0A = (1<<COM0A1)|(1<<COM0B1)|(1<<COM0B0)|(1<<WGM01)|(1<<WGM00); //Ustawienie rejestrów porównań
  54. DDRD = 0xFF; //ustawienie kierunku linii portu D w stronę wyjścia
  55. DDRC = 0x0F; //ustawienie połowy pinów portu C w stronę wyjścia
  56. DDRA = 0b11110000; // Ustawienie kierunku połowy linii portu A w strone wejścia
  57. PORTA |= (1 << PA0); // Aktywowanie rezystora podciągajcego
  58. OCR0A = 255; //Maksymalna jasność diody
  59. TCCR0B = (1<<CS00);
  60.  
  61.  
  62.  
  63. while (1) //nieskończona pętla
  64. {
  65. _delay_ms(8); //opóźnienie
  66. int x = 128;
  67.  
  68. for(int j=0;j<4;j++)
  69. {
  70. PORTA = ~x;
  71. x=x/2;
  72. }
  73. switch(PINA)
  74. {
  75. case 0b01111110: OCR0A=1;_delay_ms(50);break;
  76. case 0b01111101: OCROA=25;_delay_ms(50);break;
  77. case 0b01111011: OCROA=81;_delay_ms(50);break;
  78. case 0b01110111: OCROA=169;_delay_ms(50);break;
  79. case 0b10111110: OCROA=4;_delay_ms(50);break;
  80. case 0b10111101: OCROA=36;_delay_ms(50);break;
  81. case 0b10111011: OCROA=100;_delay_ms(50);break;
  82. case 0b10110111: OCROA=196;_delay_ms(50);break;
  83. case 0b11011110: OCROA=9;_delay_ms(50);break;
  84. case 0b11011101: OCROA=49;_delay_ms(50);break;
  85. case 0b11011011: OCROA=121;_delay_ms(50);break;
  86. case 0b11010111: OCROA=225;_delay_ms(50);break;
  87. case 0b11101110: OCROA=16;_delay_ms(50);break;
  88. case 0b11101101: OCROA=64;_delay_ms(50);break;
  89. case 0b11101011: OCROA=144;_delay_ms(50);break;
  90. case 0b11100111: OCROA=254;_delay_ms(50);break;
  91.  
  92. default OCROA = 50;
  93. }
  94. }
  95. */
  96.  
  97. //Zadanie 3.
  98.  
  99. include <avr/io.h>
  100. void main(void)
  101. {
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement