[問題] C跨檔案公用變數
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Windows MPLAB X
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
xc.h -->microchip libraries
問題(Question):
我現在有一個header -> INCLUDE.h
裡面引入多個header ---myLCD.h,INIT.h
我想要讓我的main可以更動INIT.h底下的INIT.c的一個變數
我使用extern 宣告該變數於INIT.h
並宣告該變數於INIT.c
但compile該專案卻跳出這行
(在main的地方)error: 'PWMValue' undeclared (first use in this function)
請問問題出在哪裡
或者是是否有更好的方法?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
error: 'PWMValue' undeclared (first use in this function)
程式碼(Code):(請善用置底文網頁, 記得排版)
我只放部分
main.c:
#include"INCLUDE.h"
int main(){
...
sprintf( input1 , "PWM = %lld " , PWMValue );
...
}
INCLUDE.h:
#ifndef INCLUDE_H
#define INCLUDE_H
#include <xc.h>
#include <stdio.h>
#include <string.h>
#include "INIT.h"
#include "MY_LCD.h"
#define Tcy 20000000 //10MHz oscillator with 8xPLL -> 20'000'000MIPS
#endif /* INCLUDE_H */
INIT.h
#ifndef INIT_H
#define INIT_H
void IO_init();
void PWM_init();
void Timer1_init();
void Interrupt_init();
void delay_us(unsigned int );
void delay_ms(unsigned int );
void _ISR _T1Interrupt();
void _ISR _INT1Interrupt();
extern unsigned int PWM_Value;
extern unsigned char flag;
#endif /* INIT_H */
INIT.c:
#include "INCLUDE.h"
unsigned int TIMER1_DELAY_VALUE;
unsigned int PWMValue;
...
void _ISR _INT1Interrupt()
{
PWMValue++;
IFS0bits.INT0IF = 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.224.246.127
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1440740897.A.792.html
※ 編輯: tommycc (125.224.246.127), 08/28/2015 13:49:17
※ 編輯: tommycc (125.224.246.127), 08/28/2015 13:52:22
※ 編輯: tommycc (125.224.246.127), 08/28/2015 14:03:00
※ 編輯: tommycc (125.224.246.127), 08/28/2015 14:03:35
※ 編輯: tommycc (125.224.246.127), 08/28/2015 14:25:05
推
08/28 14:46, , 1F
08/28 14:46, 1F
→
08/28 15:26, , 2F
08/28 15:26, 2F
→
08/28 15:27, , 3F
08/28 15:27, 3F
→
08/28 15:52, , 4F
08/28 15:52, 4F
→
08/28 16:12, , 5F
08/28 16:12, 5F
→
08/28 16:24, , 6F
08/28 16:24, 6F
→
08/28 16:25, , 7F
08/28 16:25, 7F
推
08/28 20:16, , 8F
08/28 20:16, 8F
→
08/31 02:06, , 9F
08/31 02:06, 9F
推
08/31 02:09, , 10F
08/31 02:09, 10F