Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. Drawing shapes on LedMatrix
  2. 1) Ustawienie timera
  3.  
  4. static void startTimer1(tU16 delayInMs)
  5. {
  6. //initialize VIC for Timer1 interrupts
  7. VICIntSelect &= ~0x20; //Timer1 interrupt is assigned to IRQ (not FIQ)
  8. VICVectAddr5 = (tU32)ledMatrix; //register ISR address
  9. VICVectCntl5 = 0x25; //enable vector interrupt for timer1
  10. VICIntEnable = 0x20; //enable timer1 interrupt
  11.  
  12. //initialize and start Timer #0
  13. T1TCR = 0x00000002; //disable and reset Timer1
  14. T1PC = 0x00000000; //no prescale of clock
  15. T1MR0 = delayInMs * ((CRYSTAL_FREQUENCY * PLL_FACTOR) / (1000 * VPBDIV_FACTOR)); //calculate no of timer ticks
  16. T1IR = 0x000000ff; //reset all flags before enable IRQs
  17. T1MCR = 0x00000003; //reset counter and generate IRQ on MR0 match
  18. T1TCR = 0x00000001; //start Timer1
  19. }
  20.  
  21.  
  22. #define SPI_CS 0x00008000 //<= new board, old board = 0x00800000
  23.  
  24. void ledMatrix(void)
  25. {
  26. static tU32 columnCounter = 0x01;
  27. static tU8 index = 0;
  28.  
  29. if (columnCounter > 0x80)
  30. {
  31. columnCounter = 0x01;
  32. index = 0;
  33. }
  34. send_SPI(~pattern[index++]);
  35. send_SPI(~columnCounter);
  36. columnCounter <<= 1;
  37.  
  38. T1IR = 0xff; //reset all IRQ flags
  39. VICVectAddr = 0x00; //dummy write to VIC to signal end of interrupt
  40.  
  41. ticks++; /* time measure */
  42. }
  43.  
  44.  
  45. void send_SPI(unsigned char indata)
  46. {
  47. tU32 failsafe;
  48.  
  49. IOCLR0 = SPI_CS; // activete SPI
  50.  
  51. SPI_SPDR = indata;
  52. failsafe = 0;
  53. while(((SPI_SPSR & 0x80) == 0) && (failsafe < 5000))
  54. failsafe++;
  55. IOSET0 = SPI_CS; // deactivate SPI
  56.  
  57. if (failsafe >= 5000)
  58. {
  59. SPI_SPCCR = 0x08;
  60. SPI_SPCR = 0x60;
  61. }
  62. }
  63.  
  64.  
  65. 2) Drawing specific picture 8x8 char array
  66.  
  67. //!! global array
  68. tU8 pattern[8] = {0,0,0,0,0,0,0,0};
  69.  
  70.  
  71. void drawPicture(char const *data)
  72. {
  73. tU8 i, j;
  74. for(i = 0; i < 8; i++)
  75. {
  76. pattern[i] = 0;
  77. for(j = 0; j < 8; j++)
  78. {
  79. pattern[i] |= ((1 << j) * (data[(j << 3) | i] == '*'));
  80. }
  81. }
  82. }
  83.  
  84. 3) Drawing example
  85.  
  86. char random4[] = \
  87. " " \
  88. "********" \
  89. "********" \
  90. " " \
  91. " " \
  92. "********" \
  93. "********" \
  94. " ";
  95.  
  96.  
  97. PINSEL0 |= 0x00001500 ; //Initiering av SPI
  98. SPI_SPCCR = 0x08;
  99. SPI_SPCR = 0x60;
  100. IODIR0 |= SPI_CS;
  101.  
  102. startTimer1(2);
  103.  
  104.  
  105. drawPicture(random4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement