×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Embedded PIC C programming

Embedded PIC C programming

Embedded PIC C programming

(OP)
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.

RE: Embedded PIC C programming

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

RE: Embedded PIC C programming

(OP)
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.

RE: Embedded PIC C programming

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.

RE: Embedded PIC C programming

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

RE: Embedded PIC C programming

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
}

RE: Embedded PIC C programming

"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.

RE: Embedded PIC C programming

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

Cheers

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources