调用必须有CCS的指针问题
我是这里的新手,但有一个没有答案的问题。我使用的是来自德克萨斯州的TM4C1294,代码中有无数错误。但首先,我有这个代码。您可以看到,x3从引脚ADC0读取数据,但在通道中给我的错误是obs。忽略前面的星号,代码不完整,因为CCS中身体的其余部分太大。谢谢你的关注调用必须有CCS的指针问题,c,texas-instruments,C,Texas Instruments,我是这里的新手,但有一个没有答案的问题。我使用的是来自德克萨斯州的TM4C1294,代码中有无数错误。但首先,我有这个代码。您可以看到,x3从引脚ADC0读取数据,但在通道中给我的错误是obs。忽略前面的星号,代码不完整,因为CCS中身体的其余部分太大。谢谢你的关注 %declaration of pointers to PIN read #define F_SAMPLE 2000 #define x0 *ADC3_read #define x1 *ADC
%declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0 *ADC3_read
#define x1 *ADC2_read
#define x2 *ADC1_read
#define x3 *ADC0_read
#define x4 *ADC4_read
%declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0, ya1, yb1, y_1;
float y0_aux, ya1_aux, yb1_aux;
int alfa, i, j;
%declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read=&ADC_read[0];
uint32_t *ADC1_read=&ADC_read[1];
uint32_t *ADC2_read=&ADC_read[2];
uint32_t *ADC3_read=&ADC_read[3];
uint32_t *ADC4_read=&ADC_read[4];
%control code
for( i=0; i <= 12000; i++)
{
alfa = alfa + (2*PI/200);
if (alfa >= 2*PI)
alfa = alfa - 2*PI;
j++;
y0_aux = y0_aux + x3[i]; %error=identifier "x3" is undefined
ya1_aux = ya1_aux + x3[i]*sin(alfa);
yb1_aux = yb1_aux + x3[i]*cos(alfa);
if(j==200){
y_0 = y0_aux/200;
ya1 = ya1_aux/200;
yb1 = yb1_aux/200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
警告:这可能不完整,因为我不确定您的最终结果,但我们可以找出编译错误。我不得不稍微随便添加一个主函数,这样我就可以得到一些可编译的东西
这是您的最新程序的更新版本[有错误]:
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0 *ADC3_read
#define x1 *ADC2_read
#define x2 *ADC1_read
#define x3 *ADC0_read
#define x4 *ADC4_read
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3[i];
ya1_aux = ya1_aux + x3[i] * sin(alfa);
yb1_aux = yb1_aux + x3[i] * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
这里有一种方法可以改变事情[这可以干净地编译]:
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0 ADC3_read
#define x1 ADC2_read
#define x2 ADC1_read
#define x3 ADC0_read
#define x4 ADC4_read
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3[i];
ya1_aux = ya1_aux + x3[i] * sin(alfa);
yb1_aux = yb1_aux + x3[i] * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0(o) ADC3_read[o]
#define x1(o) ADC2_read[o]
#define x2(o) ADC1_read[o]
#define x3(o) ADC0_read[o]
#define x4(o) ADC4_read[o]
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3(i);
ya1_aux = ya1_aux + x3(i) * sin(alfa);
yb1_aux = yb1_aux + x3(i) * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
老实说,我看不出单个指针ADC3\u read等如何适应[well]重新定义如下:定义x3offset\u ADC0\u read[offset\u],我认为这会起作用。同样,对于其他宏。@CraigEstey现在在表达式y0_aux=y0_aux+*x3i中给出了以下错误:;*的操作数必须是指针。我已更改为指针,但什么也没有发生,我必须做什么?按照[原始]说明:-。也就是说,我说的是更改定义,而不是其他任何内容。你的原始方程是y0_aux=y0_aux+x3i。有了这一点,再加上我建议的“定义变化”,它就会起作用。但是,您也[错误地]通过执行y0_aux=y0_aux+*x3i添加了一个*。请理解,要取消对带有偏移量的指针的引用,可以执行以下操作:*ptr+off或[这通常更可取]:ptr[off]。您的第二次尝试相当于*ptr[off],这是不同的。所以,只需删除额外的*我已经按照您最初的指示:但没有工作:这就是为什么我做了更改。然而,即使采纳了您所说的,错误仍然存在。此时,我将编辑您的问题并发布[更多]您的完整代码,包括ADC0_read的定义等。我的假设是它类似于定义ADC0_read 0x8010。此外,y0_aux等的定义也会发布准确的错误消息
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0(o) ADC3_read[o]
#define x1(o) ADC2_read[o]
#define x2(o) ADC1_read[o]
#define x3(o) ADC0_read[o]
#define x4(o) ADC4_read[o]
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3(i);
ya1_aux = ya1_aux + x3(i) * sin(alfa);
yb1_aux = yb1_aux + x3(i) * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
uint32_t ADC_read[12000];
#define x3(o) ADC_read[(o) + 0]
#define x2(o) ADC_read[(o) + 1]
...