gpt4 book ai didi

调用必须有指针 - CCS 问题

转载 作者:行者123 更新时间:2023-11-30 20:30:56 26 4
gpt4 key购买 nike

我是这里的新手,但有一个问题没有答案。我正在使用来自德克萨斯州的 TM4C1294,代码中存在无数错误。但首先,我有这段代码。您可以看到,x3 具有从 PIN ADC0 读取的数据,但在 channel 中给我的错误是(obs.忽略 # 之前的星号,并且代码不完整,因为 CCS 中的主体的其余部分太大)。感谢您的关注!

 %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;
}
}
}

最佳答案

警告:这可能不完整,因为我不确定您的最终结果,但我们可以找出编译错误。我必须稍微自由地添加一个 main 函数,这样我才能得到可编译的东西。

这是您最新程序的重新缩进版本[有错误]:

#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;
}
}
}

这是gcc错误输出:

fix1.c: In function ‘main’:
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:46:21: note: in expansion of macro ‘x3’
y0_aux = y0_aux + x3[i];
^~
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:47:23: note: in expansion of macro ‘x3’
ya1_aux = ya1_aux + x3[i] * sin(alfa);
^~
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:48:23: note: in expansion of macro ‘x3’
yb1_aux = yb1_aux + x3[i] * cos(alfa);
^~

这是一种改变事物的方法[这可以干净地编译]:

#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;
}
}
}

但是,从 ADC0_read 建立索引对我来说没有意义。您的 for 循环达到 12000,但 ADC_read 只有 5 个元素,因此上面的任一变体都可能会出现段错误,因为您远远超过了数组末尾。

更有可能的是,您可能想要类似的东西:

uint32_t ADC_read[12000];

#define x3(o) ADC_read[(o) + 0]
#define x2(o) ADC_read[(o) + 1]
...

老实说,我不明白各个指针(ADC3_read等)如何适应[well]

关于调用必须有指针 - CCS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976314/

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