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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
821 Views
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

Labels (1)
1 Solution
542 Views
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

View solution in original post

3 Replies
542 Views
karthick1987
Contributor II

Hey guys,

Any one with some advice?

0 Kudos
543 Views
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

542 Views
karthick1987
Contributor II

Yup thanks for that again Erich!

0 Kudos