Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include "AT91SAM9263.h"
  2. #include "AT91SAM9263-EK.h"
  3.  
  4. #define PMC_PCER (volatile unsigned int * const) 0xFFFFFC10
  5. #define Q1 (1U<<29)
  6. #define Q2 (1U<<28)
  7. #define Q3 (1U<<30)
  8.  
  9. #define E (1U<<20)
  10. #define D (1U<<21)
  11. #define C (1U<<22)
  12. #define DP (1U<<23)
  13. #define B (1U<<24)
  14. #define A (1U<<25)
  15. #define G (1U<<26)
  16. #define F (1U<<27)
  17.  
  18. #define BATON1 (1<<5)
  19.  
  20. #define S7 (A | B | C | D | E | F | G)
  21.  
  22. const unsigned int num[10] =
  23. {
  24. A | B | C | D | E | F, //0
  25. B | C, //1
  26. A | B | G | E | D, //2
  27. A | B | G | C | D, //3
  28. F | G | C | B, //4
  29. A | F | G | C | D, //5
  30. A | F | E | G | C | D, //6
  31. A | B | C, //7
  32. A | B | C | D | E | F | G, //8
  33. A | F | B | G | C | D //9
  34. };
  35.  
  36.  
  37.  
  38. void delay(int delay)
  39. {
  40. volatile unsigned int i = 0;
  41. for(i; i < delay; i++);
  42. }
  43.  
  44. void wyswietl(int jednosci, int dziesiatki)
  45. {
  46. int i;
  47. volatile unsigned int temp;
  48. for(i = 0; i < 10; i++)
  49. {
  50. while(1)
  51. {
  52. AT91C_BASE_PIOB->PIO_SODR = Q2 | Q3;
  53.  
  54. if(dziesiatki>0)
  55. {
  56. AT91C_BASE_PIOB->PIO_CODR = S7 | Q2;
  57. AT91C_BASE_PIOB->PIO_SODR = Q3 | num[dziesiatki];
  58. }
  59.  
  60. delay(20000);
  61. AT91C_BASE_PIOB->PIO_CODR = S7 | Q3;
  62. AT91C_BASE_PIOB->PIO_SODR = Q2 | num[jednosci];
  63. delay(20000);
  64.  
  65. if(AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS)
  66. {
  67. temp = AT91C_BASE_PITC->PITC_PIVR;
  68. break;
  69. }
  70. }
  71. }
  72. }
  73.  
  74.  
  75. void main(void)
  76. {
  77. //Q1 - jasnosc
  78. //Q2 - lewy tranzystor
  79. //Q3 - prawy tranzystor
  80.  
  81. AT91C_BASE_PIOB->PIO_PER = S7 | Q1 | Q2 | Q3;
  82. AT91C_BASE_PIOB->PIO_OER = S7 | Q1 | Q2 | Q3;
  83. AT91C_BASE_PIOB->PIO_CODR = S7 | Q1 | Q3;
  84. AT91C_BASE_PIOB->PIO_SODR = Q2;
  85.  
  86. //PRZYCISK
  87. *AT91C_PMC_PCER = 1<<4;
  88. AT91C_BASE_PIOC->PIO_PER = BATON1;
  89. AT91C_BASE_PIOC->PIO_ODR = BATON1;
  90. AT91C_BASE_PIOC->PIO_PPUER = BATON1;
  91.  
  92. //PIT
  93. AT91C_BASE_PITC->PITC_PIMR = AT91C_PITC_PITEN | AT91C_PITC_PITIEN;
  94. AT91C_BASE_PITC->PITC_PIMR |= 624999;
  95.  
  96.  
  97.  
  98.  
  99. volatile int i = 0,j = -1;
  100. while(1)
  101. {
  102. if((AT91C_BASE_PIOC->PIO_PDSR & BATON1) == BATON1)
  103. j++;
  104. else
  105. j--;
  106.  
  107. if(j>9)
  108. {
  109. i++;
  110. j=0;
  111. }
  112.  
  113. if(i>9)
  114. {
  115. i=0;
  116. }
  117.  
  118. if(j<0)
  119. {
  120. i--;
  121. j=9;
  122. }
  123.  
  124. if(i<0)
  125. i=9;
  126.  
  127. wyswietl(j,i);
  128.  
  129.  
  130.  
  131. }
  132. }
  133.  
  134.  
  135. void dbgu_print_ascii(const char* string){};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement