Close

Modifying the sources for new devices

A project log for Microchip PIC Arduino based programmer

I love to program programmers. Yo dawg...

jaromirsukubajaromir.sukuba 01/18/2016 at 09:375 Comments

Currently, the supported devices are 16F1507, 16F1508, 16F1509, 16F1825 and 16F1829 with LF variants for the latter two.

Though I'm planning to add more devices, you may want to try it by yourself. For basic PIC16F1xxx devices, you have to add new lines into setCPUtype function in pp2.c file. Each MCU has its descriptor, looking like

if (strcmp("16f1507",cpu)==0)
{
flash_size = 4096; //bytes, where 1word = 2bytes, though actually being 14 bits
page_size = 32; //bytes
devid_expected = 0x2D00;
devid_mask = 0xFFE0;
}

It is determined by four parameters:

flash size - its size is in words, where one word is calculated as two bytes, though the single program word occupies only 14 bits.

page size - this is the biggest chunk of FLASH that can be written at once.

devid_expected - clean device ID, where revision is chopped off

devid_mask - mask to be AND-ed with word from address 8006h to get clean device ID.

Say you want to add PIC16F1503. Download the datasheet and if you are lazy, search for "Device ID" string. One of the first search results should get you to the chapter 4.6, named Device ID and Revision ID

You can see what revision looks like, so lets create mask to chop off, where revison bits are
0010 1101 111x xxxx - ID register, where x are revision bits
1111 1111 1110 0000 - MASK to leave ID untouched
F    F    E    0    - MASK in hex format
0010 1101 1110 0000 - ID register without revision bits
2    D    E    0    - ID in hex format

The device ID translates to 2DE0 hexadecimal and mask to FFE0 hexadecimal. Now we have to determine FLASH size and page size.

In the same datasheet, go to chapter "Flash program memory control", or search for "latches". You should find chapter 10.2, where is described size of erase and write block.

The write latches buffer the data to be written into FLASH, so our page size is as big as amount of latches. Because flash is erased in bulk, write latches are interesting - there are 16 words of write latches, making 32 bytes of FLASH write "buffer".

Flash size is easy to determine, on second page of datasheet is comprehensive table

where PIC16F1503 has 2048 words of FLASH, translating into 4096 bytes. So, complete entry for PIC16F1503 should look like this
if (strcmp("16f1503",cpu)==0)
{
flash_size = 4096; 
page_size = 32;
devid_expected = 0x2DE0;
devid_mask = 0xFFE0;
}

Recompile, run and enjoy.

Discussions

Stefan Lochbrunner wrote 01/19/2016 at 15:35 point

Just wanted to let you know that you can add the 16F1454 and 16F1503 to the supported devices list. No surprise there, just confirmation. Feel free to merge the changes in my fork.

And again, thanks a lot for this project!

  Are you sure? yes | no

jaromir.sukuba wrote 01/19/2016 at 18:59 point

Did you try that in real hardware? Give me more details, please!

  Are you sure? yes | no

Stefan Lochbrunner wrote 01/19/2016 at 19:57 point

Yes, I tried it in real hardware. I used a Pro Mini and CP2102 as programmer and followed your (Windows) instructions in the other log for building a new executable. This is my first time using a PIC so I tried just a simple blink example for now, but that should prove that it's working, right? What else details do you need or what tests would you like me to run? Anything you need :)

  Are you sure? yes | no

jaromir.sukuba wrote 01/19/2016 at 21:02 point

Yep, blinky should prove your programmer is working, unless you made some major changes.
I'm glad you got it together using the instructions, that's the spirit of this site ;-) 

If you find a time, I'd absolutely love to see it here on .io. Other folks like @davedarko are building remakes of projects from here, like #Me building projects from hackaday.io. I think it is great idea and valuable feedback to original authors. No big deal, just a photo or two, along with a few sentences are enough.

  Are you sure? yes | no

Stefan Lochbrunner wrote 01/19/2016 at 21:45 point

The file I wrote is only slightly different from the blink example in one of these logs so it should be fine. Not sure yet if I'll throw them on GitHub or in a project here, we'll see.

For now my version of the programmer is still just the Pro Mini on a breadboard with wires connecting it to the PIC so it's not really much to show off but I have been thinking about making a simple adapter for the Pro Mini to the ICSP pinout.

Yeah, I've seen @davedarko's project and the one from @al1. When I built a #Ignore this ESP8266 board I just posted some pictures in the comments. Maybe I'll make #Misc. spur-of-the-moment projects also the place where I build other people's projects since it's already themed around 'mini projects' already. Anyway, I'll find a place to put that info for you ;)

  Are you sure? yes | no