Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C code for PIC

Status
Not open for further replies.

DerStrom8

Super Moderator
Good day, everyone!
I'm currently trying to learn more about the programming of a PIC. I have used C to program VEX robots in the past, but I'm not exactly sure how to apply it to a PIC. Is anyone willing to post an example of C programming for a PIC, or point me towards a site that covers it?
Any help would be much appreciated!
Regards,
Der Strom

P.S. At this point I would really like to learn C rather than other programming languages because I already have a slight background in it.
 
What compiler are you planning to use.

Mike.

Hey, Mike! Thanks for the quick reply!
I plan on using MPLab IDE v. 8.60 (I already have it :D ), and I think that uses the HI-TECH C compiler.
Der Strom
 
There will be lots of examples on the HiTech web site. If there's any specific questions that you're stuck with just ask away.

Mike.
 
At the moment I'm having a little trouble figuring out and remembering the abbreviations. I know the basic commands (If-Then-Else, the While loop, etc.) but I am a bit confused about what types of things go inside the commands. I am really looking for a site that has a tutorial of some sort. I have found a couple of really good sites for learning Assembly, which I may try if I cannot find a C tutorial. Can anyone help me with this?
Many thanks!
Der Strom
 
Thanks Raj. I'll give those a try.
 
Ok, so on that link there's only small programs that, though easy to understand, do not help much in the long run. I am in need of full tutorials on how to write full, (relatively) large programs with several different commands, rather than simply, "While(1) { LED=1; Delay_ms(1000); LED=0; Delay_ms(1000); } etc.
Sorry if I seem picky or thankless. I do sincerely appreciate all the help I am being given.
Regards,
Der Strom
 
Last edited:
i have seen some good books for the ccs compiler personaly i use c18 but have found the ccs books useful as alot of it seems to apply to most compilers.
 
Ok, so on that link there's only small programs that, though easy to understand, do not help much in the long run. I am in need of full tutorials on how to write full, (relatively) large programs with several different commands, rather than simply, "While(1) { LED=1; Delay_ms(1000); LED=0; Delay_ms(1000); } etc.

Maybe you are getting a little too focused on C specifics and not on the task itself?

Generally a good programming method is to design it as a flowchart showing what the program needs to do, then writing that out as comments saying exactly what it is doing and WHY, then at the end you can stick in the code part quite easily, regardless of the language. In fact if you write code in this fashion it can be converted to other languages very easily.

Maybe you should start a thread on what your program needs to do with the operation or flowchart described, and if you like some more detailed operation described as comments, and people can help you with the specific code segments you might be having difficulties with?
 
Maybe you are getting a little too focused on C specifics and not on the task itself?

Generally a good programming method is to design it as a flowchart showing what the program needs to do, then writing that out as comments saying exactly what it is doing and WHY, then at the end you can stick in the code part quite easily, regardless of the language. In fact if you write code in this fashion it can be converted to other languages very easily.

Maybe you should start a thread on what your program needs to do with the operation or flowchart described, and if you like some more detailed operation described as comments, and people can help you with the specific code segments you might be having difficulties with?

Thank you all for the suggestions!
Mr RB: What I am actually trying to do is to learn C as it is used on a PIC. Therefore, I do not have an actual project on which I am working, as of yet. I would like to learn C so that I may write ANY program without much additional help, if it is possible. Does this make sense?
Again, I very much appreciate all the help :)
Der Strom
 
Mr RB: What I am actually trying to do is to learn C as it is used on a PIC. Therefore, I do not have an actual project on which I am working, as of yet. I would like to learn C so that I may write ANY program without much additional help, if it is possible. Does this make sense?

Well if you really want to learn to put PIC projects together very quickly then consider getting on of these development boards;
MikroElektronika - EasyPIC6 Development System - PIC Development Board and MikroC compiler that goes with it.

They have functions for control of all the peripherals you might need and tons of C examples, including all through the MikroC compiler help file. Within a few days you should be putting together some very impressive PIC C projects without the headache of trying to solder up hardware and hope you got all the wires in the right place, then not knowing if it's code that is broken or your soldering. :)
 
Well if you really want to learn to put PIC projects together very quickly then consider getting on of these development boards;
MikroElektronika - EasyPIC6 Development System - PIC Development Board and MikroC compiler that goes with it.

They have functions for control of all the peripherals you might need and tons of C examples, including all through the MikroC compiler help file. Within a few days you should be putting together some very impressive PIC C projects without the headache of trying to solder up hardware and hope you got all the wires in the right place, then not knowing if it's code that is broken or your soldering. :)

Wow! Thanks, RB, but it's a little out of my price range at the moment ;) I'll keep that in mind, though. Thanks!
Der Strom
 
Maybe this will help you decide. Comparison between picc-18 and C18. I started out using C18, but now I'm starting to think PICC-18 looks like it may be better, but I haven't used it much so look at the details and see what you prefer.

People should stick with one compiler till they get their feet under them. You are going to spend a good deal of time sorting the "non c" implementation differences. After that the C is till there.

I use PICC for 16F and C18 or 18F. PICC can be a bit easier due to some of the "built in's". Some people discourage their use because the code is more difficult to port to other C compilers. They can also make debugging a bit harder.

Having said that it is a good compiler with a very good users forum.

C18 is more of a nuts and bolts compiler. The unoptimized code generated by the student and expired demo versions ix large. But 18F's have enough memory that most users will not care.
 
Last edited:
I use PICC for 16F and C18 or 18F. PICC can be a bit easier due to some of the "built ins". Some people discourage their use because the code is more difficult to port to other C compilers. They can also make debugging a bit harder.

Having said that it is a good compiler with an very good users forum.

I'm looking into buying a PIC32F kit that I found online for a really good price. Which should I use if I end up buying the kit?
Many thanks for all the replies! They are greatly appreciated :)
Der Strom
 
I do not know much anything about the 32 bit'ers. But I would investigate the tool chains first and base my choice of processor brand/arch based on that. We can afford the chips but some of the tools are out our our reach.
 
I would stay away from the bigger chips and start with the 18 series. For a compiler I'd start with one of the free versions, C18, HiTech C or BoostC. Try to stay away from library routines as you will then be learning how to use the library rather than the language and chip. Also, some of the boards available online are very badly supported, the ones by FutureLec being one example. If you're going to buy a board then check how easy it is to find examples on the net.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top