Advertisement
Guest User

Zadanka z C - oceniane

a guest
Apr 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. /*
  2. * tset.c
  3. *
  4. * Created: 2019-04-09 10:12:18
  5. * Author : oem1
  6. */
  7. /*
  8. //zadanie 1
  9. #include <avr/io.h>
  10. #define F_CPU 16000000UL
  11. #include <util/delay.h>
  12. #include <avr/interrupt.h>
  13.  
  14. uint8_t seg7[]={0b11000000,
  15. 0b11111001,
  16. 0b10100100,
  17. 0b10110000,
  18. 0b10011001,
  19. 0b10010010,
  20. 0b10000010,
  21. 0b11111000,
  22. 0b10000000,
  23. 0b10010000};
  24.  
  25. volatile uint8_t LED[4];
  26.  
  27. int main(void)
  28. {
  29. TCCR0 |= (1 << WGM01 ) | (0 << WGM00 );
  30. TCCR0 |= (1 << CS02) | (0 << CS01) | (1 << CS00);
  31. OCR0=50;
  32. TIMSK |=(1 << OCIE0);
  33. sei();
  34.  
  35. uint16_t sec = 1955;
  36. uint16_t tmp = sec;
  37.  
  38. LED[3]=seg7[tmp/1000];
  39. tmp %= 1000;
  40. LED[2]=seg7[tmp/100];
  41. tmp %= 100;
  42. LED[1]=seg7[tmp/10];
  43. tmp %= 10;
  44. LED[0]=seg7[tmp];
  45.  
  46.  
  47. DDRB = 0x0F;
  48. DDRA = 0xFF;
  49.  
  50.  
  51. // Replace with your application code
  52. while (1)
  53. {
  54.  
  55.  
  56. }
  57. }
  58. ISR(TIMER0_COMP_vect)
  59. {
  60. static uint8_t licznik = 0;
  61.  
  62. PORTB |= 0x0F;
  63. PORTA = LED[licznik];
  64. PORTB &= ~(1 << licznik);
  65.  
  66. if (++licznik>3){
  67. licznik = 0;
  68. }
  69.  
  70. }*/
  71.  
  72.  
  73. //zadanie 2
  74. #include <avr/io.h>
  75. #define F_CPU 16000000UL
  76. #include <util/delay.h>
  77. #include <avr/interrupt.h>
  78.  
  79. uint8_t seg7[]={0b11000000,
  80. 0b11111001,
  81. 0b10100100,
  82. 0b10110000,
  83. 0b10011001,
  84. 0b10010010,
  85. 0b10000010,
  86. 0b11111000,
  87. 0b10000000,
  88. 0b10010000};
  89.  
  90. volatile uint8_t LED[4];
  91. volatile uint8_t key_state1 = 0;
  92. volatile uint8_t key_state2 = 0;
  93.  
  94. int main(void)
  95. {
  96. TCCR0 |= (1 << WGM01 ) | (0 << WGM00 );
  97. TCCR0 |= (1 << CS02) | (0 << CS01) | (1 << CS00);
  98. OCR0=50;
  99. TIMSK |=(1 << OCIE0);
  100. sei();
  101.  
  102. uint16_t sec = 1234;
  103.  
  104. DDRB = 0x0F;
  105. DDRA = 0xFF;
  106.  
  107. DDRC = 0x00;
  108. PORTC = 0x03;
  109.  
  110. // Replace with your application code
  111. while (1)
  112. {
  113. uint16_t tmp = sec;
  114.  
  115. LED[3]=seg7[tmp/1000];
  116. tmp %= 1000;
  117. LED[2]=seg7[tmp/100];
  118. tmp %= 100;
  119. LED[1]=seg7[tmp/10];
  120. tmp %= 10;
  121. LED[0]=seg7[tmp];
  122.  
  123. if (key_state1 == 2){
  124. sec = 1234;
  125. key_state1 = 3;
  126. }
  127. else if(key_state2 == 2){
  128. sec = 4567;
  129. key_state2 = 3;
  130. }
  131.  
  132. }
  133. }
  134. ISR(TIMER0_COMP_vect)
  135. {
  136. static uint8_t licznik = 0;
  137.  
  138. PORTB |= 0x0F;
  139. PORTA = LED[licznik];
  140. PORTB &= ~(1 << licznik);
  141.  
  142. if (++licznik>3){
  143. licznik = 0;
  144. }
  145.  
  146. switch(key_state1){
  147. case 0: if ((PINC & 0x01) == 0) key_state1 = 1;
  148. break;
  149. case 1: if ((PINC & 0x01) == 0) key_state1 = 2;
  150. else key_state1 = 0;
  151. break;
  152. case 2: break;
  153. case 3: if ((PINC & 0x01) != 0) key_state1 = 4;
  154. break;
  155. case 4: if ((PINC & 0x01) != 0) key_state1 = 0;
  156. else key_state1 = 3;
  157. break;
  158. default:key_state1 = 0;
  159. }
  160.  
  161. switch(key_state2){
  162. case 0: if ((PINC & 0x02) == 0) key_state2 = 1;
  163. break;
  164. case 1: if ((PINC & 0x02) == 0) key_state2 = 2;
  165. else key_state2 = 0;
  166. break;
  167. case 2: break;
  168. case 3: if ((PINC & 0x02) != 0) key_state2 = 4;
  169. break;
  170. case 4: if ((PINC & 0x02) != 0) key_state2 = 0;
  171. else key_state2 = 3;
  172. break;
  173. default:key_state2 = 0;
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement