Converting PIC program written in C to Arduino C ?

I know this question has been asked about converting Microchip PIC program code written in C to Arduino C.

Where does one start?

At the moment I want to convert something written for the PIC 12F series(8 pin micros), but is their a website that has some guidelines? The conversion of timers seems a little daunting, yet the configuration lines are brain twisting. The code I have is not rocket science, but all it is doing is electronic ignition with a hall-effect pick-up, and electronic advance. I would also imaging somebody has made an electronic ignition using the Arduino.

The Arduino platform is the best for development as one does not need to fight with the complexity of Microchip's MPLAB and the programmers. The Arduino just has the USB interface to speed-up development and deployment...



Perhaps post the code? Most code is either logic (which won’t need conversion) or some sort of interface to the hardware (which will). With luck, the interface part will be fairly small and can be easily converted. If it is 99% hardware access, then it is basically a rewrite.

Also it might be quicker and easier to simply Google (say) “electronic ignition +arduino” and see if something that does what you want already exists.

For something like ignition timing, it's probably better to stick to code as minimal as you can get. I would look into AVR Studio and program the AVR chip directly. Not that you couldn't do it with Arduino, but you'll probably bump into some of the convenience libraries, and their appropriations of hardware.

To answer your question directly, though... since it's C, you're just converting the hardware-specific stuff. Preferably, all the low-level code is tucked away into functions that perform some particular task. Then it just becomes a matter of re-writing those functions to perform equivalent actions on the AVR. There will be direct substitutions for a lot of it, but there's not avoiding studying the data sheets for the source device and the target AVR to fully understand the behavior of each.

E.g., for timers, you'll need to know if they're 8- or 16-bit, how to enable overflow interrupts (unless you're polling a register), how to initialize them, how to set their clock dividers, and so on. For I/O, it's probably a bit easier. Toggling pins is pretty simple on either platform (at least from what I've seen, but I'm not a PIC guy.)

If you were hoping to find some "code converter", you're out of luck I'm afraid. There are stark differences even among the AVRs sometimes. Some of the more universal libraries are littered with #ifdefs to pick appropriate code paths for abstracting some of those things.

Thank you both for the replies!!

I'd first figure, someone would have a web site with some guidance on a conversion of PIC code to Arduino, and it might exist!

I did follow Nick's suggestion, and used the power of the search engine, and found a handful of Arduino ignition projects, so enough code to tinker.

Again, thank you for your replies!