gpt4 book ai didi

c - 十六进制数组和十六进制文字的区别

转载 作者:太空宇宙 更新时间:2023-11-04 06:18:00 25 4
gpt4 key购买 nike

我什至不能 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 值...也许?

最佳答案

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

关于c - 十六进制数组和十六进制文字的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41387333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com