What is the standard programming language for PICs? - Page 1
Forum section: electronics / general

author: microbug
author_rank: Frequent Contributor
timestamp: June 18, 2013, 06:57:56 pm
content: Hi,I am beginning with microcontrollers in general - I have a few ATMEGAs + an Arduino, and I like using them (Atmels) a lot because you can program them in C.I had a quick look into using PICs as they seem to be (correct me here) more common, and that must be for a reason. However, when I looked into it all I could see with regards to options was PICAXE and assembly. Are PICs normally programmed in assembly language or is it possible to program them in C / C++?

author: Skimask
author_rank: Super Contributor
timestamp: June 18, 2013, 07:00:24 pm
content: PICs, like every other MCU, are programmed using whatever method/language/development environment you choose to use.

author: microbug
author_rank: Frequent Contributor
timestamp: June 18, 2013, 07:08:27 pm
content: OK, I will revise my question: what is the most popular development environment for PICs and is there a popular one I can use that will allow me to program in C?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 18, 2013, 07:17:11 pm
content: Quote from: microbug on June 18, 2013, 07:08:27 pmYes, Microchip's C compilers - there are free versions with poor code optimisation - this is mostly an issue on the 8-bit range, which need a cleverer compiler to deal with the limitations of the architecture. AFAIUI the 16 and 32 bit ones show less difference between the free and full versions.

author: lorth
author_rank: Contributor
timestamp: June 18, 2013, 07:18:56 pm
content: Quote from: microbug on June 18, 2013, 07:08:27 pmMicrochip´s MPLAB X is now the "standard" I guess, but I tried a year a go and use it for a bit, but being used to the older versions I had to go back to those... I guess now is probably better. Then get the compiler for the family (8,16/dsPIC, 32bit...) and thats it.You can program in assembly or C using the API provided... If you have more time and want to learn more, you can just get the datasheet and program the registers yourself (That is how I used to do it...)

author: ivan747
author_rank: Super Contributor
timestamp: June 18, 2013, 09:47:12 pm
content: Quote from: mikeselectricstuff on June 18, 2013, 07:17:11 pmI was coding someif (TMR0>=n)conditionals and when I looked into the assembly listing it almost seemed like if they were deliberately adding unnecessary goto's and instructions in the code. It was for software PWM to control servos. Manually coding the routine in asembly made it 3x faster.This was in a 12F part by the way, using the free XC8.

author: c4757p
author_rank: Super Contributor
timestamp: June 18, 2013, 09:52:37 pm
content: Not a surprise, XC8 is truly miserable. I really rarely bother with C for programming 8-bit PICs these days - I'll sometimes use it for simple, branch-heavy, somewhat boring stuff like the UART interface, but otherwise I just don't bother with the crappy compiler.

author: ve7xen
author_rank: Super Contributor
timestamp: June 18, 2013, 09:55:03 pm
content: I just don't bother with the crappy compiler - by using a different arch.Isn't PIC32 a MIPS core? Then you can just use gcc and not worry about for-profit toolchains?Sometimes it seems to me that these MCU vendors think their product is the tools, not the MCUs themselves.

author: c4757p
author_rank: Super Contributor
timestamp: June 18, 2013, 09:57:30 pm
content: I like PICs, though, when I don't have to screw around with their compiler. And yes, PIC32 is MIPS (another one ridiculously easy to program in assembly, by the way). Fortunately, AVR (which I use about as often) can be used with GCC.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 18, 2013, 10:06:50 pm
content: The full version of the 8-bit compiler is pretty good - I've used it for parts as small as 10F200 with nontrivial functionality.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 18, 2013, 10:08:57 pm
content: Quote from: ve7xen on June 18, 2013, 09:55:03 pmBoth PIC24 and 32 are based on GCC - ISTR reading you can work around most or all of the non-optimisations of the free versions of these with some additional command line options.

author: andersm
author_rank: Super Contributor
timestamp: June 18, 2013, 10:58:47 pm
content: Quote from: mikeselectricstuff on June 18, 2013, 10:08:57 pmYes, and you can also download the source code and recompile for a full version (or, if you don't mind straying into a bit of gray area, look exactly at how the compiler interacts with the license server).

author: nctnico
author_rank: Super Contributor
timestamp: June 18, 2013, 11:08:57 pm
content: Quote from: microbug on June 18, 2013, 06:57:56 pmFor hobby like projects perhaps (which is why there are so many websites with 8 bit PIC projects) but you won't find many PICs in real products. If you want to program a PIC in C you need to buy the Hitech C compiler which isn't cheap so you need to sell lots of hardware to recoup the price difference. Hence so many PIC projects get programmed in assembly... OTOH GCC based tools for ARM microcontrollers in general or TI's MSP430 are completely free with full optimisation.

author: westfw
author_rank: Super Contributor
timestamp: June 19, 2013, 02:45:49 am
content: There are "many" C compilers, plus some Basic Compilers, plus "JAL", for 8-bit PICs (PIC10, PIC12, PIC16, PIC18.) Most are "not free" but have free versions with various limitations. Microchip's own 8-bit C compiler is particularly annoying in its "no optimizations in the free version" strategy; it produces truly AWFUL code. I've used CC5X, and found it quite acceptable (for the processors it supports.)The 16bit PICs (PIC24, PIC30, PIC33) and the 32bit PICs (PIC32) have fewer options, but the Microchip C compilers are based on gcc, and so aren't quite as bad in their free versions (plus there is the "build-your-own" option.) PIC32 is MIPS-based, and so theoretically is widely supported.

author: Skimask
author_rank: Super Contributor
timestamp: June 19, 2013, 03:00:13 am
content: QuoteReally?I find quite the opposite to be the case, or rather not the opposite, but I see just as many PICs of various flavors as I see Atmel, various 8051 type incarnations, Motorola 8 bit types, and so on.To generalize and say "won't find PICs in real products" is just plain incorrect.

author: Rufus
author_rank: Super Contributor
timestamp: June 19, 2013, 03:24:14 am
content: Quote from: nctnico on June 18, 2013, 11:08:57 pmLol Microchip shipped its 12 billionth PIC processor in May this year, 10 months after shipping its 11 billionth.100 million a month - must be a lot of busy 'makers' out there.

author: glatocha
author_rank: Regular Contributor
timestamp: June 19, 2013, 04:02:13 am
content: Also, As I am register to the Microchip newsletter I got lately two emails from the CEO that they cannot handle production as they have so many orders.

author: Bored@Work
author_rank: Super Contributor
timestamp: June 19, 2013, 05:01:45 am
content: I still see more 8051 variants (including some from Atmel), but then followed by PIC, followed by AVRs. And the AVRs hardly sticking out from the crowd.For 32 bit it is ARM, then ARM, followed by ARMAnd then some more.

author: millerb
author_rank: Regular Contributor
timestamp: June 19, 2013, 05:37:02 am
content: Regarding PIC compilers, I like mikroC from MikroElektronika.

author: caroper
author_rank: Regular Contributor
timestamp: June 19, 2013, 08:29:57 am
content: Quote from: microbug on June 18, 2013, 06:57:56 pmIf you already have experience with the Arduino then I recommend that you start with ChipKIThttp://chipkit.net/. It uses the PIC32MX devices, a MIPS Core with all the normal PIC peripherals.The IDE is the same one you are already used too, MPIDE, but supports both ChipKIT (PIC) and Arduino (AVR) platforms. It uses the GCC compiler and is even compatible with (most of) the Arduino Libraries, saving you a lot of headaches in your initial experiments.Microchip have released a PIC32MX in a Dip Package suitable for Hobbyists, and it includes a Bootloaderhttp://www.microchipdirect.com/ProductSearch.aspx?Keywords=TCHIP-USB-MX250F128Bso no expensive Programmer is required.Take a look at my thread on this forum about using this Chip on a breadboard, or hop on over to my new blog athttp://caroper.blogspot.com/.I have just started a tutorial series to introduce hobbyists and students to the PIC32MX.CheersChris

author: nctnico
author_rank: Super Contributor
timestamp: June 19, 2013, 11:00:07 am
content: Quote from: Rufus on June 19, 2013, 03:24:14 amThat still doesn't make getting into the 8 bit PICs a wise choice. None of the professional embedded engineers I know would choose for a PIC. Most people who put an 8 bit PIC into a design don't know other processors so for them the PIC is a hammer which makes everything look like a nail. Just ask why people use a PIC. Most will say 'because I know it'. Not because its good or the best fit. Just look at the number of people complaining about silicon bugs in Microchip controllers.I recently did some software development for a customer for a new (high volume very cost sensitive) design. The customer intended to use a PIC. I pushed an MSP430. It appeared the MSP430 costs about the same, uses about 3 times less power so a smaller battery would suffice AND took less time to write software for.What I'm saying is that if someone wants to get into using microcontrollers he/she should not use some archaic architecture from the 70's which also needs spending serious cash to get decent tools.

author: amyk
author_rank: Super Contributor
timestamp: June 19, 2013, 11:53:07 am
content: Quote from: Bored@Work on June 19, 2013, 05:01:45 amSame here. An AVR in a commercial consumer product is very rare. On the 32-bit side MIPS seems to be a bit more popular for the Chinese, in tablets and routers.I think it's been said before on this forum that the advantage of PICs is not ease of use or cost of dev tools, it's availability; which is more important when you have products that need long production runs. The same reason 8051 stays around - it's a pretty constrained architecture but it's been around for so long and so many vendors sell them. (Similar situation with the 6502, and Z80, although not nearly as much.)

author: nctnico
author_rank: Super Contributor
timestamp: June 19, 2013, 12:05:38 pm
content: Due to Broadcom the MIPS architecture has a strong foothold in routers and setop boxes but for general purpose its no match for ARM. I once had to work on a MIPS based Linux device but if you are working for a small company then (community) support is hard to come by. And MIPS32 has some 'quirks': it executes the instruction after a jump before jumping. That can make programming them in assembly tricky because it is easy to forget (as I found out myself).

author: BravoV
author_rank: Super Contributor
timestamp: June 19, 2013, 12:20:46 pm
content: Quote from: nctnico on June 19, 2013, 12:05:38 pmHuh ?Mind elaborate further with simple explanation or example ? Really curious.

author: amyk
author_rank: Super Contributor
timestamp: June 19, 2013, 12:36:12 pm
content: http://en.wikipedia.org/wiki/Delay_slotBasically an artifact of the RISC fad.

author: andersm
author_rank: Super Contributor
timestamp: June 19, 2013, 01:07:18 pm
content: By convention, MIPS uses a "smart" assembler, so you rarely have to worry about delay slots unless writing kernel-level code. Occasionally, the delay slots allow for some elegant solutions, such as performing a register indirect jump, and loading a parameter into the same register before the target is reached.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 19, 2013, 03:37:10 pm
content: QuoteUnless you're into high volumes where the last penny matters, "because I know it" is a very valid reason for choosing a device. Reduces developmet time, and familiarity reduces risk of unknown time to learn about quirks of devices or devtools.QuoteAll devices have silicon bugs. Microchip is good at documenting them If one affects you, use another part and stop moaning about it. If you only found it later, then that's your stupid fault for not reading the errataQuoteArchitecture is pretty much irrelevant. Does it do the job, and can you get it. 8051 is still going strong and that's at least as oddball.Something which AFAIK is fairly unique to Microchip is you can get parts preprogrammed and custom marked for a few pennies (way cheaper than any 3rd-party programming house I've seen) - this alone can sometimes make them a cheaper option in terms of all-up cost.

author: Rufus
author_rank: Super Contributor
timestamp: June 19, 2013, 05:09:51 pm
content: Quote from: mikeselectricstuff on June 19, 2013, 03:37:10 pmAnd I can go to Microchip and buy parts I designed in 20+ years ago while I have had to re-do more recent designs for parts made obsolete by ST, Atmel and NXP. Can someone tell me which ARM cored processors I will still be able to buy in 20 years?

author: nctnico
author_rank: Super Contributor
timestamp: June 19, 2013, 07:31:33 pm
content: Time to get new reading glasses O0What I'm saying is that its better to spend time on learning how to use a modern controller likeBUT NOT LIMITED TOMSP430 or ARM for which a wide variety of good tools (including free ones) are available. Talking people into using PICs and 8051 is like saying a horse & carriage is the best means of transport because the horse doesn't need fuel. For a few dollars you can buy to most exciting development boards with lots of processing power and memory so lack of resources isn't getting in the way of creativity... and most have .1" headers so embedding such a board into a project is easy.

author: c4757p
author_rank: Super Contributor
timestamp: June 19, 2013, 07:34:24 pm
content: Saying a horse and carriage is the best means of transport is like saying an abacus is the best processor. No, talking people into using PICs and 8051 is like teaching them how to drive a car from the 1960s - yes, it's a bit different from a current car, but name one thing that won't still be applicable.

author: Bored@Work
author_rank: Super Contributor
timestamp: June 19, 2013, 08:06:45 pm
content: Quote from: c4757p on June 19, 2013, 07:34:24 pmDouble-clutchHe, you asked for it.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 19, 2013, 10:11:21 pm
content: Quote from: nctnico on June 19, 2013, 07:31:33 pmThere are some situations where a horse & carriage may be the most appropriate solution.Every application is different. There are many applications that can use a wide variety of parts, so choose what you know. There are some situations where a PIC is the standout best ( or only) solution. Others where an ARM, or 8051 or whatever is. The age or otherwise of the architecture is usually a non-issue. It's about cost, peripherals and availability.

author: c4757p
author_rank: Super Contributor
timestamp: June 19, 2013, 10:31:26 pm
content: Quote from: Bored@Work on June 19, 2013, 08:06:45 pmYou got me. Still, wouldn't you at least agree that the knowledge of the car's operation that you gain from learning that would be useful in other areas - at least, much more so than any knowledge you'd learn from a horse and carriage?

author: itdontgo
author_rank: Regular Contributor
timestamp: June 20, 2013, 04:42:18 am
content: Quote from: lorth on June 18, 2013, 07:18:56 pmHaha that's exactly what I did. I think MPLAB X looks like a child's toy. Nothing fits on the screen properly. I hated v6 though when it switched from v5 and I grudgingly got used to it so there is hope yet.On the original subject you need to do a bit of assembly even within a C program just because it's sometimes easier to write a snippet in assembly than writing some structured C code for the same thing.

author: Bored@Work
author_rank: Super Contributor
timestamp: June 20, 2013, 04:48:57 am
content: Quote from: c4757p on June 19, 2013, 10:31:26 pmIt has to be in some balance. At work I am constantly fighting (read: kicking young guys' buts) that we don't follow the latest and greatest hype technology. We don't design in parts not shipping in volume right now, we don't use the latest idiotic hype programming language.On the other hand I am constantly fighting (read: kicking old guys' buts) that we need to get rid of some old crust and moldy parts.

author: David_AVD
author_rank: Super Contributor
timestamp: June 20, 2013, 05:10:57 am
content: Quote from: mikeselectricstuff on June 18, 2013, 10:06:50 pmWe use 8-bit PICs a lot and I'm moving to C code as new projects come up. So the paid version of XC8 worth it eh? I don't mind paying for a compiler as it's just another tool and part of business.

author: GK
author_rank: Super Contributor
timestamp: June 20, 2013, 05:29:32 am
content: I currently use the PCW C complier by CCS.http://www.ccsinfo.com/content.php?page=compilersIt isn't bloatware, does the job and has straightforward and comprehensive documentation. I've been happy with it. However the software I have is "IDE version 3.26", which doesn't run on Windows 64bit, so I'm going to be forced to upgrade quite soon.Anyone have experience with the current version of PCWHD?

author: westfw
author_rank: Super Contributor
timestamp: June 20, 2013, 06:11:15 am
content: QuoteThis is complete nonsense; but something I see all too often. Get it straight: there are *NO* IC manufacturers that make a successful business out of selling "mostly to hobbyists." It is not a viable business model. Just because you don't SEE xxx chips when you take things apart doesn't mean that they're not there...Back when I worked at <major OEM>, I requested a sample PIC via the company email address, and very quickly received a call from the Microchip Rep, wanting to know if I needed anything in particular. I explained that the samples were for a hobby project, but I was curious as to whether <company> actually USED any Microchip products. (Our "visible" cpus were the meanest, baddest, MIPS or PPC devices we could talk up-and-coming semiconductor vendors into promising to us.) "Yes!" she said. "Lots of them!", and she gave me a list to look at. Several pages worth; fan controllers. Hot swap managers. Power supply sequencers. Front panel helpers. They were there, and I had never noticed them. (Sure, I was a "high level" programmer, but I was internal, and I would have thought I would have noticed SOMETHING. Sigh.)Professionally, a lot of 8-bit PIC software is still written in assembly language. I mean, if a bunch of your showpiece chips have 512 words of flash (or less) and 64 or fewer bytes of RAM, you're a bit limited in how much HLL overhead you can put up with. The whole <PIC18 range only runs C "grudgingly" (no SW stack, small and noncontiguous RAM, limited working registers, a bunch of instructions that don't fit well in the "C model" of what a processor should look like.) There are some other development languages, but C is still pretty much king for small microcontrollers, and JAL or some random version of BASIC doesn't give you any of the portability you'd like to have from a HLL. PIC18 improves a bit, and PIC24 and PIC32 start to look a lot more like other CPUs.So, if you want to learn the ways of the ancient PICs that basically started the whole "microcontroller hobby", go for assembly on a PIC16xxx (Note that many published designs use very old chips like the PIC16F84 that are now considered obsolete and overpriced compared to modern chips.)If you want to just DO stuff with PICs, you might want to look at PIC18s and JAL.If you want to expand your horizons to a Microchip processor, but don't particularly care what, you should probably consider the ChipKit arduino-like boards (PIC32, with C/C++ "MPIDE")If you want to expand, and Microchip just came up by default, THEN you should consider nctnico's advice to consider other chips as well. Frankly, at this point, ignoring ARM seems like a bad idea.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 20, 2013, 07:12:12 am
content: Quote from: David_AVD on June 20, 2013, 05:10:57 amDefinitely. The free version is only useable for things that are not very size or speed critical. The full version can be pretty close to what you'd get with assembler,.

author: David_AVD
author_rank: Super Contributor
timestamp: June 20, 2013, 09:16:53 am
content: Quote from: mikeselectricstuff on June 20, 2013, 07:12:12 amInterestingly, Element14 have the professional version for AUD $985.05 + GST (we claim the GST back anyway) which is cheaper than buying it from Microchip in USD at present.

author: Rufus
author_rank: Super Contributor
timestamp: June 20, 2013, 12:53:13 pm
content: Quote from: David_AVD on June 20, 2013, 05:10:57 amIt should be noted the Microchip XC compilers have a pretty awful licensing and online activation scheme.I haven't checked recently but it was impossible to find out what you were actually buying. A node locked license is allowed to be activated on more than one computer (MAC address tethered) but how many? Allowed activations have to cover moves to a different computer and computer replacement. After activations are used up you are contacting Microchip begging to be allowed to install the compiler you own on your new laptop?Likewise the value of and required number of network licenses depends on how long a license is checked out for on use. I couldn't find that stated anywhere.Then there is HPA (maintenance) - very unclear on what that actually buys you.

author: nctnico
author_rank: Super Contributor
timestamp: June 20, 2013, 02:06:43 pm
content: This sort of licensing crap is the reason why I only buy software for which a cracked version is available. If your PC dies in the middle of a project you don't want to wait for the next business day (or longer) to get a new license.

author: Vasi
author_rank: Regular Contributor
timestamp: June 20, 2013, 02:18:07 pm
content: Ok, it seems to me that is mainly about PIC 8bit microcontrollers...Microchip is still maintaining the MPLAB C18 compiler which provide much better optimisation in free mode than the crappy XC8 compiler. I advise you to download the windows version (and maybe linux version as well) and burn them on a CD/DVD - you will use them for a long time from now on if your language of choice is C.www.microchip.com/mplabc18-linux-installerBUT, if you can learn another language, then I recommend you theJALv2compiler accompanied byjallib libraries(open-source, supports all PIC10F, PIC12F, PIC16F, PIC18F microcontrollers for free, USB libraries and USB bootloades, and the compilation result is amazing - is at a professional level and throws away the competition). There are also a lot of documentation. Wait for JALv2 2.4q to get out - it will be amazing.http://justanotherlanguage.org/If you can not digest the ADA(or VHDL) like language of JALv2, then maybe you will like to learn Turbo Pascal or Delphi like language, and start using Pic Micro Pascal of Pilippe Paternotte - it supports from PIC12F to PIC18F and the 2.0 version will come with dead code removal, a much improved IDE and USB CDC libraries among other things. Free but not open-source.http://www.pmpcomp.fr/So, you can forget about Microchip tools - it willnotprovide such a level of optimization unless you pay for it.Still, I will recommend you to stay with AVRs if you can...______________________Edit: I will dare to say that the standard in programing PICs must be JALv2!

author: Rufus
author_rank: Super Contributor
timestamp: June 20, 2013, 02:55:39 pm
content: Quote from: nctnico on June 20, 2013, 02:06:43 pmThe XC compilers are easily cracked so the licensing and activation scheme only affects paying customers which makes it even more annoying.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 20, 2013, 03:04:23 pm
content: Quote from: Rufus on June 20, 2013, 12:53:13 pmFree updates to the latest version. Not looked into whether it also includes any tech support.

author: nctnico
author_rank: Super Contributor
timestamp: June 20, 2013, 03:28:24 pm
content: Quote from: Vasi on June 20, 2013, 02:18:07 pmYou do know that Pascal is derived from ADA

author: Rufus
author_rank: Super Contributor
timestamp: June 20, 2013, 03:46:41 pm
content: Quote from: mikeselectricstuff on June 20, 2013, 03:04:23 pmBut you get 'minor' and bug fix updates free anyway and there is no definition of minor. HPA stands for High Priority Access and was inherited from Hi-Tech and used to mean high priority access to technical support. I am not aware of any special path to Microchip tech support for those with current HPA. HPA would seem to be worthless.The whole compiler side of Microchips dev tools is a confused mess, seems to be run by an idiot who was probably acquired with Hi-Tech. They fund MPLAB and all the application library development through part sales while seemingly trying to treat compiler development as a profit centre. 2/3rds of them are only ggc ports anyway. I would be very surprised if don't loose more in part sales than they gain from compiler sales.

author: andersm
author_rank: Super Contributor
timestamp: June 20, 2013, 04:38:47 pm
content: Quote from: nctnico on June 20, 2013, 03:28:24 pmPascal predates Ada by about 10 years. The main influence for Pascal was ALGOL, at least according to Wikipedia.

author: Vasi
author_rank: Regular Contributor
timestamp: June 20, 2013, 04:40:17 pm
content: Quote from: nctnico on June 20, 2013, 03:28:24 pmYou are sure?I thought that Ada is a better kind of everything...__________________Edit: From wikipediaQuote

author: millerb
author_rank: Regular Contributor
timestamp: June 20, 2013, 08:13:21 pm
content: Quote from: GK on June 20, 2013, 05:29:32 amI thought I had seen them all after 10 years of messing with PICs. Guess not. That suite looks really nice, I'll have to try it out.Slightly unrelated, but does anybody out there have a favorite FORTH for the PIC?

author: envisionelec
author_rank: Frequent Contributor
timestamp: June 21, 2013, 03:08:14 am
content: Quote from: westfw on June 20, 2013, 06:11:15 amYou absolutely will. I happen to know an engineer that wrote the code for each of the 390+ PIC18F4550 in the printing system "major OEM" that I work for developed. We're talking over USD2M systems. Each system module contains 23 PICs and there are 16 modules. And that was truly the low cost method. So far they've been bulletproof.

author: GK
author_rank: Super Contributor
timestamp: June 21, 2013, 09:35:30 am
content: Quote from: millerb on June 20, 2013, 08:13:21 pmThey've been around for a while too! I started with a DOS version of their PCB compiler in ~2000, upgraded to the windows based PCW compiler 10 years ago now.

author: envisionelec
author_rank: Frequent Contributor
timestamp: June 21, 2013, 12:33:27 pm
content: Quote from: GK on June 21, 2013, 09:35:30 amHi GK! I know (of) you from the DIY Audio board.I was introduced to CCS about five years ago. The programmer I hire* uses it exclusively.*What can I say? I'm a traditional hardware guy. Learning C as we speak.