Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. // lab2-gpio/heart.c
  2. // Copyright (c) 2018 J. M. Spivey
  3.  
  4. #include "hardware.h"
  5.  
  6. /* delay -- pause for n microseconds */
  7. void delay(unsigned n) {
  8.     unsigned t = n << 1;
  9.     while (t > 0) {
  10.         // 500nsec per iteration at 16MHz
  11.         nop(); nop(); nop();
  12.         t--;
  13.     }
  14. }
  15.  
  16. static const unsigned v[6][3] = {
  17.     {0x3ff0, 0x5ff0, 0x9fb0},
  18.     {0x3bf0, 0x5bf0, 0x9fb0},
  19.     {0x39f0, 0x5bb0, 0x9fa0},
  20.     {0x38f0, 0x59b0, 0x8ba0},
  21.     {0x3830, 0x59a0, 0x8380}
  22. };
  23.  
  24. static const unsigned test[] = {
  25.  
  26. };
  27.  
  28. static const unsigned heart[] = {
  29.     0x28f0, 0x5e00, 0x8060
  30. };
  31.  
  32. static const unsigned banana[] = {
  33.     0x3dd0, 0x49b0, 0x9de0
  34. };
  35.      
  36. static const unsigned small[] = {
  37.     0x2df0, 0x5fb0, 0x8af0
  38. };
  39.  
  40.  
  41. #define JIFFY 5000 /* Delay in microsecs */
  42.  
  43. /* show -- display three rows of a picture n times */
  44. void show(const unsigned *img, int n) {
  45.     while (n-- > 0) {
  46.         // Takes 15msec per iteration
  47.         for (int p = 0; p < 3; p++) {
  48.             GPIO_OUT = img[p];
  49.             delay(JIFFY);
  50.         }
  51.     }
  52. }
  53.  
  54. void init(void)
  55. {
  56.     GPIO_DIR = 0xfff0;
  57.     GPIO_PINCNF[BUTTON_A] = 0;
  58.     GPIO_PINCNF[BUTTON_B] = 0;
  59.     int i=0;
  60.     int lastA = GPIO_IN | BIT(BUTTON_A);
  61.     int lastB = GPIO_IN | BIT(BUTTON_B);
  62.  
  63.     while (1)
  64.     {
  65.         if((GPIO_IN | BIT(BUTTON_A)) < lastA)
  66.             i++;
  67.         if((GPIO_IN | BIT(BUTTON_B)) < lastB)
  68.             i--;
  69.         lastA = GPIO_IN | BIT(BUTTON_A);
  70.         lastB = GPIO_IN | BIT(BUTTON_B);
  71.         if(i<0)
  72.         i=4;
  73.         if(i==5)
  74.         i=0;
  75.         show(v[i],1);
  76.             //show(banana, 70);
  77.             //show(small, 10);
  78.             //show(banana, 10);
  79.             //show(small, 10);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement