Saturday, March 31, 2018

Trick MPLAB-X 1.80 to offer debugging and programming support to Pickit 2 for PIC18F46K22

If you are a PIC programmer under Linux, you already have the pk2cmd installed, including support for the PIC18F46K22. If you use the MPLAB-X IDE, the programmer is painted in red for this microcontroller.

What follows, it works for MPLAB-X version 1.80, did not tried for the others. In the following folder, you will find the mplabinfo.jar archive:


Inside the archive is another folder structure. The file mplab.deviceSupport is what we need, and can be found in the folder showed bellow:


Open the file for edit (as root) and search for the PIC18F46K22 word. On that line, the items mp:pk2d and mp:pk2p must be changed from "no" to "yes" values - you will understand once you see the content of the file.

Save the file (take care to be saved as a Windows file) back into the archive, go back to your normal user rights and start the MPLAB-X. On your project, you will see that the Pickit 2 programmer is now painted in yellow which means that the debug part is in beta stage for that microcontroller. I not tried it yet programming the micro from inside the IDE or the debug part but I will update the article with my result.


Now I've realized that you have to add an entry for the PIC18F46K22 into the pk2.xml file that is found in the PICKIT2.jar file. This jar archive can be found in the same folder as mplabinfo.jar archive. So it seems that a little more work must be done in order to fully trick the IDE...


After adding the required entries in pk2.xml and pk2xs.xsd files, the pickit2 programmer won't even blink a LED. No support under Linux... :( Someday I will have my PicKit3 programmer/debugger, but not anytime soon.

P.S., I can't post the code here, Blogger removes anything XML.

Sunday, February 18, 2018

It could be something...


I've added some recent tests, including a new version of XC8 compiler (1.45) and the SDCC compiler (3.6.9 #10225). a development version.  The results are surprising. First here is the SDCC that performs better than the 1.33 version of the XC8 compiler (in free mode), and second, the new version of the XC8 performs better in free mode than the JALv2 compiler that has all the optimizations active.

Original article:

At the article's date (December 19, 2014), MPLAB XC8 compiler is at 1.33 version and shockingly, it scores smaller code sizes in the free version than the older and unsupported MPLAB C18 in his commercial version. Regarding compiling bootloaders, C18 still remain the only alternative between the two, but anything else can be successfully compiled with XC8.

Well, "anything else" means all I have tested so far, in the form of a common code (the code can be compiled without modifications by both compilers) for custom libraries and projects and that is:

  •  - I2C library;
  •  - hardware serial comm. library;
  •  - non-blocking delays library;
  •  - 4bit LCD HD44780 library with arbitrary pinout;
  •  - PCF8583 RTC applications displaying on LCD or sending on serial;
  •  - Blinking LED with non-blocking delays, in both sloted (JALv2 with Jallib) and millis (Arduino) ways.

Saturday, February 10, 2018

Bootloader and board upgrades

I did modifications to the both versions of the Il Pinguino Rosso boards and to the serial bootloader. Now there is a single unified design - the bootloader no longer address different hardware configurations of the various variants of the board. Bootloader had a bug that prevented correct functionality - now is fixed.

The Bootloader

- is a modified copy of the AN1310 Microchip high speed serial bootloader (although, mine is set to the 19200bps);
- it can be compiled entirely and exclusively with gputils open-source assembler;
- is delivered as PikLab (the link is for the Fedora and OpenSUSE linux distros) project under linux, but console utilities that allow a standalone compilation (as long as you have the gputils and pk2cmd installed and functional) are also provided;
- the board enters bootloader mode when the user button on the board is pressed at the power or reset time. If not, the application is started immediately! I would say that this is the desired behavior in the industrial environment :);
- the application is located in flash memory starting with the $300 address and the vector interrupts at $308 and $318 - the bootloader occupies the first 768 bytes of the flash memory.

The "Breadboardable" Board

- is based on the Microchip's PIC18F46K22 microcontroller (exclusively, but you can use the schematic as a reference design for your own micro) because it offers separate I2C and SPI peripherals;
- the boot button puts the RA4 pin at GND when pressed;
- the cathode of the boot  mode indicator LED is grounded (the anode is connected to the RC2 pin) via an 470R resistor;
- the one variant of the board offers a standard Arduino PRO serial connector and the other design has a PIC16F1454 micro included that connects the board at an USB port (virtual serial port);
- all the examples provided in the repository are Eclipse projects that are compiled with the SDCC open-source compiler.

Go to the repository - all you need is included there!

Wednesday, June 7, 2017

Eclipse IDE with SDCC C compiler tutorial

I created a new page with a mega tutorial about using the Eclipse IDE with the SDCC C compiler in creating projects for the Il Pinguino Rosso board (PIC18F46K22) here.

Tuesday, May 30, 2017

SDCC support

Update: The sdcc plugin for eclipse is designed to work for 8051 microcontrollers but it is possible to be used for PIC microcontrollers, as compiler will ignore non-specific parameters. And it works just fine... 

Original article: I won't start another blog for SDCC C compiler alone. This blog can host both projects as is about a common language and differences are minimal. But SDCC project has a separate github location so it won't interfere with one another.

Now, it all works in Linux and we have many options for a dedicated IDE: eclipse, piklab, mplabxide. With mplabxide and his SDCC plugin I got nowhere - I can't configure it properly yet  With piklab would be the best but there are some requirements and won't work on all linux distributions so, I decided to give the eclipse plugin a try. I installed the oldest eclipse version supported by the CDT and the sdcc plugin, having the sdcc compiler installed in a subfolder of my linux home folder. Will see how it goes and if it works, I will publish the entire setup. If not, I'll move to the piklab ide.

Saturday, May 20, 2017

Back tracking...

I get problems trying to use the newest versions of MPLAB X IDE and XC8 compiler... I thought ... I'll abandon the Microchip toolchain  in favor of SDCC or even cpik C compiler and, of course, JAL language, all working in Linux as I've finally became a full Linux user because of the Microsoft aggressivity with their Windows 10 (we all saw that Windows 10 proved to be a huge spying tool).

But on the second thought, I downloaded some older versions, 2.15 for MPLAB X IDE, 1.31 for XC8 and 1.11 for XC16. So, this will continue. I saw that the serial bootloader firmware written in assembler compiles with errors in this IDE version so I use the assembler from the MPLAB C18 compiler (see this article) and works fine. I know it will not offer support for the most recent Microchip additions, but this is for the PIC18F46K22 microcontroller.

Now I'm working with a Nucleo board based on STM32 microcontroller and recently finished the onewire library for DS18B20 temperature sensor and I will port the library here when there will be time for this.

Wednesday, January 20, 2016

AVR with Microchip emblem.

Yep, as anyone knows by now, AVR is a Microchip property. Not yet a product... will see about this later. Anyway, first effect: Pickit2 programmer is no longer restricted in programming AVR microcontrollers (this means a common ICSP connector for development boards addressed to usual PIC programmers willing to try AVR). Also, we expect a better availability and maybe low prices for ATmega and ATtiny microcontrollers.

See the Microchip declaration here.

Sunday, December 7, 2014

The full FatFS library for C18

This time, the full version of FatFS library, but for PIC18F27J53 microcontroller. The library is adapted by @spinnaker and posted on "All About Circuits" forums. Go to "Microchip MDD File System" thread and from the second post you will be able to download the archive containing his project.

Of course, you'll have to subscribe in order to download the file. In the linker script you'll see three protected zones for the bigger arrays FatFS needs. Many thanks @spinnaker!

Friday, December 5, 2014

One Wire and Dallas Temperature Sensors

The provide library and example for DS1820, DS18B20 and DS18S20 temperature sensors. It also have a search function, useful when you don't know the IDs of the sensors. The code is written for CCS C and MPLAB C18 compilers.

The code is quite nice, thanks!

Wednesday, July 9, 2014

MPLAB C18 Lite for Windows is available again

The MPLAB C18 Lite compiler is available again on the Microchip's official page. The actual version is 3.47 and is an insignificant update to the 3.46 version (just a file corrected for two microcontrollers - something which you can do for yourself on the 3.46 version). It remains to be seen if Microchip altered in any way the lite compiler...

This way, this blog gains even more meaning...
But don't forget that we already have full versions under Linux and OS X.