How to: Program PIC in Linux

It could be said that Microchip PIC microcontrollers are not getting enough messages here. One of the drawbacks for some of us is that Linux for PIC is not well known. The data is there, but no one has described the procedure for moving from writing C code to Programming a Written chip for Linux users who know microcontrollers, fundamental circuits, C programming language, and can read a datasheet, this consultant deserves to help you temporarily schedule a PIC with Linux.

The compiler:

The Small Device C compiler, sdcc, will be used to create the Arrayhex record required to program a PIC. PIC is still growing, and still in beta, so keep in mind that the outdoor pieces of code and chips in this article may require debugging. However, like all other open source projects, more contributing users will help in the project. Better yet, it is loose, with ports for Windows and MacOS X, it is a compiler that handles many architectures and gadgets without the restricted program of loose versions. from paid compilers restricted to Windows. Sdcc will be obtained through package managers of various distributions, adding Ubuntu and Fedora.

For sdcc on Ubuntu:

For sdcc on Fedora:

Fleas:

Three other PIC chips were used to write this tutorial: the 40-pin PIC16F887, the 14-pin PIC16F688, and the 8-pin PIC12F675. You can track one of those chips like other chips.

The programmer:

We will use two programmers, the Olimex PIC-MCP-USB compatible PICStart programmer and the Microchip PICkit 2. Both programmers have been working with the 3 chips used here.

PICStart programmers use the picp program. Most PICStart-compatible programmers will paint with picp. Easily on Ubuntu with:

For Fedora and other distributions, you may want to download and install it from the source, so in an empty directory of your choice:

It is located on the PIC Developer Development Tools page of [Jeff Post] along with other programming options.

If you use the PIC16F887 and picp, you will want to replace your record / etc / picp / picdevrc by adding the following lines:

The above lines are changed settings for PIC16F886 discovered in a message from [Al Williams]. For chips already in / etc / picp / picdevrc, more settings will need to be added to / etc / picp / picdevrc.

PICkit 2 programmers will work with some other program called pk2cmd hosted via Microchip here. You’ll want to install pk2cmd from the source, in a directory of your choice:

Note that Microchip promotes the PICkit 3 as a replacement for the PICkit 2. This is not a replacement for the PICkit 2 as there are no Linux drivers for the PICkit 3, so don’t buy the PICkit 3 thinking it will work on Linux.

There is also a program that claims to paint with a variety of DIY PIC programmers: PICPgm. We have not tested this program or any of the DIY programmers yet. We know that there are other reasonable and expensive PIC programmers who have not been. You may wish to write a summary of PIC programmers.

The code:

The code for this how-to consultant is a type of LED from the Hello World program. The code for this is hosted on Github, you can stick to the blink. c registry for PIC16F887, PIC16F688, or PIC12F675. The FunctionalArrayhex records are also included. Here is the PIC16F887 code for reference as we go through each major operation:

The first line is #include for the specific chip header register you will use. It tells the compiler which records to have and where they are in memory. On maximum systems, the header records will be in / usr / percent / sdcc / include.

Next, we set up the configuration word or the fuse words. They can only be written when the chip is programmed, however, we can configure them here so that we do not have to program them manually later. The PIC16F887 supports the configuration words explained in its header record as _CONFIG1 and _CONFIG2. The PIC16F688 and PIC12F675 do not have the configuration word addressed in their header (we said sdcc in beta, right?), so we only use the word deal with the configuration code: 0x2007. The configuration words are expressed in the style and application of the chip and are described in the bankruptcy “Special CPU Features” on each of the knowledge sheets of the respective chips. In the blink. c examples, the configuration word is only a 16-bit hexadecimal word, however, the word can be made more human-readable by combining the AND configuration options. See the bullet header records for option names.

Next, we configure some global variables, one for which it will be emitted on the LEDs and the other for a hold counter.

In void hand(), we set the login to 3 PORTC, TRISC states on all outputs. The PIC12F675 has a port, GPIO, and its 3-state register is TRISIO. After defining the 3-state login, we enter an infinite loop with while (1) . Inside this loop there is a hold loop so we can see the LEDs change. After the retention loop, the demo counter is incremented and then written to PORTC (or GPIO) to be demonstrated on the LEDs.

Code compilation:

Now that you’ve reviewed the code, it’s time to turn it into anything a PIC can use. Sdcc will take the blink. cy will create a lot of records. One of those logs will be blink. hex, which will be the PIC device. The programmer will write about the PIC. Here’s how to:

For the PIC16F887:

For the PIC16F688:

For the PIC12F675:

The -mpic14 option tells sdcc that it will compile for the 14-bit commands of the PIC16 and PIC12 families. The moment option is the chip for which the code will be compiled. The last on the line is the record that contains the C code to be compiled.

Chip programming:

To program a chip, it will take the programmer from your device and connect the chip you want to load with your program. Unless you use a socket scheduler such as pic-MCP-USB, you want to check the programmer and chip technical sheets for the correct connection Once it is securely attached, you will want to run the program to run the scheduler:

For a PICStart programmer on / dev / ttyUSB0 programming a PIC16F887:

For a PICkit 2 programmer programming a PIC16F887:

If you are programming a chip or if the PICStart programmer is on a port other than /dev/ttyUSB0, you will want to make the corresponding settings for the controls.

Note: The code provided for the PIC16F887 disables low voltage programming. Some of the programmers that have not yet been discussed directly only perform low voltage programming. If you have one of those programmers, you want to replace the code so that low voltage programming The bit in the configuration words allows low voltage programming. The low voltage programming pin on the microcontroller will also need to be removed during general operation.

Wire the circuit:

The circuit of this mapping with the code provided is undeniable to test Here are the diagrams of the 3 chips:

Start by connecting the Vdd pins to a positive voltage source between 4. 5 volts and 6 volts and the Vss pin to ground. The four-pin PIC16F887 and the 1-four-pin PIC16F688 will want a boost resistor on their main clear pin. On one or all ports of the road pins (or GPIO pins for PIC12F675), connect the LEDs with existing resistor to ground. Note that pin four of the PIC12F675 is just an input and will not light a soft LED. The existing of any of the 3 chips used is limited to 20mA so existing limiting resistors are optional for a reasonable maximum of jellybean LEDs. What you see when you turn on the circuit are flashing LEDs. The LEDs should light up according to a binary number.

Now that we’ve gotten you started with PIC programming on Linux, we look forward to seeing more projects with those chips and equipment that we discussed earlier. Although this article was written for Linux users, Windows and MacOS X users deserve to be able to use sdcc for their PIC programming needs.

Image Info: The Tux logo is via Larry Ewing, Simon Budig and Anja Gerwinski, Wikimedia Commons. The Microchip logo is a registered trademark of Microchip Technology Incorporated.

Very nice.

I like those tutorials.

I think ARM programming is next

MPLAB (beta) is cross-platform. PC / Mac / Linux

http://devupdates. microchip. com/mplab/

@Chipmunk

What is “ARM”? All other “ARM” vendors have many other parts, each seller has their own methods of circuit programming, Array. If you were writing such an instruction, you would have to use a logo and probably one of the logos. ARM families, unless you need to write a one-million-page hands-on guide.

Building a computer chain is quite simple if you have a part that doesn’t have a hardware FPU or anything extraordinary, you can easily search google commands to create binutils, gcc, gdb, newlib, etc. , startup code, etc. they’re alone, I hope they like to read the fact sheets.

@Reseller

Why PIC when you can get a decent loose rig for AVR? 😉 SDCC supports very few PIC AFAIK families.

“Why PIC then can you get a decent loose rig for AVR?;)»

Because you can get a decent loose gear for PIC;)

“Microchip PIC microcontrollers can be said not to receive enough messages here. “

Blame the Italians for it.

1

@squirrel With all the communication about ARM, there is rarely a singles article about OpenOCD, especially since it works with Bus Pirate.

Is it obsessive compulsive disorder?

Note that you can compile compilers for PIC24, PIC30, and PIC33 on a Linux machine. They are built from CCG, the only problem is that you do not get the popular Microchip library or DSP functions. Unfortunately, I have a RealICE/debug circuit emulator and I am forced to use Windows in Virtualbox, but it works well.

@cantido

all the ARM7s that I knew of (Analog Devices, ST and NXP) use the same programming approach and this approach is the serial port. So you want nothing more than a MAX232-type translator to start running with ARM7.

I started running with an ST Cortex-M3 and am my ARM7 programmer before migrating to JTAG, which is also available on all models.

ARM is a popular and there are not so many differences between the models. Compatibility goes even further with Cortex models, where more than the core will have to be popular with manufacturers.

As for compilers, it’s very, very easy to get started with Code Sourcery g lite, which can be achieved loose and manages UPFs

As for AVR, I agree 😉

Next month, Microchip will deliver the new Netbeans-based MPLAB X, which will work on Windows, MacOS, and Linux (including compiler and debugging).

The last few days I’ve also noticed progress on a buspirate to schedule a pic uC (I’ve already personally used a BP to program some other brick). BusPirate’s assignment is temporarily adjusting a very smart Swiss knife for electrical engineers!:)

What’s so great about PICs that you need to use in an ATtiny or AVR (or picaxe)?

. . . I think they became extinct in the 90s

I like to see an instructional on the ARM M0 cortex

It is attractive to note that MPLAB X (Microchip IDE) runs on OS X 10. 5, 10. 6, Linux, and Windows.

http://devupdates. microchip. com/mplab/Files/installer. html

I haven’t tried yet, but it’s hereArray. .

You forget:

– JALv2, a very smart compiler that uses the JAL language. There is also a task called Jallib with many great libraries for JALv2: http://www. casadeyork. com/jalv2/

– PIC-GCC, a gcc portage to the 8-bit microchips family: https://forja. rediris. es/projects/cls-pic-16f877/

– Pinguino project, founded in Arduino and sdcc: http://www. hackinglab. org/pinguino/

I think that’s enough to get you started with Linux, but there are even more alternatives.

Good luck.

VERY GOOD TUTORIAL! I am a huge fan of Microchip PIC, having a huge dislike for micro $ oft operating systems.

I have had limited luck with pickit2 and other online tutorials.

I was excited about the new mplabx until I knew it was discontinuing pickit2 support.

Keep up the work.

@ftorama

> all ARM7s I found (analog devices, ST and NXP)

You can program them through the serial portArray . . . however I’m pretty sure the NXP serial bootloader is the same as all the others. The LPC tool I use can write other parts of ARM7, but there is no AFAIK universal toolArray. and they are only ARM7TDMI parts.

The configuration of other parts of ARM differs when OpenOCD + Your favorite JTAG dongle.

I must say that if the main thing preventing you from having a PIC is Linux support, you are an idiot.

Imagine, you paint as an engineer. There is this image that would work very well for your application, but you should not use it for the reason “linux”. The next day, tell your assignment manager.

He fires you for being an idiot. Hahaha

@Jake

I would have fired you for opting for a pic ^^

Possibly ??? PIC is not getting enough messages!

And yes, the newest mplabx is, although beta, Java-based, cross-platform and is a very advanced idea.

Bring PIC messages!

@ftorama: ARM would possibly be a standard, but internal flash programming in an ARM MCU in fact is not. Try the serial bootloader approach with an ST STR9 or STR7, or with an Atmel AT91SAM. Or even with a Luminary LM3S (now TI).

this is awesome but i am still waiting 3 of the AVR’s programming . . .

@darkore

You’re right, I aimed at the point of view

I think there’s so much devoted fanaticism here. I use AVR and PIC. They’re NOT that different. I have designs based on anyArray. .

I love the arrival of a Microchip product for Mac OS. That’s the only thing that’s kept me away from PIC recently, I’m just tired of the VM.

If you want to upload the osC calibration knowledge for the 12F675, use this little excerpt:

If you have Win2K or XP installation discs, there is a much easier way to do it: install VirtualBox and the guest supplements on Linux. (You’ll want the Oracle loose edition, the network edition, because you want the guest plugins to run on USB support. )

Once done, install the newest MPLab from Microchip. I use it on my Debian system and its functionality is indistinguishable from my Win2K box.

VirtualBox + Micro $ oft also provides me with the ability to run some critical Windows programs, such as clear design and research applications, that have no Linux counterparts.

This is the challenge I had with PIC. It’s almost figuring out precisely what it is that you want to start with as a beginner. PIC, programmers, compilers, programming language, IDE . . . etc. There are too many features with too little compatibility between the PIC families and too little guidance. It was a smart tutorial.

If you need to create tutorials for PIC, how about choosing the right PIC for your project?

In the old days, there was a WinPic program to flash the chips. Today, Linux can use the wxpic program (WinPic clone) to flash its PIC processors. Http://wxpic. free. fr

It is with posix.

Hello, very good instructional, I like it. So far, I used JAL V2 http://code. google. com/p/jallib/ because it works with Windows and Linux, it’s free, it supports almost all pico 10,12,18 gadgets with libraries, and it’s very easy to learn. But now I read these instructions and will check sdcc

@hubert

Thanks for the link. I’m interested in JAL, but the only pages I can find in it are about ten years old (approximately).

“The existence of any pin of the 3 chips used is at 20 mA”

I wouldn’t count on that. This note in the datasheet almost means “it is your duty to restrict the existing to 20 mA”. My 2c? Buy resistance.

Well that would have been very useful to me a few years ago when I was looking to get started with photos; I’ve gotten frustrated and gave up on this very explanation of why. I ended up going with the apr, the paintings are wonderful with unrestricted linux and the usb-tinyISP I use to program it charges around $ 20 and ladyada has linux commands for it right on the site. It sounds like a smart tutorial, however, for me, if I need to invest the time to be informed of any news, it would be a more resistant and functional arm, not a more or less equivalent image. Same explanation why I wouldn’t possibly find myself driving a Chevrolet pickup;)

MSP430, AVR, PIC and ARM. We want tutorials on all three! You at AVR, I hope the others come.

Here is an ARM tutorial for the mc13224v:

one). Buy an Econotag (or 2):

http://www. redwirellc. com/store/node/1

two). Build / Get ARM7 Toolchain. For example. :

http://mc1322x. devl. org/ubuntu. html

3). Get the code libmc1322x:

git git clone: ​​//git. devl. org/git/malvira/libmc1322x. git

4). It is based on:

do -C libmc1322x / tests

5). Connect the Econotag.

6a). Run code from RAM:

mc1322x-load. pl -f rftest-tx_redbee-econotag. bin -c “bbmc -l redbee-econotag reset”

6b. ) Update your code:

mc1322x-load. pl -f flasher_redbee-econotag. bin -s rftest-tx_redbee-econotag. bin -c “bbmc -l redbee-econotag reset”

6c. ) Delete your code because you showed it:

bbmc -l redbee-econotag clear

7) _optional_ debugging with OpenOCD (using econtag’s built-in ft2232):

map from openocd -f / redbee-econotag. cfg

(see also: http://mc1322x. devl. org/openocd. html)

8) Run rftest-rx on the other econtag you purchased (bought two, didn’t you?) And get your packages.

“Microchip PIC microcontrollers can be said not to receive enough messages here. “

True story.

“This is the challenge I had with PIC. It’s almost accurate to perceive what you want to start as a beginner. PIC, Programmers, Compilers, Programming Language, IDE. . . Etc. There are too many features with very little compatibility between PIC Families and very few tips. It was a smart tutorial. “

For starters, the kits are more affordable. For existing development, the build approach is less expensive in the long run, but more expensive to start with. (programmer, chip, breadboard, components, etc. )

As for which compilers and IDE to use, I am Mplab and Microchip compiler is chip offerings. I amArray Microchip is in the process of refining their compiler offerings to 1 compiler consistent with the elegance of the chip. They bought Hitec and lately they offer, for example, C18 and Hitec for the same chip of elegance. I regularly use PIC18, so I regularly use C18 (MCC18). Everyone has loose options, use them for now.

“If you need to create tutorials for PIC, how about choosing the right image for your project?”

This is a delicate request. The chip you choose will depend entirely on how effectively you need to perform the task and what you need to do. The most productive thing you can do is to perceive that there is ALWAYS a more effective way to do it. You’re going to have some extra pins. The good news is that if you ask in the similar PIC forum, I’m sure someone will tell you a decent chip to start playing. For example:

First, find out how to use it. It is not how to design the best chip for the device. There are kits at microchip dot com to help you determine the portions after better perceiving. It is not so bad to design anything and use a differential chip. The difference in charge is quite small and transferring the code from one device to another is quite simple and as I learned.

God, I’m sorry for a long time.

@sHitler, who said: “What’s so smart about the PICs you need to use in an ATtiny or AVR (or picaxe)?”

PIC is less expensive than AVR for roughly equivalent capacity portions.

PIC offers a much wider variety of portions in DIP packages, if you prefer not to use SMD for ease of welding or ease of portion reuse (without the additional unorders or prices of SMD adapters).

And whatever flavor of packaging you want, you can likely locate the precise image you want, as more are provided through distributors.

If any of the above is for you, then PIC has a merit over AVR.

I find it a little ironic that Linux people, with their supposed greatest technical acumen, have a tendency to AVR over PIC * only * because they cannot perceive or cannot be bothered to be informed about how to program a PIC on Linux. Use a Windows box or virtual device running Windows if desired. I’m a Windows guy and I run Ubuntu on a virtual machine whenever I want, it’s just no big deal. Also, exhausting trend test periods on a virtual machine is easy; I mean more

And I was an assignment manager for anything that was a mass produced product, and an engineer told me that I was opting for an AVR that costs more and has longer lead times than an equivalent PIC, just because I was looking to program on Linux instead of Windows, it would actually boot it!

So I am very happy to see this tutorial. And now that Microchip enters cross-platform development, it will be attractive to see what happens to the relative popularity of the PIC / AVR.

Excellent, there’s a typo in your configuration bits

Alex, thank you! Figures that I would like to replace the comments. Updating github nowArray . .

“Microchip PIC microcontrollers can be said not to receive enough messages here. “

There is no discussion here. I love myself a little bit of PIC. Moar pleaz.

I never literally understood why other people write their systems for those types of C devices given the simplicity of their instruction sets. I was able to retrieve the ARM meeting in about one night, only reading the disassembly at IDA and Fujitsu FR in about a week (it took longer because IDA incorrectly lists the operands for add2 and some other minor issues). Compared to the group shit looking to do something meaningful with Intel/AMD SSE/AVR/any shit they added while writing the meeting for those microcontrollers, it’s good, but I see it’s rarely mentioned.

The PIC fan here too, underrepresented here.

Nice tutorial. Thanks HaD!

@Jake, you’re falling behind but I’m going to bite.

This instruction is at least useful to me. I’m not an engineer and (like many others) I don’t run Windows, I haven’t run it since the mid-1990s, so the Windows-only progression team is a genuine impediment to me, unless they can paint under Wine or anything similar (and that slows things down considerably). It is not a devout position, it is purely practical at this stage.

Of course, if I were an EE, I still wouldn’t have any selection to follow the PIC regardless of those issues if this turned out to be the optimal selection for an application. But for the record, this is an IEEE forum.

Microchip’s gcc compiler works fine on wine. Here is an example of a makefile that runs gcc wine:

I have a clever explanation for why you should go for PIC over AVR – you can design or order just about any and every device they’ve made in the last 20 years direct from the factory with a credit card at the list price. I don’t know if the component I designed will be available next year or it will have been replaced via a “compatible” device that will still require me to pass an application note outlining the migration path and forcing me to resurrect the chain tool I used . .

Oh, and I think in general, PIC devices have the advantage. I have a tendency to use more AVR for recreational projects due to the loose tool chain.

I’m sure other people will agree with me here, however in order for the microchip to really gain momentum, they will have to put in the ‘external reminiscence bus’ (which other people have been discussing for a LONG TIME). Microchip, it turns out, needs to combat this concept for some reason. I mean, hay! . . . Why go for a 32-bit photo when you’re not really getting anything that has been on your line for a while? > ???? it just turns out like a white elephant.

I’ve only been microcontrollers for a few years, but from what I’ve noticed, the PICs and AVRs look pretty similar. Personally, I use PICs because that’s what the teacher who threw me on them knew. So when he taught in school, everyone learned about PICs and I helped run labs that use them, so I use PICS. But I have a friend who loves using AVR; So it seems to me that this is largely what you start with. Personally, I am incredibly pleased to have read this article, if only to realize that Microchip is in the process of creating a Linux edition of MPLAB. One of the walls of my device was Windows only because of systems like this, where it is much less difficult to use them in Windows than to perceive the complexities to constantly make them pictures in Linux.

Leave a Comment

Your email address will not be published. Required fields are marked *