全局变量的冲突类型 C



我想使用一个文件来包含我所有的 #define 和常量:示例

#ifndef CONSTANTS_H_
#define CONSTANTS_H_
#include <avr/io.h>
//OVERALL DEFS
#define TRUE 1
#define FALSE 0

// CLK_32MHz.h
const uint8_t NEW_CLOCK_FREQ = 0b00000010;
#endif /* CONSTANTS_H_ */

然后调用不同的文件来调用它。例:

#ifndef CLK_32MHZ_H_
#define CLK_32MHZ_H_
#include <avr/io.h>
#include "constants.h"
extern uint8_t NEW_CLOCK_FREQ;    
void Change_CLK_32HZ(){
//Set the clk config
OSC_CTRL = NEW_CLOCK_FREQ;
//Wait for the right flag to be set in the OSC_STATUS reg 
while((OSC_STATUS & PIN1_bm) != PIN1_bm);
//Write the “IOREG” signature to the CPU_CCP reg
CPU_CCP = CCP_IOREG_gc;
//Select the new clock source in the CLK_CTRL reg
CLK_CTRL = CLK_SCLKSEL_RC32M_gc;
return;
}
#endif /* CLK_32MHZ_H_ */

这是我的主要功能:

#include <avr/io.h>
#include "constants.h"
#include "Clk_32MHz.h"

int main(void){
}

这是我在终端上收到的错误:

"NEW_CLOCK_FREQ"文件的冲突类型限定符:Clk_32MHz.h 以前对"NEW_CLOCK_FREQ"的定义在这里 文件:常量.h

尝试以下操作...

在标题.h中:

extern const uint8_t myconst;

在 foo.c 中:

#include "header.h"
const uint8_t myconst = 42;

最新更新