Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded PIC C programming

Status
Not open for further replies.

shamone

Electrical
Jun 8, 2005
30
Hey guys, I was wondering if anyone could direct me to a site that explains, in detail, embedded C programming for PIC microcontrollers. I am trying to learn how to manipulate data on PORTS such as see if a switch has been pressed and stuff like that. It seems quite trivial and i can do it in assembly but i am a little confused. Any help would be appreciated.
 
Replies continue below

Recommended for you

Did you know that switches 'bounce'? I.e., go on and off, briefly, perhaps hundreds of times, before assuming a stable state? Dealing with that well requires nontrivial code, in any language.

{
Personally, I would program a PIC in C only if "tied to a horse, and dragged forty miles ... by my tongue". Perhaps you have other incentives.
}

What about the documentation that came with your C compiler? And all the stuff on the Microchip CD?






Mike Halloran
NOT speaking for
DeAngelo Marine Exhaust Inc.
Ft. Lauderdale, FL, USA
 
So what you are saying is that you enjoy itP-). I am just re-learning my C code as i haven't done it in awhile and i am familiar with PIC's back in my school days. So it is just for educational purposes. And yes I am aware of bouncy switches.
 
To MikeHalloran-

Hi Mike-

You might want to do a google search on "cc5x" and revisit
the C compilers for PICs.

It's a freebie that runs on Windoze, but aside from that
limitation, it isn't too bad.

As an evaluation example, I did a "geek-clock" with it using
my favorite mid-level pic, 16f648A.

Turns out that although there were some differences and
implementation details (some of the K&R C code didn't
compile and had to be worked around) it came up pretty
clean.

With the "freebie" package, you get a floating point math
package (although not the complete package) and can have
oddles of fun with it for no investment.

The code is surprisingly compact and with the mixed listing,
I found it to be very easy to use with the microchip
simulator.

YMMV, of course, but I think that it will be a tool that I
will keep in my toolbox.

Cheers,

Rich S.
 
I've lost count of the hours I've spent chasing bugs that were 'my fault', because I didn't know about one weird behavior or another of C or its accursed preprocessor.

I'd much rather deal with a language whose behavior can be completely described in one paragraph; FORTH. Or, no language at all, just a decent assembler that does what it's told to do.





Mike Halloran
NOT speaking for
DeAngelo Marine Exhaust Inc.
Ft. Lauderdale, FL, USA
 
Down load the c18 compiler and look at the examples.

Here is a read and a write to port b. write commented out.

#include <p18cxxx.h> /* for TRISB and PORTB declarations */

/*
void main (void)
{
TRISB = 0; //sets port b as all outputs
PORTB = 255; //set port b bits
}
*/
int buttons;

void main (void)
{
TRISB = 255; //sets port b as all inputs
buttons = PORTB; //read port b bits
}
 
"behavior or another of C or its accursed preprocessor"

One man's pleasure is another man's poison.

I've used the C preprocessor quite a number of times all
by itself to manipulate data and find it a blessing.

Each to his own.

Cheers,

Rich S.
 
Yah that is what i think, thanks guys, it is all coming back slowly. Got some books on theway which help me out.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor