Jump to content

#defines for J5 as digital output


ilmenator
 Share

Recommended Posts

I am using J5 as digital output for a number of control signals. As these signals might be located on other pins in the future (depending on the hardware design), I would like to design my code such that the "pin mapping" can easily be reconfigured in the future.

So, instead of writing

PORTAbits.RA2 = 1;
I would prefer something like
Clk_LData = 1;
with Clk_LData being the name of the signal. I'm still no programmer, but would something like
/////////////////////////////////////////////////////////////////////////////
// Global definitions
/////////////////////////////////////////////////////////////////////////////

#define Clk_LData     PortAbits.RA1

in main.h do what I want? It compiles okay, but I am without hardware right now and cannot properly test it...

Thanks a lot, ilmenator

Link to comment
Share on other sites

So yes, as per the chat, the variables are case-sensitive, so we need "PORTAbits.RA1" :)

Typos suck. I always forget the semicolons at the end of the line. I mean like aaaaaall the time, maybe one in every 50 lines I write..... I dunno what's wrong with my brain :D

For those not in the chat:

[stryd_one] 12:13 am: illy hot tip for ya (i'll put this in the thread too)

[stryd_one] 12:13 am: sdcpp is your friend

[stryd_one] 12:14 am: you can run the preprocessor standalone to see what your code outputs

[stryd_one] 12:14 am: and that's what i'm about to do right now    

[stryd_one] 12:17 am: i create test.c:

#define Something PORTAbits.RA1
Something=1;
[stryd_one] 12:18 am: that's all just the two lines.. you can do it with the whole file if you want, it doesn't alter it [stryd_one] 12:19 am: then I run sdcpp (Small Device C PreProcessor...what handles the defines and #ifs and such) against the file:
C:\Temp>sdcpp test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"

PORTAbits.RA1=1;

C:\Temp>
[stryd_one] 12:19 am: works like a charm [stryd_one] 12:20 am: btw, you can output to a file like this:
sdcpp <yourfile.h> -o <output filename>

[stryd_one] 12:21 am: sdcpp --help will show you a billion pages of options

HTH!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...