工具与软件:
大家好、团队成员:
我将尝试使用 MSP430FR2676复制 Adafruit neopixel LED 的功能。 我发现一个在线库(msp430-NeoPixel-WS2812-Library/README.md、位于主控 mjmeli/msp430-NeoPixel-WS2812-Library··GitHub)、该库已在本论坛中讨论、并尝试根据 MSP430FR2676的数据表对其进行编辑。 但我无法打开 LED。 在这方面、您能帮忙吗?我在下面附上了代码。
非常感谢
Criton
#include <msp430.h> #define OUTPUT_PIN (0x04) //px.2 on msp430fr2676 #define NUM_LEDS (12) // NUMBER OF LEDS IN YOUR STRIP // Useful typedefs typedef unsigned char u_char; // 8 bit typedef unsigned int u_int; // 16 bit // Transmit codes #define HIGH_CODE (0xF0) // b11110000 #define LOW_CODE (0xC0) // b11000000 // Configure processor to output to data strip void initStrip(void); // Send colors to the strip and show them. Disables interrupts while processing. void showStrip(void); // Set the color of a certain LED void setLEDColor(u_int p, u_char r, u_char g, u_char b); // Clear the color of all LEDs (make them black/off) void clearStrip(void); // Fill the strip with a solid color. This will update the strip. void fillStrip(u_char r, u_char g, u_char b);
#include <msp430.h>
#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 |= BIT4 | BIT5 | BIT6;
FRCTL0 = FRCTLPW | NWAITS_1;
__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
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 < NUM_LEDS; i++) {
u_char rgb[3] = { leds[i].green, leds[i].red, leds[i].blue }; // get RGB color for this LED
// send green, then red, then blue
for (j = 0; j < 3; j++) {
u_char mask = 0x04; // b0000100
while (mask != 0) {
while (! UCB0IFG)
;
if (rgb[j] & mask) { // most significant bit first
UCB0TXBUF = HIGH_CODE; // send 1
} else {
UCB0TXBUF = LOW_CODE; // send 0
}
mask >>= 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();
fillStrip(0xFF, 0x00, 0x00);
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
}
}

