Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC pin definitons in a C structure

Status
Not open for further replies.

ChrisRR

Newbie level 6
Joined
Aug 8, 2009
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,393
I'm not an amazing C programmer so bear with me.

On my PIC I have 5 controls that have one input and one output each. They have a structure on the C code that stores the variables and I want it to store the pins that it's interfacing too.

Say that the pin i want to interface is PORTDbits.RD0, how would I include that in my structure?
I presume that it would be some sort of pointer but I'm not too sure how to define that. What sort of data type does the pin pointer need to be?

If I'm completely on the wrong track then please let me know how it should be done

Added after 29 minutes:

Also I just realised my stupid mistake that I should be using LATDbits instead of PORTDbits. But either way, that's irrelevant to my question.
 

Which C compiler are you using?

Here is a nice tutorial to give you a good kick start, if you're using MikroC PIC compiler.

Code:
http://www.mikroe.com/en/books/pic-books/mikroc/ch2/#c2v2

Good luck
 

I'm using the c18 compiler. Thanks for the link but I would hope that I'm slightly above that beginner level by now!

Maybe I should elaborate on my issue.

Code:
typedef struct{
  pin inputPin;
  pin outputPin;

  int var1;
  float var2;

  void (*function)(void *self);
} struct_t;

The function pointed to by this structure should take the input from an input pin, perform some calculations using the variables and output to the output pin.

I want to know if it is at all possible to replace that "pin outputPin" (which obviously is invalid) with a pointer that points to the actual pin "LATAbits.LATA0" or "LATAbits.LATA1".
And if this is possible, then what data type should the pointer be?
 

Hi !

I assume you are using microchip compiler.

My advise it... You should understand your c good very well. Then it is smart to wire some small programs about PIC peripherals... like IO. Try to get test program outputs as you like them to be, then just change your main program little to include IO functions into your main program code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top