#define F_CPU 25000000L //includes #include "Arduino.h" extern "C" { #include } // //Pin connected to latch pin (ST_CP) of 74HC595 const int latchPin = 20; //Pin connected to clock pin (SH_CP) of 74HC595 const int clockPin = 15; ////Pin connected to Data in (DS) of 74HC595 const int dataPin = 17; #define SCLK BIT5 //#define CS BIT5 #define MOSI BIT7 #define MISO BIT6 //#define CLKPORT P1OUT #define LATPORT P2OUT //#define DATPORT P1OUT //#define CLKBIT BIT1 #define LATBIT BIT0 //#define DATBIT BIT0 #define NumMatrixCols 4 //uint16_t LEDChannels[NumMatrixCols*8][3] = {0}; float offset = 0; /*void SPI_write(uint8_t addr, uint8_t value) { //P1OUT &= ~CS; UCA0TXBUF = addr; __bis_status_register(LPM4_bits|GIE); UCA0TXBUF = value; __bis_status_register(LPM4_bits|GIE); //P1OUT |= CS; }*/ #define SPI_write(value) {\ UCB0TXBUF = value;\ __bis_status_register(LPM4_bits|GIE);\ } void SPI_init() { P1SEL |= SCLK|MOSI|MISO; P1SEL2 |= SCLK|MOSI|MISO; UCB0CTL1 = UCSWRST; /* Hold USCI */ UCB0CTL0 = UCMST; /* Master mode */ UCB0CTL0 |= UCSYNC; /* SPI mode? */ UCB0CTL0 |= UCMSB; /* MSB first */ UCB0CTL0 |= UCCKPH; /* Bit shiftout on rising edge, */ UCB0CTL1 |= UCSSEL_2; /* SMCLK */ UCB0BR1 = 0; UCB0BR0 = 0; UCB0CTL1 &= ~UCSWRST; IE2 |= UCB0RXIE | UCB0TXIE; __eint(); } void setup() { SPI_init(); //SPI_write(0x04, 0x00); /* Shutdown */ //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); //pinMode(dataPin, OUTPUT); //pinMode(clockPin, OUTPUT); } void display() { /*for (int numberToDisplay = 0; numberToDisplay < 8; numberToDisplay++) { for (int mat = 0; mat < NumMatrixCols; mat++) { LATPORT &= ~LATBIT; fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 255); fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 0); fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 255); fastShiftOut(DATPORT, dataPin-10, clockPin-10, LSBFIRST, BITS[numberToDisplay]); LATPORT |= LATBIT; delayMicroseconds(10); LATPORT &= ~LATBIT; fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 0); fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 255); fastShiftOut(DATPORT, dataPin-10, clockPin-10, MSBFIRST, 0); fastShiftOut(DATPORT, dataPin-10, clockPin-10, LSBFIRST, BITS[numberToDisplay]); LATPORT |= LATBIT; delayMicroseconds(5); } //delay(1); }*/ uint8_t mat = 0; for (int numberToDisplay = 0; numberToDisplay < 8; numberToDisplay++) { // R LATPORT &= ~LATBIT; for (mat = 0; mat < NumMatrixCols; mat++) { SPI_write(255); SPI_write(0); SPI_write(255); SPI_write(BITS[numberToDisplay]); } LATPORT |= LATBIT; delayMicroseconds(12); // B LATPORT &= ~LATBIT; for (mat = 0; mat < NumMatrixCols; mat++) { SPI_write(0); SPI_write(255); SPI_write(255); SPI_write(BITS[numberToDisplay]); } LATPORT |= LATBIT; delayMicroseconds(8); // G LATPORT &= ~LATBIT; for (mat = 0; mat < NumMatrixCols; mat++) { SPI_write(255); SPI_write(255); SPI_write(0); SPI_write(BITS[numberToDisplay]); } LATPORT |= LATBIT; delayMicroseconds(7); //delay(1); } } interrupt(USCIAB0RX_VECTOR) ucarx_isr(void) { IFG2 &= ~UCB0RXIFG; __bic_status_register_on_exit(LPM4_bits); } interrupt(USCIAB0TX_VECTOR) ucatx_isr(void) { IFG2 &= ~UCB0TXIFG; __bic_status_register_on_exit(LPM4_bits); } void loop() { // count from 0 to 255 and display the number // on the LEDs display(); }