Content originally posted in LPCWare by kiantek on Tue Jan 27 02:44:06 MST 2015
Hi, I am confused with the use of #INCLUDE in LPCOpen. I have tried numerous attempt in modifying the code and Google for the answer, but I couldn't find a concrete explanation.
I'm developing using LPCOPEN_17XX_BOARD_EA1788. I have created a new LPCOpen project with src folder and inc folder. Error start when I tried to split the main source file into multiple functional source files.
For instance, I have created d_screen.h and d_screen.c in 'inc' folder and 'src' folder respectively.
<d_screen.h>
#ifndef D_SCREEN_H_
#define D_SCREEN_H_
LPC_USART_T *pUART;
void myTest(void);
#endif /* D_SCREEN_H_ */
<d_screen.c>
#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif
LPC_USART_T *pUART;
void myTest(void) { LPC_USART_T myUART; }
Above code can be compiled without any error. But I am puzzled with the following:
Q1:
Why <d_screen.h> does not required definition of LPC_USART type? Shall I insert #include "uart_17xx_40xx.h" at header?
Q2:
For <d_screen.c>, I failed to compiled if I change the lengthy header into #include "uart_17xx_40xx.h". Console show multiples errors as follow:
>> error: unknown type name '__IO'
>> error: expected ':', ',', ';', '}' or '__attribute__' before 'DLL'
>> error: unknown type name '__IO'
Since I'm using LPC_USART type, why can't I simply include the related header files?
Q3:
For <d_screen.c>, is there a need to insert header #include "d_screen.h"?
Q4:
Can I repeatedly use the following code for all functional source files i.e. driver files?
#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif
Please advise me! My project files are getting very messy when I split the single main.c into different source file.
I hope experienced programmer could share your coding convention for similar situation.
Thank you.
Sincerely,
KT