十六进制数组和十六进制文字之间的差异

时间:2016-12-29 21:19:29

标签: c arrays

我甚至不能100%确定我正确地标记了标题但是这里有。我正在尝试使用these LED's。我必须通过SPI总线写入它,这一切都正常,但有一些奇怪的事情,我不知道为什么。

我想让LED“脉冲”。如果我这样做,它可以正常工作:

quadrantFrame_1[0] = 0xe9;
quadrantFrame_1[1] = 228;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe8;
quadrantFrame_1[1] = 228;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe7;
quadrantFrame_1[1] = 228;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe6;
quadrantFrame_1[1] = 218;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe5;
quadrantFrame_1[1] = 208;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe4;
quadrantFrame_1[1] = 198;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe3;
quadrantFrame_1[1] = 188;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe2;
quadrantFrame_1[1] = 178;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe1;
quadrantFrame_1[1] = 168;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe0;
quadrantFrame_1[1] = 158;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe1;
quadrantFrame_1[1] = 168;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe2;
quadrantFrame_1[1] = 178;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe3;
quadrantFrame_1[1] = 188;
Update_SPI();

CyDelay(delay + 10);

quadrantFrame_1[0] = 0xe4;
quadrantFrame_1[1] = 198;
Update_SPI();

CyDelay(delay);

quadrantFrame_1[0] = 0xe5;
quadrantFrame_1[1] = 208;
Update_SPI();

CyDelay(delay);

quadrantFrame_1[0] = 0xe6;
quadrantFrame_1[1] = 218;
Update_SPI();

CyDelay(delay);

quadrantFrame_1[0] = 0xe7;
quadrantFrame_1[1] = 228;
Update_SPI();

CyDelay(delay);

quadrantFrame_1[0] = 0xe8;
quadrantFrame_1[1] = 238;
Update_SPI();

CyDelay(delay);

quadrantFrame_1[0] = 0xe9;
quadrantFrame_1[1] = 238;
Update_SPI();

其中quadrantFrame_1[0]是亮度,quadrantFrame_1[1]是蓝色值(您无需担心)。因此,如果我执行上面的代码,它可以完美地运行...意味着亮度逐渐下降然后再回升。

我正试图通过使用几个for循环来清理它:

unsigned char values[10] = {0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9};

for (i = 0; i <= 9; i++) {
    quadrantFrame_1[0] = values[i];
    quadrantFrame_1[1] = 228;
    Update_SPI();

    CyDelay(delay + 10);
}

for (i = 9; i >= 0; i++) {
    quadrantFrame_1[0] = values[i];
    quadrantFrame_1[1] = 228;
    Update_SPI();

    CyDelay(delay + 10);
}

所以,有了这个,它应该逐渐变得更亮,然后调整所有同时保持相同的颜色......但是,如果我这样做,它绝对是疯了。颜色开始变为蓝色/紫色/红色等。而且亮度到处都是。

我能看到的唯一区别是,在工作解决方案中,我明确设置了值:quadrantFrame_1[0] = 0xe9;。然后在非工作解决方案中,我尝试从数组中设置它:quadrantFrame_1[0] = values[i];

我不明白为什么数组尝试不起作用?

根据数据表,我知道我的位需要正确: enter image description here

他们应该是第一个例子。我不确定这是否有效,因为我明确设置了值,然后第二个示例不起作用,因为它们被转换为数组中的unsigned char值...也许?

1 个答案:

答案 0 :(得分:4)

问题是第二个循环primefac中的拼写错误,您应该在其中编写for (i = 9; i >= 0; i++) {而不是i--