Passing a #define to include files

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In program like program.c I have

#define lcd_ddr   DDRC
#define lcd_port  PORTC

In an include like include.h I would like to use something like

lcd_ddr = 0xff;
lcd_port = 0xf7;

This way the include.h can be universal for micros with and without a PORTC. All I have to do is change the code in program.c to DDRB and PORTB.

Is there a way this can be done?

Thanks,
Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One normally doesnt put code in include files or variable declarations.

You would put the #defines in the .h file

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should study "managing large pjts." tutorial in that forum.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put the #define before the #include.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the first post you surely have things the wrong way round? The #defines would be in the .h and the assignments in the .c ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TimothyEBaldwin wrote:
Put the #define before the #include.

Thanks Timothy, thats the answer I was looking and hoping for. Works just like I want it to.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Place your code in a separate c file, not a H file. Then you have your H file to act as the linkage between your "library" routines and your program. To pass configuration/implementation details, you can place that data in a dedicated config.h or pass it to the compiler with the -D parameter via your make file.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.