Categories
electronics

pic18f4550 bootloader

I’ve made a couple of pin assignment tweaks to the Microchip HID bootloader. You’ll need MPLAB X, the C18 Lite compiler, and the Microchip Application Libraries. The bootloader I started with is in the Application Libraries under USB/Device – Bootloaders/HID/Firmware – PIC18 Non-J. I’m not sure about the license all this stuff operates under, so here are the changes I made as a zipped diff, and here’s the zipped hex file in case you happen to like my pin assignments better than the default microchip ones (I use RE2 for the bootloader sense and RC0:2 for LEDs; this leaves all of ports B and D available, plus A0:5 and E0:1 which happen to be 8 contiguous pins; it also leaves RC4:5 for USB and RC6:7 for serial).

Categories
electronics

pic18f4550 – first impressions

So I’ve decided to build a new circuit board to convert an old mechanical keyboard (NCD N97) from PS2 to USB. (A normal converter won’t work, as this keyboard only operates in “mode 3” which I very much doubt your average converter will know about). Initially I expected to use an Atmel ATmega32u4 or similar for this – but there’s no through-hole version of that chip, and I don’t want to have to produce a proper PCB and do surface mount soldering. (Atmel take note: I’d be using one of your chips if you did have a through-hole version!). My next thought was to embed a Teensy (or adafruit 32u4 breakout, or Teensy++) into the middle of some veroboard , but that means spending at least $20 on the chip, and I’d have a usb socket inside the keyboard which would then need to be routed to the outside etc.

A bit of googling led me to the Microchip PIC18F4550, which is available in 40pin DIP, and can be purchased from Futurlec for under $7 at time of writing. I order two, and a bunch of support bits (appropriate crystals etc).

Then I start to find that there are some fundamental differences between getting started in the PIC world compared to the AVR world (especially as a linux user who doesn’t want to spend the $$ on a proper programming tool like the PICkit 3).

It seems that the AVR-on-linux community has two big advantages – one is that there’s a nice GCC-based compiler which everyone uses, and the other is that avrdude supports a large number of different programmers, some of which are pretty easy to build. As a result, the community has pretty much a common toolset across the board. And thanks to the arduino project, you can even buy a bare chip with a bootloader on it fairly easily.

PIC-land is different. For a slightly-out-of-date view see this ladyada post. Apparently a GCC port isn’t possible, so there’s a bunch of different C compilers out there in use, most of which aren’t free. There also seems to be a dizzying variety of programming tools, most of which support a limited set of chips, seem to be rarely maintained, and only work with a small number of programmer hardware designs. On top of that, programming generally requires a 12V source (on a 18f4550 there is a low voltage programming mode, but it doesn’t seem to be widely supported and it eats a pin in the middle of an IO port). Which makes the programmer hardware more complicated. After several evenings googling and fruitlessly installing random unmaintained windows programmers (which is complicated by running windows 7 64bit, which doesn’t generally allow the sort of direct access to the parallel port these programs expected from Windows ME or whatever), I discovered that, at least for the 18f4550, the combination of Byron Jeff’s Trivial HVP Programmer circuit and the linux ‘pkp’ programmer which comes as part of PiKdev works nicely.

In addition, Microchip have their beta MPLAB X programming IDE available, which works on linux, and also have the “MPLAB C18 Lite Compiler for PIC18 MCUs” available for free-as-in-beer, along with the “Microchip Application Libraries”. The combination of these 3 allow you to build a bootloader which allows you to reprogram the chip using hid_bootloader. I’ve tweaked the bootloader slightly to suit me better; see my bootloader post.