Connect with us

Pic, c programing

Discussion in 'Electronic Basics' started by Tuurbo46, Sep 6, 2004.

Scroll to continue with content
  1. Tuurbo46

    Tuurbo46 Guest


    Im currently trying to become more conversent with pic, whilst using c
    programming. Does anybody recommned any good books, or links to help me on
    this journey?

    Cheers Turbo
  2. Dingo

    Dingo Guest

    You should ask the same question over on the PicList -
    (Or search previous posts there)

    The only drawback is signing up to Yahoo.
    I bet you'll get 10 responses within 24 hours asking the same question
    there. (Very active group)

    BTW I too would like to see the answer to that question. If you are looking
    to free PIC C compilers a few were mentioned here -

    And I'm sure there are others.

  3. Don Taylor

    Don Taylor Guest

    "Programming Robot Controllers" by Predko describes using the free
    PICC Lite C compiler with the 16F627 (I think, it has been a few
    months) and the Microchip IDE simulator/debugger/etc.

    The only down side is that not too long after the book came out
    Microchip completely revised their IDE user interface, and may have
    done so again, and that makes small parts of the book that are
    trying to tell you how to get started and interface the output of
    the C compiler with the IDE, and using the IDE, much harder for a
    beginner. Somebody could write a small revision that would make
    this lots easier for the novice.
  4. Don Taylor

    Don Taylor Guest

    There tends to be one other drawback to C Compiler & PicList, since
    many/most of those folks got started writing code in raw assembly
    language, it seems that many folks who have a problem with something
    written in C and who ask the group often don't get wildly helpful
    answers other than "it is probably your compiler and why don't you
    learn assembly language for this like you are supposed to."

    When I had a problem I went WAY overboard checking everything that
    I could imagine, providing documentation, etc, etc, etc, and put
    all this into my first question for the list. The responses were
    mostly "wow, well written question, now, we still don't trust that
    you are using a compiler so why aren't you doing this in assembly?"

    Your mileage may vary, I hope it works out for you.
    And you can always toss me questions via email.
    I may give disclaimers but I really try to not tell
    you something when I actually don't know the answer.
    (email address is valid)
  5. CBarn24050

    CBarn24050 Guest

    There tends to be one other drawback to C Compiler & PicList, since
    hi, the reason is that the pics are particularly bad at running C programs. If
    you must use C switch to another chip.
  6. Yes, the PIC has a *strange* instruction set. It does not correspond very
    well to any conventional programming language.
  7. Dingo

    Dingo Guest

    Which chips are more 'C' friendly?
  8. Don Taylor

    Don Taylor Guest

    I respectfully tend to disagree. I think "culture" is usually the
    major reason that most people do and say what they do.

    I don't know about anyone else but the rather simplistic C code that
    I write when using the PIC seems to compile surprisingly well and it
    keeps me from making most of the little silly mistakes I'd otherwise
    make if I were writing assembly with my old and decaying brain cells.

    I served my time writing assembly code 30+ years ago and switched to
    writing compilers 20 years ago.
  9. James Beck

    James Beck Guest

    Now, that's about as dopey a statement as I've seen here in a while.

    I guess I had better tell all of my customers to throw away all of our
    products, they obviously don't work well, NOT......
    PICs don't have any problem running 'C'. Some of them (the 18 series)
    do a better job of it, but I have even done a quick and dirty servo
    pulse to camera interface in 'C' on a PIC12C509A in less than 5 minutes.
    I have done more than my fair share of BIG assembly projects to know I
    REALLY like 'C' and only resort to assembly where it is needed. It is
    also nice to have a common library of routines like CRC's, ADPCM, and so
    on that you can drag between MCU's/CPU's with out recoding. Do that in
    assembler. Besides good 'C' compilers do some pretty good optimizations
    these days. You should take a look at one.
  10. Almost anything else :) Atmel AVR particularly.
  11. Dingo

    Dingo Guest

    Had a feeling that would be your response.....think I'll struggle with C on
    PICs for now all the same
  12. CBarn24050

    CBarn24050 Guest

    hi, the reason is that the pics are particularly bad at running C programs.
    Well if you look around you will find much worse, like this one.> but I have
    even done a quick and dirty servo
    Just compare you c program running on a pic then run it on an avr. It is true
    that the 18 series make a much better job. If you can put up with using 5 times
    as much memory and a speed penalty of 10 to100 times slower then c is ok on
    these chips.
  13. Don Taylor

    Don Taylor Guest

    I dunno what kind of C code you guys are writing but when I look
    at the generated assembly listing, with the PICC Lite compiler
    optimizations turned on, I don't see that I would write assembly
    code any smaller than that in most cases. Subscripting into an
    array of constants that will never be modified looks to me like it
    could be better thought out by the guys that wrote the code
    generator but I understand they had to deal with the general case.
    Other than that I haven't found anything that takes 5x the code or
    10x-100x the time. I'm building state machines, reading inputs,
    deciding on transitions, driving outputs.

    Have you got an example where the code size is 5x larger than what
    PICC Lite with optimizations generates?
  14. CBarn24050

    CBarn24050 Guest

    I dunno what kind of C code you guys are writing but when I look
    It very hard to comment about the code your using if you quote some.I've never
    used picc lite so I can't comment on it, however since it has the word lite in
    it's title that usually means its not a real C compiler.
  15. What rubbish.
    Yes, the PIC 16x architecture is not optimised for high level
    languages, but that doesn't mean you can't or shouldn't use C with it.
    There are very good and efficient professional C compilers available
    for the PIC, just like every other micro.
    Using a good C compiler you shouldn't really notice the difference
    between using a PIC or another micro more optimised for higher level
    The good PIC C compilers can do everything a C compiler for any other
    micro can do. All micros will vary in speed and memory usage of
    compiler code to be sure, but there are so many other factors involved
    in chossing the right micro that compiler efficiency is usually way
    down on the list.

    Dave :)
  16. James Beck

    James Beck Guest

    I guess the bottom line is this :
    I have been an embedded programmer/designer since 1982, I have done more
    than my fair share of assembly code and still do, BUT I use 'C' as my
    predominate language for what I do to make a living. How about you?

    I was not commenting your statement on what processor would run what
    better/faster/most elegant. I am commenting on your ignorant statement
    that the OP should consider something other than a PIC if he/she wants
    to run 'C'. We don't know what the performance specs the OP is shooting
    for, do we? Running 'C' on a PIC maybe more than adequate for the job
    at hand. Making generalized statements just because you have a hard on
    for AVRs make a statement in itself. Reminds me of the old saying,
    "When all you have is a hammer, everything looks like a nail."

  17. CBarn24050

    CBarn24050 Guest

    so why not use a chip whos archtecture is opimised for C as they are the same
    I am not aware of any fully complient C compilers for the pic, I could be out
    of date of course.

    No you won't notice anything untill it really maters.
    Yes quite so, the problem is not the compiler but the missing hardware resorces
    on the pic.
  18. PIC-C Lite is the same high end compiler as the regular Hitech PICC,
    but it only supports a few specific chips.
    The PICC compiler is a really supurb and highly optimised compiler.
    When you look at the assembler generated it's pretty darn tight and
    you'd be hard pressed to write assembler that did much better on the
    size or speed front.
    Your statements that a C compiler for the PIC takes 5x the code or
    10-100x the time of an AVR one is just plain silly and ill-informed.
    You can get good and bad C compilers for the PIC and the same is true
    for the AVR or any other micro. But even a "bad" C compiler is not
    going to be an order of magnitude worse than a "good" one. The same
    goes for differences in micro architectures.

    I have recently started using C on the AVR and quite frankly I have
    the found the opposite to what you claim. The CodeVision compiler I
    used took more code space for floating point than my Hitech PICC
    compiler on the PIC 16 series. I was not that impressed.

    It's horses for courses.

    Dave :)
  19. There are many many reasons to choose the PIC over the Atmel and
    vice-versa, having an architechure optimised for C is usually WAY down
    on anyones list!

    You can't make blanket statements like the PIC and AVR are the same
    price, that is not comparing apples to apples. What about quatity?,
    what about availability?, what about choosing the exact features you
    want to save cost?, what about development systems and support?, what
    about migration paths to higher volume?, higher performance?, lower
    perfomance?, power?, pinout compatability?
    I could go on.

    I won't get into a debate over AVR vs PIC but suffice it to say that
    the PICs have a LOT going for them, which is why they outsell the
    Atmels and are used in everything from Smartcards to Playstations.
    How about being able to migrate from FLASH to OTP to mask ROM?
    How about having a truely massive device selection range to choose
    from to meet a specific application?
    How about having anything from a tiny SOT23 package to a DSP based

    The Atmels are poor competition in these areas.
    You are many years out of date.
    - PICC
    - Microchips own MPLAB C Compilers
    - IAR
    All are ANSI C complient.
    There are probably others.

    Dave :)
  20. CBarn24050

    CBarn24050 Guest

    Your statements that a C compiler for the PIC takes 5x the code or
    That isn't what I said.
    Thats very suprising, I too would not be impressed.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day