Advertisement
Guest User

Untitled

a guest
May 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1.  
  2. #include "main_base.h"
  3.  
  4. int x = 120, y = 160, dx = 1, dy = 1;
  5. unsigned int pomiar;
  6.  
  7. void move_square_asm();
  8. unsigned short int RGB16Pack(unsigned char,unsigned char,unsigned char);
  9.  
  10. void move_square_C()
  11. {
  12. x=pomiar;
  13. //y+=dy;
  14. //if (x <= 1 || x >= 240 - 34)
  15. // pomiar = -pomiar;
  16. //if (y <= 1 || y >= 320 - 34)
  17. //dy = -dy;
  18. }
  19.  
  20. int main(void) {
  21. HAL_Init();
  22. SystemClock_Config();
  23. BSP_SDRAM_Init();
  24. LCD_Config();
  25.  
  26.  
  27. RCC->APB2ENR|=RCC_APB2ENR_TIM1EN;
  28. GPIOA->AFR[1]|= 1 << (0*4); // 1 - Tim2_CH1 //funkcja alternatywna wejsc (AFR), bo port moze byc i/o/adc/enkoder/inne alternatywne
  29. GPIOA->AFR[1]|= 1 << (1*4); // 1 - Tim2_CH2
  30. GPIOA->MODER |= GPIO_Mode_AF << (8*2);
  31. GPIOA->MODER |= GPIO_Mode_AF << (9*2); //bylo gpiob
  32. GPIOA->PUPDR |= GPIO_PuPd_UP << (8*2);
  33. GPIOA->PUPDR |= GPIO_PuPd_UP << (9*2); //bylo gpiob
  34. TIM1->PSC=0; // Brak preskalera
  35. TIM1->CNT=16; // Pocz¹tkowy stan licznika
  36. TIM1->SMCR=1; // Wybór trybu pracy enkodera
  37. TIM1->CCMR1=0x3232; /* CCxS bits = 01 - Ustawia kana³y
  38. CH1 i CH2 do pracy wejœciowej (CAPTURE) ICxF bits = 3 -
  39. ustawia rozmiar okna filtru wejœciowego */ //jeszcze go skonfigurowac?
  40. TIM1->ARR=32; // Rejestr prze³adowania stanu licznika
  41. TIM1->CR1=1; // Odblokowuje licznik
  42. //pomiar=TIM1->CNT;
  43.  
  44.  
  45. while (1)
  46. {
  47. pomiar=TIM1->CNT;
  48. Clear_And_Reload_Screen();
  49.  
  50. #ifdef ASM_EXMPL
  51. move_square_asm();
  52. #else
  53. move_square_C();
  54. #endif
  55.  
  56. for (int yy = 0; yy < 32; yy++)
  57. {
  58. unsigned short int *pixel = (unsigned short int*) (LCD_BUF + x + (y + yy) * 240);
  59.  
  60. for (int xx = 0; xx < 32; xx++)
  61. {
  62. #ifdef ASM_EXMPL
  63. *pixel++ = RGB16Pack(y >> 4, (xx + (((240 - x)) * (32 - yy) / 240)+x * yy / 240), 31 - (x >> 4));
  64. #else
  65. *pixel++ = ((31 - ((x >> 4) & 0x1f)) << 11) | (((xx + (((240 - x)) * (32 - yy) / 240) + x * yy / 240) & 0x3f) << 5) | (((y >> 4) & 0x1f) << 0);
  66. #endif
  67. }
  68. }
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement