Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include "include/project.h"
  2. #include "stdio.h"
  3.  
  4. #define A 1 << 25
  5. #define B 1 << 24
  6. #define C 1 << 22
  7. #define D 1 << 21
  8. #define E 1 << 20
  9. #define F 1 << 27
  10. #define G 1 << 26
  11. #define DP 1 << 23
  12.  
  13. #define LEFT 1 << 30
  14. #define RIGHT 1 << 28
  15.  
  16.  
  17. unsigned int number[10];
  18.  
  19. void delay() {
  20. volatile int i;
  21. i = 6000;
  22. while(i) {
  23. i -= 1;
  24. }
  25. }
  26.  
  27. void screen_left (int numer) {
  28. AT91C_BASE_PIOB->PIO_SODR = LEFT; //ustawienie lewego screenu
  29. AT91C_BASE_PIOB->PIO_SODR |= number[numer]; //wyświetlenie numeru - Set Output Data Register
  30. AT91C_BASE_PIOB->PIO_PER |= number[numer];
  31. AT91C_BASE_PIOB->PIO_OER |= number[numer];
  32. delay();
  33. AT91C_BASE_PIOB->PIO_CODR = number[8];
  34. AT91C_BASE_PIOB->PIO_CODR = LEFT; // wyczyszczenie data - Clear Output Data Register
  35. }
  36.  
  37. void screen_right (int numer) {
  38. AT91C_BASE_PIOB->PIO_SODR = RIGHT;
  39. AT91C_BASE_PIOB->PIO_SODR |= number[numer];
  40. AT91C_BASE_PIOB->PIO_PER |= number[numer];
  41. AT91C_BASE_PIOB->PIO_OER |= number[numer];
  42. delay();
  43. AT91C_BASE_PIOB->PIO_CODR = number[8];
  44. AT91C_BASE_PIOB->PIO_CODR = RIGHT;
  45. }
  46.  
  47. void show_number (int left, int right) {
  48. volatile int i;
  49. for(i = 0; i < 100; i++) {
  50. screen_left(left);
  51. screen_right(right);
  52. }
  53. }
  54.  
  55. void counter99 () {
  56. int i, j;
  57. for(i = 0; i <= 9; i++) {
  58. for(j = 0; j <= 9; ) {
  59. show_number(i, j);
  60. if((*AT91C_PIOC_PDSR & 1<<4) != 0){
  61. j++;
  62. }
  63. else{
  64. j--;
  65. if(j==0&&i!=0){
  66. i--;
  67. j=9;
  68. }
  69. else if(i==0&&j==0){
  70. i=9;
  71. j=9;
  72. }
  73. }
  74. }
  75. }
  76. }
  77.  
  78. void counter9 () {
  79. int i, j;
  80. i=0;
  81. for(j = 0; j <= 9; j++) {
  82. show_number(i, j);
  83. }
  84. }
  85.  
  86. void set_number_table (){
  87. number[0] = A|B|C|D|E|F;
  88. number[1] = B|C;
  89. number[2] = A|B|G|E|D;
  90. number[3] = A|B|G|C|D;
  91. number[4] = B|F|G|C;
  92. number[5] = A|F|G|C|D;
  93. number[6] = A|F|G|C|D|E;
  94. number[7] = A|B|C;
  95. number[8] = A|B|C|D|E|F|G;
  96. number[9] = A|B|G|F|C|D;
  97. }
  98.  
  99. void unlock_ports (){
  100.  
  101. AT91C_BASE_PIOB->PIO_PER = LEFT; //PIO Enable Register
  102. AT91C_BASE_PIOB->PIO_OER = LEFT; //Output Enable Register
  103. AT91C_BASE_PIOB->PIO_PER = RIGHT;
  104. AT91C_BASE_PIOB->PIO_OER = RIGHT;
  105. }
  106.  
  107. int main() {
  108. set_number_table();
  109. unlock_ports();
  110.  
  111. while(1) {
  112. counter99();
  113. //counter9();
  114. }
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement