5873 views|14 replies

135

Posts

1

Resources
The OP
 

The interrupt service function is placed in a separate C file. How should the global variable array in the interrupt be defined? [Copy link]

 
The interrupt service function is placed in a separate C file. How should the global variable array in the interrupt be defined so that it can be used? This array is used in both the main program and the interrupt. After I define it, the compilation fails and the following error occurs: ADC1.o(.text+0xae): In function `_ADC1Interrupt': C:\Users\Administrator\Desktop\AD\ADC1.c:61: undefined reference to `ADCValue' I don't know what the reason is? The header file is as follows: #ifndef ADC1_H #define ADC1_H #define AINPUTS 0xffex //Analog inputs Set the multiplexed pin AN5 as the analog input pin. //#define AINPUTS 0xC0FF //Analog inputs Set the 6 multiplexed pins AN8~AN13 as analog input pins. /***Declare global variables****/ extern unsigned int ADCValue[6][32]; #endif The interrupt C source file is as follows: (other function settings are omitted, and the interrupt service function is given directly) #include
#include "ADC1.h" void __attribute__((interrupt,no_auto_psv)) _ADC1Interrupt(void) { int n,*BufPtr; char gNum; if(AD1CON2bits.BUFS) BufPtr=&ADC1BUF0; //The pointer points to the ADC1BUF0 unit, get the data in the lower 8-word buffer else BufPtr=&ADC1BUF8; //The pointer points to the ADC1BUF8 unit, get the data in the upper 8-word buffer for(n=0;n<6;n++) { ADCValue[n][gNum]=*BufPtr; //Transmit the collected data of 6 channels BufPtr++; } gNum++; if(gNum>=32)gNum=0; IFS0bits.AD1IF=0; //Clear interrupt flag }


This post is from Microchip MCU

Latest reply

Key points: The definition should be in the *.c file. The attached program you posted is in the *.h file. Delete "extern unsigned int ADCValue[6][32]; " in the *.h file. Change extern unsigned int ADCValue[6][32]; in the *.c file to unsigned int ADCValue[6][32] = {}; The OP needs to learn C language programming.   Details Published on 2018-12-20 09:38
 

6040

Posts

204

Resources
2
 
You need to define the following array in a C file: unsigned int ADCValue[6][32]; before you can reference it in other files.
This post is from Microchip MCU

Comments

This array is also defined in the ADC1.C file. The main program has not used this array yet, so the compilation fails.  Details Published on 2018-9-25 18:18
 
 
 

3471

Posts

11

Resources
3
 
extern unsigned int ADCValue[6][32]; If the extern is removed and the compilation succeeds, the array is not defined.
This post is from Microchip MCU

Comments

Removing extern doesn't work either  Details Published on 2018-9-25 18:26
Removing extern doesn't work either  Details Published on 2018-9-25 18:14
 
 
 

135

Posts

1

Resources
4
 
ienglgge posted on 2018-9-25 13:42 extern unsigned int ADCValue[6][32]; If you remove extern and the compilation passes, it means that the array is not defined.
Removing extern does not work either
This post is from Microchip MCU

Comments

Removing extern does not work either. What is the prompt? . Arrays can only be defined in one file, but can be defined in multiple files with extern  Details Published on 2018-9-26 10:23
 
 
 

135

Posts

1

Resources
5
 
lcofjp posted on 2018-9-23 16:11 You need to define the following array in a C file: unsigned int ADCValue[6][32]; before you can reference it in other files
This array is also defined in the ADC1.C file. The main program has not used this array yet and the compilation fails
This post is from Microchip MCU
 
 
 

135

Posts

1

Resources
6
 
ienglgge posted on 2018-9-25 13:42 extern unsigned int ADCValue[6][32]; If you remove extern and the compilation passes, the array is not defined.
Please help me take a good look @dcexpert
This post is from Microchip MCU
 
 
 

135

Posts

1

Resources
7
 
Great Gods, please help me take a look, the program is in the attachment

AD.zip

93.74 KB, downloads: 3

This post is from Microchip MCU
 
 
 

1w

Posts

25

Resources
8
 
This post was last edited by dcexpert on 2018-9-25 19:54 You only defined extern unsigned int ADCValue[6][32]; this only means that this variable exists somewhere else in the system. You did not define the actual variable, so of course an error message will be prompted. You need to define an unsigned int ADCValue[6][32] in a C file.
This post is from Microchip MCU
 
 
 

3471

Posts

11

Resources
9
 
werjufour posted on 2018-9-25 18:14 Removing extern doesn't work either
Removing extern doesn't work either, what's the hint? . Arrays can only be defined in one file, but can be extern in multiple files
This post is from Microchip MCU
 
 
 

637

Posts

2

Resources
10
 
PIC uses arrays in interrupts, but the compiler doesn't seem to support it, especially for 8-bit PIC microcontrollers.
This post is from Microchip MCU
 
 
 

29

Posts

0

Resources
11
 
Define unsigned int ADCvalue[6][32] in ADC.c file. Declare extern unsigned int ADCvalue[6][32] in ADC.h file.
This post is from Microchip MCU
 
 
 

6366

Posts

4936

Resources
12
 
Define unsigned int ADCvalue[6][32] in main.c file. Declare extern unsigned int ADCvalue[6][32] in ADC.c file.
This post is from Microchip MCU
 
 
 

6

Posts

0

Resources
13
 
The above is the orthodox way. Recommended.
This post is from Microchip MCU
 
 
 

2

Posts

0

Resources
14
 
The compiler does not support
This post is from Microchip MCU
 
 
 

6

Posts

0

Resources
15
 
Key points: The definition should be in the *.c file. The attached program you posted is in the *.h file. Delete "extern unsigned int ADCValue[6][32]; " in the *.h file. Change extern unsigned int ADCValue[6][32]; in the *.c file to unsigned int ADCValue[6][32] = {}; The OP needs to learn C language programming.
This post is from Microchip MCU
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list