我在一个牧人文件中初始化一个外部变量,然后在(.c)文件中使用它,但是当我编译我的代码时,我得到一个警告说:没有以前的非静态变量的外部声明。下面是我的代码:
enter code here
/*led.h
extern int iStep = +1;
static void SetLEDPort2Output(void);
void LEDPortIni(void);
void LEDSet(unsigned char Value);
void PB10IntIni(void);
void TIM3IntIni(void);
void EXTI15_10_IRQHandler(void);
void TIM3_IRQHandler(void); */
/*led.c
#include <stm32f10x.h>
#include "led.h"
int iStep;
#define CHECKBIT(Var, Nr) (Var & (1<<Nr))
#define CLR_PORTBIT(PORT, BIT) {PORT->BRR |= (1<<BIT);}
#define SET_PORTBIT(PORT, BIT) {PORT->BSRR |= (1<<BIT);}
#define COPY_PORTBIT(Var, Nr, PORT, BIT) {if(CHECKBIT(Var, Nr)) SET_PORTBIT(PORT, BIT)
else CLR_PORTBIT(PORT, BIT)}
typedef struct
{
GPIO_TypeDef* aGPIO[7];
unsigned int aPIN[7];
} PORT;
static PORT LEDPort =
{{GPIOA, GPIOA, GPIOA, GPIOA, GPIOA, GPIOA, GPIOA},
{ 0, 1, 2, 3, 4, 5, 6}};
void EXTI15_10_IRQHandler(void)
{
if(GPIOB->IDR & (0x1<<10))
iStep = +1;
else
iStep = -1;
EXTI->PR |= (0x1<<10);
}
void TIM3_IRQHandler(void)
{
const unsigned char out[] = {0x1, 0x3, 0x6, 0xC, 0x18, 0x30, 0x60, 0x40};
static int i = 0;
i = (i + iStep) & 7;
LEDSet(out[i]);
} */
我没有在主函数中使用该变量。
似乎在led.h
extern int iStep = +1;
而在led.c
:
int iStep;
应该是相反的:
// Declaration in 'led.h'
extern int iStep;
// Definition in `led.c`
int iStep = 1;