Which language do you use to code for PIC/other MCUs, and why? - Page 1
Forum section: electronics / general

author: glossywhite
author_rank: Regular Contributor
timestamp: January 14, 2011, 10:22:44 pm
content: Okay, I'm curious as to which language you guys find preferable for coding for PIC & other MCUs. Personally, and as a newcomer, I find assemlyincrediblysimple and SO logical (counter to what many people say, oddly). I am autistic, so maybe it is my abrupt, logical & lateral thinking mind that draws me to it. I have tried to learn many languages (I once spent almost a year trying to learn Objective C for coding iPhone apps, before abandoning it - elitist Mac coders didn't help much, with their heads up their arses!).Simple poll; I have given each user 4 votes, as you may like to use more than one, and hence poll them all. A place to discuss the why and how... thanks

author: NiHaoMike
author_rank: Super Contributor
timestamp: January 14, 2011, 10:34:39 pm
content: I haven't done any real work on the PIC, but I have done C++ on the mbed (ARM), C and shell script on Broadcom wireless routers (MIPS), and a little C/C++ on the Renesas RX62N (RX).

author: tyblu
author_rank: Frequent Contributor
timestamp: January 14, 2011, 10:37:36 pm
content: 100% Haskell.

author: baljemmett
author_rank: Unknown
timestamp: January 14, 2011, 10:39:30 pm
content: I've said assembly, which is what I've used for all my PIC stuff to date, and C because I really meant C++ on the mbed. I've tried C on the PIC but never got as far as a successful compilation, and frankly I prefer the nuts-and-bolts of assembly; whether that's because I write C/C++ in the day job and assembly is a nice change, or because it's a constrained system and I like the challenge, I'm not entirely sure!

author: glossywhite
author_rank: Regular Contributor
timestamp: January 14, 2011, 10:41:22 pm
content: Quote from: baljemmett on January 14, 2011, 10:39:30 pmNuts and bolts is what assembly is- love that you have TOTAL control, not abstracted away by some higher level code. Wonderful.

author: johnmx
author_rank: Frequent Contributor
timestamp: January 14, 2011, 11:35:17 pm
content: I started playing with PICs more than 10 years ago and on that time I made a promise to myself to not touch in C for the first years. I already knew that the best way to learn all about any microcontroller is through assembly and once starting coding in C I would never go back. So during almost 3 years I never wrote a single line in C for the PIC.Now sometimes I use assembly just to do some small and time critical functions (not very complex). I also use it to develop some small projects with any micro of the PIC10 and PIC12 family.Oh, I tried once BASIC and JAL (Just Another Language) but didn’t like it.

author: Hypernova
author_rank: Unknown
timestamp: January 15, 2011, 12:44:46 am
content: C all the way, I have yet to encounter a timing critical app down to the clock level which is where you need asm. Although I started on Basic in high school on my avr, where the teacher made sure we knew the holy commandment: "Thal shal not use GOTO!"

author: Psi
author_rank: Super Contributor
timestamp: January 15, 2011, 01:16:55 am
content: Coding in assembly language can definitely be *better* than C if your just looking at the argument from the point of view of the code itself.However rarely do you ever encounter a situation where assembly is the better choice overall when considering the decision and it's impact as a whole.(Some exceptions of course are when you absolutely need control over the speed of your code or when the mcu you're using cant really handle C due to its capabilities)Since you always want your code to be easily understandable by others as well as yourself and also easy to reuse in other projects C just makes more sense. You can write a little in-line assembly in C when needed so C has lots of the advantages assembly has with little of the disadvantages.Of course this is just my opinion on the subject.

author: EEwannabe
author_rank: Contributor
timestamp: January 15, 2011, 04:43:56 am
content: I started out with BASIC a long time ago, now I use assembly mostly because I don't trust my C/C++ writing skills yet.- Patrick

author: williefleete
author_rank: Regular Contributor
timestamp: January 15, 2011, 06:28:32 am
content: i got hooked on picaxe about 7 years ago so i use basic for that. because of the space limitations of picaxe i have learnt how to write reasonably fast and efficient code and i've done some quite amazing stuff with the limited capabilities of them including a clock, and an 8 digit LED display using 08M's

author: Zero999
author_rank: Super Contributor
timestamp: January 15, 2011, 09:17:26 am
content: Quote from: glossywhite on January 14, 2011, 10:22:44 pmI've not tried C on PICs yet but I agree with you sentiments regarding C vs assembler on the PC. I've not done much MCU work and have chosen assembler each time. I did find BASIC easier than both asm and C on the PC so maybe you could give it a go, if you want an easy option.Another advantage of high level languages is portability and C is the most popular one. Unfortunately lots of BASIC products are very proprietary so are probably not very portable. I've heard about GC BASIC being open source but I don't know how good it is.

author: Jimmy
author_rank: Regular Contributor
timestamp: January 15, 2011, 11:42:21 am
content: Mnemonic, Basic, Assembly andProcessing

author: jahonen
author_rank: Super Contributor
timestamp: January 15, 2011, 01:20:58 pm
content: I have used ASM with PICs. Things are simple with ASM when you are doing simple things, but when you start needing things like large value (>8 bit or floating point) arithmetic, string parsing, multitasking operating system or any communications protocol, things go very difficult to maintain very quickly and whole thing becomes a pain and you'll find yourself re-inventing the wheel instead of developing your own system.I have mostly moved into MSP430 for casual MCU needs, and I use mainly C with it (mspgcc), although it is very beneficial to know the assembly so you can check the compiler output in case of doubt. My current coding philosophy is that do not optimize too early, instead try to obtain smart program algorithm overall. That gets most optimization.If there are some time critical sections in the code, then they can be optimized into ASM if required, but writing whole complex program in ASM is sheer madness. By complex I mean substantially more complex than simple "led flasher". I think that it does not matter if you use 70 or 90% of code space or 70 or 90% of CPU cycles if it does what you want. The difference between assembly and C is not even that big, unless compiler is flawed somehow. Only in specialized occasions (like in DSP filter kernels), human knowledge of CPU assembly features can shrink speed and code size considerably.Regards,Janne

author: DaveW
author_rank: Frequent Contributor
timestamp: January 15, 2011, 02:05:55 pm
content: C all the way, not only does it let you do much more complex stuff than assembly, but more importantly you can port a lot of code straight across processors. You can take an algorithm straight off wikipedia and drop it into your code. Heck, if you wanted to you could rewrite the Arduino functions for a PIC and have lots of code ready to drop in.At work we write a interface layer containing functions that have all the processor specific code, including inline assembly, then write everything in C on top of that. You can reuse the same code on ARM, Freescale, PowerPC etc, particularly useful if you've done code review

author: Simon
author_rank: Unknown
timestamp: January 15, 2011, 04:21:07 pm
content: I use basic as it's easy (reason is in the name) but would like to move to C sometime

author: Boloop
author_rank: Contributor
timestamp: January 15, 2011, 05:29:16 pm
content: I remember briefly seeing basic for micro controllers when I was at some Uni intro course. I didn't like it. At the time I had only learnt a little bit of C and PHP. So I had that knowledge to share.The only real major MCU project I have done yet was a clock, but it synced up to a Remote Radio Source (MSF60 in this case). This project seemed a little bit too complicated for ASM. so it was in straight C. But the fun thing was. I didn't entirely "code" the thing in C. Because I wasn't too sure how to decode the MSF60 time even with their documentation, because what I thought the pulses would look like wasn't exactly 100% what I was getting on the scope. So I just wrote code for the chip to measure 120 pulses (2 minutes) and save them in ram. With the In circuit debugger I dumped the contents of the 120 pulses onto a file on the PC.Anyway, this file was later read up by a python script so I can quickly and easily see it debug how to write and algo to decode the time/date. Because debugging on it would a timely and painful process. Having to wait for 2 minutes to get at least one whole complete 60 second cycle, which might not always be clean depending on the weather etc... Once I got it working, ported it to C. Ran and debugged that on my desktop, then finally put it on my PIC. Great Success!There are two things I like about C, it's portability and that it's strict defined types. With writing python I don't feel too safe. But I know what it should do! But I never code in a single language. I like python because it's quick, easy to know where it breaks. It's experimental. It just tells me that I am on the right track for the right algo. And in the above case I would of found out silly little errors much quickly. Like knowing which start of the week is. And paying close attention to when the day of the week starts etc...Although I have coded in ObjC for the iPhone, so it doesn't really count here. But I dislike this language with a passion. They tried to re-invent the wheel and just cause more trouble that what it's worth to use. And square brackets, really?Although I haven't properly coded in ASM before. I think it's important to know how compilers work so that people can understand how to code in C better. And not get bogged down in misconceptions about why their code isn't working.C# is also nice, but I only think windows mobile can run that.But I voted C, if the software is complex enough and the compiler supports it. I will do it in C++. I don't touch ASM because I haven't come to anything where it's needed for various reasons mentioned here.

author: glossywhite
author_rank: Regular Contributor
timestamp: January 15, 2011, 08:10:52 pm
content: Quote from: Boloop on January 15, 2011, 05:29:16 pmObjective C is a headache, but nowherenearas much of a headache as all the stuck-up Mac developers! Talk about snotty, arrogant and unhelpful. Keep well away

author: Hypernova
author_rank: Unknown
timestamp: January 15, 2011, 09:20:25 pm
content: Quote from: Boloop on January 15, 2011, 05:29:16 pm

author: comox
author_rank: Regular Contributor
timestamp: January 15, 2011, 09:56:35 pm
content: I develop for Microchip PIC 18s using C. I use the Hi Tech Software (now Microchip) PIC18 Pro C compiler, which features what is called omniscient code generation. The "feature" results in better memory allocation and more efficient code, which is specifically beneficial when dealing with multiple source files.I started my carrier some 20+ years ago in IT as a C developer, so when I became interested in embedded systems development a few years back, C was a logical starting point. The programs I develop are simply too big to hand-code in assembly (for me, anyways!) and I am much more productive in C. Also, I am not autistic, and as such care little for assemblyI first used the HT Soft "Hi-Tide" Eclipse-based IDE, which I liked from a development perspective, but I moved to the MPLAB IDE when I started doing debugging with the Real ICE module as HI Tide lacked any integration with the Microchip tools. Microchip has recently released a beta of their next-generation IDE (called MPLAB-X) which promises the best of both worlds: an Eclipse-like IDE with all the integrated debugging and programming functionality with the Microchip tools), however I soon gave up as I was having trouble getting the USB drivers working under 64-bit Windows 7.... I'm going to hold off for the production release...

author: Boloop
author_rank: Contributor
timestamp: January 15, 2011, 11:15:36 pm
content: Quote from: Hypernova on January 15, 2011, 09:20:25 pmThanks, I edited it now. Shame It doesn't cascade to the quotes.

author: apex
author_rank: Regular Contributor
timestamp: January 16, 2011, 07:11:37 pm
content: C.All the time.And some times Java for AVRs for things that come straight out of my mind.apex