Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #define F_CPU 16000000UL
  2. #include <avr/io.h>
  3. #include <math.h>
  4. #include <util/delay.h>
  5. #include <avr/interrupt.h>
  6. #include "cyfry.h"
  7.  
  8. class Dioda{
  9. private:
  10. int _status;
  11. int _pin;
  12. public:
  13. Dioda(int pin){
  14. _status=0;
  15. _pin=pin;
  16. DDRA|=(1<<pin); //jako wyjscie
  17. }
  18. ~Dioda(){
  19. PORTA|=(1<<_pin);
  20. }
  21. void wlacz(int status){
  22. if (status){
  23. _status=1;
  24. PORTA&=~(1<<_pin);
  25. } else{
  26. _status=0;
  27. PORTA|=(1<<_pin);
  28. }
  29. }
  30. };
  31.  
  32. class Przycisk{
  33. private:
  34. int _pin;
  35. public:
  36. Przycisk(int pin){
  37. _pin=pin;
  38. DDRA&=~pin; //jako wejscie
  39. PORTA|=pin;
  40. }
  41. int checkstatus(){
  42. if(!(PINA & (1<<_pin) )){
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. };
  48.  
  49. class Wyswietlacz{
  50. private:
  51. int _pin;
  52. int segment(int digit){
  53. switch (digit){
  54. case 0: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F);
  55. case 1: return ~(SEG_B|SEG_C);
  56. case 2: return ~(SEG_A|SEG_B|SEG_D|SEG_E|SEG_G);
  57. case 3: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_G);
  58. case 4: return ~(SEG_B|SEG_C|SEG_F|SEG_G);
  59. case 5: return ~(SEG_A|SEG_C|SEG_D|SEG_F|SEG_G);
  60. case 6: return ~(SEG_A|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G);
  61. case 7: return ~(SEG_A|SEG_B|SEG_C|SEG_F);
  62. case 8: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G);
  63. case 9: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_F|SEG_G);
  64. default: return ~(SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F);
  65. }
  66. }
  67. public:
  68. volatile int cyfra;
  69.  
  70. Wyswietlacz(int pin){
  71. _pin=pin;
  72. cyfra=0;
  73. PORTC&=~(1<<pin);
  74. }
  75. ~Wyswietlacz(){
  76. PORTC|=(1<<_pin);
  77. }
  78. void set(){
  79. PORTC=~(1<<_pin);
  80. }
  81.  
  82. void show(int digit){
  83. PORTA=segment(digit);
  84. }
  85. };
  86.  
  87. Wyswietlacz w1(0);
  88. Wyswietlacz w2(1);
  89.  
  90.  
  91.  
  92.  
  93.  
  94. ISR(TIMER2_COMP_vect){
  95. w1.set();
  96. w1.show(w1.cyfra);
  97. _delay_ms(1);
  98. w2.set();
  99. w2.show(w2.cyfra);
  100. _delay_ms(1);
  101. }
  102.  
  103.  
  104.  
  105.  
  106. int main(void){
  107. DDRA=0xFF;
  108. DDRC=0xFF;
  109. /*TIMER*/
  110. TCCR2=(1<<WGM21);
  111. TCCR2|=((1<CS21) | (1<<CS22) | (1<CS20));
  112. TIMSK=(1<<OCIE2);
  113. OCR2=99;
  114. sei();//wlaczanie
  115.  
  116.  
  117. volatile int c1,c2;
  118.  
  119.  
  120.  
  121. //const int a= Wyswietlacz::cyfry;
  122. //PORTA=Wyswietlacz::cyfry[1];
  123.  
  124.  
  125. //1 wyjscie
  126.  
  127. while(1){
  128.  
  129. w1.cyfra=1;
  130. w2.cyfra=2;
  131.  
  132. w1.cyfra=4;
  133. w2.cyfra=4;
  134.  
  135.  
  136.  
  137. //w1.show(w1.cyfra);
  138.  
  139. //w2.show(w2.cyfra);
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. /*
  169. TCCR2=(1<<WGM21);
  170. TCCR2|=((1<CS21) | (1<<CS22) | (1<CS20));
  171. TIMSK=(1<<OCIE2);
  172. OCR2=99;
  173. //sei();//wlaczanie
  174. cli();//wylaczene
  175. */
  176. /*
  177. Dioda Dioda1(2);
  178. Dioda Dioda2(3);
  179. Dioda Dioda3(4);
  180.  
  181. Przycisk Przycsik1(0);
  182. Przycisk Przycsik2(1);
  183. PORTA=0xff;
  184. while(1){
  185. if(Przycsik1.checkstatus() && Przycsik2.checkstatus()){
  186. Dioda Dioda4(5);
  187. while(Przycsik1.checkstatus() && Przycsik2.checkstatus())
  188. Dioda4.wlacz(1);
  189.  
  190. }
  191. Dioda2.wlacz(Przycsik2.checkstatus());
  192. Dioda1.wlacz(Przycsik1.checkstatus());
  193. _delay_ms(200);
  194.  
  195. }*/
  196. }
Add Comment
Please, Sign In to add comment