Thank you for getting back to me promptly. but it will have the same effect if I do it in a function as it is passed in main right? I have called it in main however still the same thing it does not light up. I have attached the code for your reference. Kind regardds, Criton #include #include "msp430fr2676.h" #include "rgb.h" typedef struct { u_char red; u_char green; u_char blue; } LED; LED leds[NUM_LEDS] = { { 0, 0, 0 } }; // Initializes everything needed to use this library. This clears the strip. void initStrip() { P1SEL0 |= OUTPUT_PIN; // configure output pin as SPI output P1SEL1 &= ~OUTPUT_PIN; // P1.2 as UCB0SIMO per SLASEO5D Table 9-23 UCB0CTLW0 |= UCCKPH + UCMSB + UCMST + UCSYNC + UCSSEL_2; // 3-pin, MSB, 8-bit SPI master UCB0BR0 = 3; // 16 MHz / 3 = .1875 us per bit UCB0BR1 = 0; UCB0CTLW0 &= ~UCSWRST; // Initialize USCI state machine clearStrip(); } // Sets the color of a certain LED (0 indexed) void setLEDColor(u_int p, u_char r, u_char g, u_char b) { leds[p].red = r; leds[p].green = g; leds[p].blue = b; } // Send colors to the strip and show them. Disables interrupts while processing. void showStrip() { __bic_SR_register(GIE); // disable interrupts // send RGB color for every LED int i, j; for (i = 0; i >= 1; // check next bit } } } // send RES code for at least 50 us (800 cycles at 16 MHz) __delay_cycles(800); __bis_SR_register(GIE); // enable interrupts } // Clear the color of all LEDs (make them black/off) void clearStrip() { fillStrip(0x00, 0x00, 0x00); // black } // Fill the strip with a solid color. This will update the strip. void fillStrip(u_char r, u_char g, u_char b) { int i; for (i = 0; i < NUM_LEDS; i++) { setLEDColor(i, r, g, b); // set all LEDs to specified color } showStrip(); // refresh strip } void gradualFill(u_int n, u_char r, u_char g, u_char b); int main(void) { WDTCTL = WDTPW | WDTHOLD; initStrip(); __bis_SR_register(SCG0); // disable FLL CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source CSCTL0 = 0; // clear DCO and MOD registers CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz CSCTL2 = FLLD_0 + 487; // set to fDCOCLKDIV = (FLLN + 1)*(fFLLREFCLK/n) // = (487 + 1)*(32.768 kHz/1) // = 16 MHz __delay_cycles(3); __bic_SR_register(SCG0); // enable FLL while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked fillStrip(0xFF, 0xFF, 0xFF); showStrip(); while (1) { gradualFill(NUM_LEDS, 0x00, 0xFF, 0x00); // green gradualFill(NUM_LEDS, 0x00, 0x00, 0xFF); // blue gradualFill(NUM_LEDS, 0xFF, 0x00, 0xFF); // magenta gradualFill(NUM_LEDS, 0xFF, 0xFF, 0x00); // yellow gradualFill(NUM_LEDS, 0x00, 0xFF, 0xFF); // cyan gradualFill(NUM_LEDS, 0xFF, 0x00, 0x00); // red } } void gradualFill(u_int n, u_char r, u_char g, u_char b){ int i; for (i = 0; i < n; i++){ // n is number of LEDs setLEDColor(i, r, g, b); showStrip(); _delay_cycles(1000000); // lazy delay } }
↧