Advertisement
rav1989

Untitled

Mar 21st, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1.  
  2. #define PIOB_PER    *((volatile int*) 0xfffff400)
  3. #define PIOB_PDR    *((volatile int*) 0xfffff404)
  4. #define PIOB_PSR    *((volatile int*) 0xfffff408)
  5. #define PIOB_OER    *((volatile int*) 0xfffff410)
  6. #define PIOB_ODR    *((volatile int*) 0xfffff414)
  7. #define PIOB_OSR    *((volatile int*) 0xfffff418)
  8. #define PIOB_SODR   *((volatile int*) 0xfffff430)
  9. #define PIOB_CODR   *((volatile int*) 0xfffff434)
  10. #define PIOB_ODSR   *((volatile int*) 0xfffff438)
  11.  
  12. #define LED0        1<<20
  13. #define LED1        1<<21
  14. #define LED2        1<<22
  15. #define LED3        1<<23
  16. #define LED4        1<<24
  17. #define LED5        1<<25
  18. #define LED6        1<<26
  19. #define LED7        1<<27
  20. #define LED_ENABLE  1<<16
  21. #define LED_DISP10  1<<30
  22. #define LED_DISP01  1<<28
  23. #define LED_DISP_ENABLE 1<<31
  24.  
  25. #define DIGIT_0     LED0|LED1|LED2|LED4|LED5|LED7
  26. #define DIGIT_1     LED2|LED4
  27. #define DIGIT_2     LED0|LED1|LED4|LED5|LED6
  28. #define DIGIT_3     LED1|LED2|LED4|LED5|LED6
  29. #define DIGIT_4     LED2|LED4|LED6|LED7
  30. #define DIGIT_5     LED1|LED2|LED5|LED6|LED7
  31. #define DIGIT_6     LED0|LED1|LED2|LED5|LED6|LED7
  32. #define DIGIT_7     LED2|LED4|LED5
  33. #define DIGIT_8     LED0|LED1|LED2|LED4|LED5|LED6|LED7
  34. #define DIGIT_9     LED1|LED2|LED4|LED5|LED6|LED7
  35. #define DOT     LED3
  36.  
  37. #define DZIESIATKI(dec) (dec/10)
  38. #define JEDNOSCI(dec)   (dec%10)
  39.  
  40. void dbgu_print_ascii(const char* a){}
  41.  
  42. void sleep(volatile int value){
  43. volatile int delay_counter = 0;
  44. for(delay_counter = 0; delay_counter<2000*value; delay_counter++);
  45. }
  46.  
  47. void stop(){
  48. while(1){}
  49. }
  50.  
  51. void init(){
  52. PIOB_PER =  LED0|LED1|LED2|LED3|LED4|LED5|LED6|LED7|LED_DISP_ENABLE|LED_DISP01|LED_DISP10;
  53. PIOB_OER =  LED0|LED1|LED2|LED3|LED4|LED5|LED6|LED7|LED_DISP_ENABLE|LED_DISP01|LED_DISP10;
  54. PIOB_CODR =     LED0|LED1|LED2|LED3|LED4|LED5|LED6|LED7|LED_DISP_ENABLE|LED_DISP01|LED_DISP10;
  55. PIOB_SODR = LED_ENABLE;
  56. }
  57.  
  58. int main(){
  59. volatile int number_counter;
  60. /*volatile int disp_numb = 0;*/
  61. volatile int numb_01;
  62. volatile int numb_10;
  63.  
  64. volatile int digits[10] = {DIGIT_0,DIGIT_1,DIGIT_2,DIGIT_3,DIGIT_4,DIGIT_5,DIGIT_6,DIGIT_7,DIGIT_8,DIGIT_9};
  65.  
  66. init();
  67.  
  68. while(1)
  69.     {
  70.         for(number_counter = 0 ; number_counter<99 ; number_counter++){
  71.             numb_01 = JEDNOSCI(number_counter);
  72.             numb_10 = DZIESIATKI(number_counter);
  73.            
  74.             PIOB_SODR = LED_DISP01;
  75.             PIOB_SODR = digits[numb_01];
  76.             sleep(10);
  77.             PIOB_CODR = digits[numb_01];
  78.             PIOB_CODR = LED_DISP01;
  79.             PIOB_SODR = LED_DISP10;
  80.             PIOB_SODR = digits[numb_10];
  81.             sleep(10);
  82.             PIOB_CODR = digits[numb_10];
  83.             PIOB_CODR = LED_DISP10;
  84.         }
  85.  
  86. /*
  87.         for(led_counter = LED0; led_counter<LED7; led_counter=led_counter<<1)
  88.         {
  89.             PIOB_SODR = led_counter;
  90.             sleep(DELAY);
  91.             PIOB_CODR = led_counter;
  92.         }
  93.  
  94.         for(led_counter = LED7; led_counter>LED0; led_counter=led_counter>>1)
  95.         {
  96.             PIOB_SODR = led_counter;
  97.             sleep(DELAY);
  98.             PIOB_CODR = led_counter;
  99.         }
  100. */
  101.     }
  102.  
  103. stop();
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement