#define macros in user defined header file not carried over to source .c files

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

#define macros in user defined header file not carried over to source .c files

跳至解决方案
890 次查看
karthick1987
Contributor II

Hi guys,

 

I am trying to interface a 20x4 LCD display with my DZ128 uC and I have written a couple of files for interfacing it, One is a header file (namely LCD.h) and the other is the .c file LCD.c. I have included them both in the source folder of the project and inside have various definitions. I have attached the files here.

 

The issue here is that when I debug the program the compiler dosent recognise the macro definitions in from the header file! (I dont get any errors from the build process as well) So If you could tell me what I am doing wrong that would be great!

 

Cheers

K

 

edit: In other words whats the right way to define the macros ? I tried including the header file in the MCUinit.h file but same result. I dont know why but for some reason the macros defined in LCD.h dont take effect until after I have gone into the for loop ! When I am in debug mode all the macros have junk values ! and after going into the main for loop it seems like they have taken the value of the macros!

 

Strange

Original Attachment has been moved to: LCD.h.zip

Original Attachment has been moved to: LCD.c.zip

Original Attachment has been moved to: main.c.zip

标签 (1)
1 解答
611 次查看
BlackNight
NXP Employee
NXP Employee

Hello,

if you expect to see values like

#define MACRO 1

in the debugger, then I must disappoint you. Macros are not variables in C. Macros are textually replaced in the source file by the compiler for the preprocessed file. So you will not have them showing up.

The other thing is: keep in mind that the compiler very likely will optimize things. So things might be in registers and not stored to variables yet.

Hope this helps,

Erich

在原帖中查看解决方案

3 回复数
611 次查看
karthick1987
Contributor II

Hey guys,

Any one with some advice?

0 项奖励
612 次查看
BlackNight
NXP Employee
NXP Employee

Hello,

if you expect to see values like

#define MACRO 1

in the debugger, then I must disappoint you. Macros are not variables in C. Macros are textually replaced in the source file by the compiler for the preprocessed file. So you will not have them showing up.

The other thing is: keep in mind that the compiler very likely will optimize things. So things might be in registers and not stored to variables yet.

Hope this helps,

Erich

611 次查看
karthick1987
Contributor II

Yup thanks for that again Erich!

0 项奖励