Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #include <basedef.h>
  2. #include <Board.h>
  3. #include <stdio.h>
  4.  
  5. #include <fixedsys.h>
  6. #include <lcd_GE8.h>
  7.  
  8. #define BIT_SW1 0x01000000
  9. #define BIT_SW2 0x02000000
  10.  
  11. #define JOY_LEFT 0x80
  12. #define JOY_DOWN 0x100
  13. #define JOY_UP 0x200
  14. #define JOY_RIGHT 0x4000
  15. #define JOY_CLICK 0x8000
  16.  
  17. #define CIRCLES 4
  18. #define CIRCLE_STEP 5
  19.  
  20. #define CIRCLE_X_BEGIN 20
  21. #define CIRCLE_Y_BEGIN 20
  22. #define CIRCLE_RADIUS 10
  23.  
  24. void Delay (unsigned long a) {while (--a!=0);}
  25.  
  26. typedef struct {
  27. int pos_x;
  28. int pos_y;
  29. char flags;
  30. } circle;
  31.  
  32. circle circles[CIRCLES];
  33. int total_circles = 0;
  34. int selected_circle = 0;
  35.  
  36. void drawCircle(circle toDraw) {
  37. if(toDraw.flags && CIRCLE_SELECTED) {
  38. LCDSetCircle(toDraw.pos_x, toDraw.pos_y, CIRCLE_RADIUS, LCD_COLOR_GREEN);
  39. } else {
  40. LCDSetCircle(toDraw.pos_x, toDraw.pos_y, CIRCLE_RADIUS, LCD_COLOR_RED);
  41. }
  42. }
  43.  
  44. int main()
  45. {
  46. int circle_x = 20;
  47. int circle_y = 20;
  48. int step = 5;
  49.  
  50. AT91PS_PIO p_pPioA = AT91C_BASE_PIOA;
  51. AT91PS_PIO p_pPioB = AT91C_BASE_PIOB;
  52. AT91PS_PMC p_pPMC = AT91C_BASE_PMC;
  53. AT91PS_SYS p_pSys = AT91C_BASE_SYS;
  54.  
  55. /* Initialize the Atmel AT91SAM7X256 (watchdog, PLL clock, default interrupts, etc.) */
  56. AT91F_LowLevel_Init();
  57.  
  58. //enable the clock of the PIO
  59. p_pPMC->PMC_PCER = 1 << AT91C_ID_PIOA;
  60. //enable the clock of the PIO
  61. p_pPMC->PMC_PCER = 1 << AT91C_ID_PIOB;
  62.  
  63. // GPIO init
  64. p_pPioA->PIO_ODR = 0xffffffff; // All as input
  65. p_pPioB->PIO_ODR = 0xffffffff; // All as input
  66. p_pSys->PIOA_PPUDR = 0xffffffff; // Disable Pull-up resistor
  67. p_pSys->PIOB_PPUDR = 0xffffffff; // Disable Pull-up resistor
  68.  
  69.  
  70.  
  71. // BUTTON SW1
  72. p_pPioB->PIO_ODR |= BIT_SW1; //Configure in Input
  73. p_pPioB->PIO_PER |= BIT_SW1; //Enable PB24
  74.  
  75. // BUTTON SW2
  76. p_pPioB->PIO_ODR |= BIT_SW2; //Configure in Input
  77. p_pPioB->PIO_PER |= BIT_SW2; //Enable PB25
  78.  
  79. //joystick
  80. p_pPioA->PIO_ODR |= JOY_LEFT; //Configure in Input
  81. p_pPioA->PIO_PER |= JOY_LEFT;
  82.  
  83. p_pPioA->PIO_ODR |= JOY_DOWN; //Configure in Input
  84. p_pPioA->PIO_PER |= JOY_DOWN;
  85.  
  86. p_pPioA->PIO_ODR |= JOY_UP; //Configure in Input
  87. p_pPioA->PIO_PER |= JOY_UP;
  88.  
  89. p_pPioA->PIO_ODR |= JOY_UP; //Configure in Input
  90. p_pPioA->PIO_PER |= JOY_UP;
  91.  
  92. p_pPioA->PIO_ODR |= JOY_RIGHT; //Configure in Input
  93. p_pPioA->PIO_PER |= JOY_RIGHT;
  94.  
  95. p_pPioA->PIO_ODR |= JOY_CLICK; //Configure in Input
  96. p_pPioA->PIO_PER |= JOY_CLICK;
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /* Init the LCD */
  103. InitLCD();
  104. LCD_ClearScreen( LCD_COLOR_WHITE );
  105.  
  106. /* enable interrupts */
  107. AT91F_Finalize_Init();
  108.  
  109.  
  110. /* add your program here ... */
  111. // LCD_WriteString("Hello world!", &Fixedsys_descriptor, 2, 20, LCD_COLOR_WHITE, LCD_COLOR_RED);
  112.  
  113.  
  114. /* ... and here */
  115. while ( true )
  116. {
  117. LCDSetRect(20, 20, 60, 60, 0, LCD_COLOR_BLACK);
  118.  
  119. if(!((p_pPioB->PIO_PDSR) & BIT_SW1) || !((p_pPioA->PIO_PDSR) & JOY_CLICK))
  120. {
  121.  
  122. if(total_circles < CIRCLES) {
  123. total_circles++;
  124. circles[total_circles].pos_x = CIRCLE_X_BEGIN + 10*total_circles;
  125. circles[total_circles].pos_y = CIRCLE_Y_BEGIN;
  126. }
  127. drawCircle(circles[total_circles]);
  128. }
  129.  
  130. if(!((p_pPioA->PIO_PDSR) & JOY_RIGHT))
  131. {
  132. circles[selected_circle].pos_x += CIRCLE_STEP;
  133. drawCircle(circles[selected_circle]);
  134. }
  135.  
  136. if(!((p_pPioA->PIO_PDSR) & JOY_LEFT))
  137. { circles[selected_circle].pos_x -= CIRCLE_STEP;
  138. drawCircle(circles[selected_circle]);
  139. }
  140.  
  141. if(!((p_pPioA->PIO_PDSR) & JOY_DOWN))
  142. {
  143. LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_WHITE);
  144. circle_y += step;
  145. LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_RED);
  146. }
  147.  
  148. if(!((p_pPioA->PIO_PDSR) & JOY_UP))
  149. {
  150. LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_WHITE);
  151. circle_y -= step;
  152. LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_RED);
  153. }
  154. }
  155.  
  156. /* Actually, the execution never gets here */
  157. return -1;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement