Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. /*
  2.  * File:        freedom_green_led.c
  3.  * Purpose:     Main process
  4.  *
  5.  */
  6.  
  7. #include "common.h"
  8. #include "ports.h"
  9. #include "isr.h"
  10.  
  11. /* void enable_sistick(void) {
  12.     SYST_RVR = 48000000;  //0x00493E00; // SysTick Reload Value Register, 100ms
  13.     SYST_CVR = 0x00000000;
  14.     SYST_CSR = SysTick_CSR_ENABLE_MASK |
  15.                 SysTick_CSR_TICKINT_MASK |
  16.                 SysTick_CSR_CLKSOURCE_MASK;
  17. } */
  18.  
  19. int state = 5;
  20.  
  21. int bauncCounter = 0;
  22. int bauncLast = 0;
  23.  
  24. int debauncer(int btn)
  25. {
  26.     if(!btn) {
  27.         bauncCounter = 0;
  28.         bauncLast = 0;
  29.     }
  30.  
  31.     if(!bauncLast & btn) {
  32.         if(bauncCounter < 0xff) {
  33.             bauncCounter++;
  34.         } else {
  35.             bauncLast = 1;
  36.             return 1;
  37.         }
  38.     } else {
  39.         bauncCounter = 0;
  40.         return 0;
  41.     }
  42. }
  43.  
  44. void on(void)
  45. {
  46.  
  47. }
  48.  
  49. void off(void)
  50. {
  51.  
  52. }
  53.  
  54.  
  55.  
  56. int counter = 0;
  57.  
  58. void systick_isr(void)
  59. {
  60.     if (counter < 10) {
  61.         counter++;
  62.     } else {
  63.         counter = 0;
  64.         on();
  65.     }
  66.  
  67.     if (counter == state) {
  68.         off();
  69.     }
  70. }
  71.  
  72.  
  73. int main (void)
  74. {
  75.     printf("\n\n\rRunning the blinky project.\n\r");
  76.  
  77.     initLed('R');
  78.     initLed('g');
  79.     initPort('C', 3, 0);
  80.     initPort('C', 12, 0);
  81.  
  82.     systick_init(4800);  // 48 000 000 / 4 800 = 10 000
  83.  
  84.     for (;;)
  85.     {
  86.         int pb = debauncer(readPort('B', 3));
  87.         int mb = debauncer(readPort('B', 12));
  88.  
  89.         if (state < 10) {
  90.             state -= mb;
  91.         } else if (state > 0) {
  92.             state += pb;
  93.         } else {
  94.             state += pb;
  95.             state -= mb;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement