Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "intrinsics.h"
- #include "iostm8s103f3.h"
- #include "types.h"
- uint8 matrix[8];
- uint8 dataBuffer[4];
- //dataBuffer[0] Anodes MSB First
- //dataBuffer[1] Green Cathodes LSB
- //dataBuffer[2] Blue Cathodes LSB
- //dataBuffer[3] Red Cathodes LSB
- #define CS PE_ODR_ODR5
- #define CS_PIN 1 << 5
- void sleep(uint32 count)
- {
- while(count)
- {
- asm("nop");
- count--;
- }
- }
- void Blinker(uint8 x, uint8 y)
- {
- matrix[x++] = (2 << y);
- matrix[x++] = (2 << y);
- matrix[x] = (2 << y);
- }
- void SetupSPI()
- {
- SPI_CR1_BR = 7; //Baude Rate to clock/2
- SPI_CR1_CPOL = 0; //Clock Idle LOW
- SPI_CR1_CPHA = 0; //First Clock Edge is data
- SPI_CR1_LSBFIRST = 0;
- SPI_CR1_MSTR = 1; //SPI Master Enabled
- SPI_CR1_SPE = 1; //Enable SPI
- SPI_CR2 = 0x01;
- //Setup CS Pin
- CS = 1;
- PE_DDR |= CS_PIN;
- PE_CR1 |= CS_PIN;
- PE_CR2 |= CS_PIN;
- }
- void TransmitSPI(uint8 data[], uint8 count)
- {
- CS = 0;
- for(uint8 i = 0; i < count; i++)
- {
- SPI_DR = data[i];
- //Wait until the buffer is clear
- while(SPI_SR_TXE == 0);
- }
- //Wait until transmition is complete
- while(SPI_SR_BSY == 1);
- CS = 1;
- }
- void SetColumn(uint8 column, uint8 state)
- {
- }
- void ClearMatrix()
- {
- uint8 data[4];
- data[0] = 0x00;
- data[1] = 0x00;
- data[2] = 0x00;
- data[3] = 0x00;
- TransmitSPI(data, 4);
- sleep(1000);
- }
- void main( void )
- {
- CLK_CKDIVR = 0x00;
- SetupSPI();
- ClearMatrix();
- sleep(1000);
- for(int i =0; i < 5; i++)
- {
- CS = 0;
- SPI_DR = 0x00;
- while(SPI_SR_TXE == 0);
- SPI_DR = 0xFF;
- while(SPI_SR_TXE == 0);
- while(SPI_SR_BSY == 1);
- asm("NOP");
- CS = 1;
- sleep(5000);
- }
- // uint8 data[2];
- // data[0] = 0x00;
- // data[1] = 0xFF;
- //
- // while(TRUE)
- // {
- // data[0] = 0x80;
- // data[1] = (uint8)~(1 << 7);
- //
- // TransmitSPI(data, 2);
- // }
- while(TRUE);
- }
Advertisement
Add Comment
Please, Sign In to add comment