Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Drawing shapes on LedMatrix
- 1) Ustawienie timera
- static void startTimer1(tU16 delayInMs)
- {
- //initialize VIC for Timer1 interrupts
- VICIntSelect &= ~0x20; //Timer1 interrupt is assigned to IRQ (not FIQ)
- VICVectAddr5 = (tU32)ledMatrix; //register ISR address
- VICVectCntl5 = 0x25; //enable vector interrupt for timer1
- VICIntEnable = 0x20; //enable timer1 interrupt
- //initialize and start Timer #0
- T1TCR = 0x00000002; //disable and reset Timer1
- T1PC = 0x00000000; //no prescale of clock
- T1MR0 = delayInMs * ((CRYSTAL_FREQUENCY * PLL_FACTOR) / (1000 * VPBDIV_FACTOR)); //calculate no of timer ticks
- T1IR = 0x000000ff; //reset all flags before enable IRQs
- T1MCR = 0x00000003; //reset counter and generate IRQ on MR0 match
- T1TCR = 0x00000001; //start Timer1
- }
- #define SPI_CS 0x00008000 //<= new board, old board = 0x00800000
- void ledMatrix(void)
- {
- static tU32 columnCounter = 0x01;
- static tU8 index = 0;
- if (columnCounter > 0x80)
- {
- columnCounter = 0x01;
- index = 0;
- }
- send_SPI(~pattern[index++]);
- send_SPI(~columnCounter);
- columnCounter <<= 1;
- T1IR = 0xff; //reset all IRQ flags
- VICVectAddr = 0x00; //dummy write to VIC to signal end of interrupt
- ticks++; /* time measure */
- }
- void send_SPI(unsigned char indata)
- {
- tU32 failsafe;
- IOCLR0 = SPI_CS; // activete SPI
- SPI_SPDR = indata;
- failsafe = 0;
- while(((SPI_SPSR & 0x80) == 0) && (failsafe < 5000))
- failsafe++;
- IOSET0 = SPI_CS; // deactivate SPI
- if (failsafe >= 5000)
- {
- SPI_SPCCR = 0x08;
- SPI_SPCR = 0x60;
- }
- }
- 2) Drawing specific picture 8x8 char array
- //!! global array
- tU8 pattern[8] = {0,0,0,0,0,0,0,0};
- void drawPicture(char const *data)
- {
- tU8 i, j;
- for(i = 0; i < 8; i++)
- {
- pattern[i] = 0;
- for(j = 0; j < 8; j++)
- {
- pattern[i] |= ((1 << j) * (data[(j << 3) | i] == '*'));
- }
- }
- }
- 3) Drawing example
- char random4[] = \
- " " \
- "********" \
- "********" \
- " " \
- " " \
- "********" \
- "********" \
- " ";
- PINSEL0 |= 0x00001500 ; //Initiering av SPI
- SPI_SPCCR = 0x08;
- SPI_SPCR = 0x60;
- IODIR0 |= SPI_CS;
- startTimer1(2);
- drawPicture(random4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement