Monday, June 29, 2009

PIC 18f14k50 USB Interface Board: Part 1

This is the first blog regarding a PIC18f14k50 USB IO board. This first session will focus on the design and building of the board, future sessions will take about software application that are being developed for this board.

At the start of the development of the board, I had the following “bullet spec” in mind:

  • Development “starter” board for Jal(lib) USB developement
  • It must have a USB 2.0 full speed connection
  • Must be able to use it as a USB<->RS-232 interface converter, including 2 HW handshake signal, operate as a true RS-232 interface as well have the ability to use it for 5v signals (RS-232c, so it can be used to interface board towards other test boards that don’t have a MAX-232 level converter).
  • Must be able to use it as a USB<->I2C interface board, either act a master or slave device
  • Be able to add (small) daughter boards, in order use to the board as a HW/SW development platform (e.g. Remote control receiver, remote control transmitter etc)
  • Homebrew friendly (easy to build, single sided PCB, no SMD component)
  • Cheap (~10 Euro)

PIC selection
The first choice is what PIC to use, since I want to use it for JAL development (which restricts me to the PIC18F series), onboard USB Serial Interface Engine (SIE), should be a thru hole device and should run with 5v IO, I got the following list from the Micrcochip website:

Product Fam Price Fl EE RAM I/O

PIC18F13K50 $1.39 8 256 512 15
PIC18F14K50 $1.53 16 256 768 15
PIC18F2450 $2.23 16 0 768 23
PIC18F2455 $3.30 24 256 2048 24
PIC18F2458 $3.58 24 256 2048 24
PIC18F2550 $3.44 32 256 2048 24
PIC18F2553 $4.12 32 256 2048 24
PIC18F4450 $2.39 16 0 768 34
PIC18F4455 $3.51 24 256 2048 35
PIC18F4458 $3.79 24 256 2048 35
PIC18F4550 $3.65 32 256 2048 35
PIC18F4553 $4.33 32 256 2048 35

In the past I’ve used the 18f4550, which is a nice chip, but it is a bit expensive. I also have used the 18f2450 in a couple of projects; however, the main drawback is the lack of onboard eeprom (always handy for device specific settings). The recently introduced PIC 18f14k50 appears to be a nice compromise (almost similar to the 18f2450, but it is a bit cheaper and has onboard eeprom). Even though it is a low pin count device, I think it has enough IO pins. I have considered the 13k50, which is even a dime cheaper, but the flash and memory size is quite limited and the availability is a problem. However, the board can be used for both chips.

Schematic & PCB:

Once the PIC was selected, the design is straightforward:

I won’t go into the details of the “standard” PIC logic, consisting of the crystal (X1) + caps (C3/C4), ISCP connector (J1) and decoupling capacitor (C1).
There are two switches connected to the PIC, SW1 is can be used as a reset switch, SW2 is a generic switch with pull resistor. The DB-9 connector is connected via a MAX-232 level converter with the PIC (towards the internal UART PINs). The non-level shifted converted TX/RS signals are also connected to J3, in addition to the UART signals pin-5 is connected with the PWM/CCP unit of the PIC.

The 5 volt supply of the USB connector is used to power the board; the differential USB signal lines d+/d- are directly coupled from the PIC to the USB connector. Capacitor C5 is required for the internal 3.3v regulator.

The I2C header signals are also directly coupled with the MSSP unit, it can be used as a master or slave depending on the firmware, besides the 3 standard wires, also a 5v is available on the connector. The pull-ups can be enabled by placing the jumper (JP1).
Potmeter P1 is connector to AN5 of the PIC, this can be used for ADC experiments.

OK enough about the schematic. Richard Zengerink was so kind to draw the schematic and do the board layout. The board layout is depicted below, a PDF file of the layour is available in the SVN repository ( 18F14K50+EXTRA_lay_out.pdf
), this has the mirrored, 1:1 scale, so when printed on glossy paper with a laser printer, it can can be ironed into a copper cladded board, then etch it and drill it.

Building the board should not be too difficult; it took me about an hour to do the component assembly and solder it and perform some quick tests (check power connections, and check shortcuts)
A picture of the assembled board is depicted below:

Testing the board;
The first test is to connect a PIC programmer to the ICSP connector. Program the 18f14k50_led_switch_test.hex file on in the PIC and reset the board by doing a power off/on cycle (external reset is disabled in order to test SW1). The source code and Hex file are available in the jallib SVN repository

The application will turn on both LEDs for about 5 seconds, afterwards it starts to blink both LEDs every second. When SW1 is pressed, LED1 will stop blinking, when SW2 is pressed, LED2 will stop blinking.

Once this is working, we can confirm that ICSP, Power, oscillator, SW1, SW2, LED1 and LED2 are properly mounted.

The next step is to download the bootloader. Select the 18f14k50_usb_bootloader.hex in the ICSP programmer, and program the hex file. Remove the ICSP connector (since there shared with the USB lines), connect the USB connector with a USB cable with the Host computer, when plugging in the USB connector, hold down SW2 (program button)

If everything went ok, after a couple of seconds the Host computer will detect the USB bootloader device, it will ask for a driver. Navigate to the directory where the USB driver bootloader driver files are located, ignore the certificate warning by selecting the continue button. MCHPUSB Custom contains required drivers. Unzip the package to a local drive, the drivers are located in the MCHPUSB Driver\Release directory

Once the drivers are installed, you can use the PDFSUSB.exe applicatio, contained in archive. After you unzip the file and launch the application, select the dropdown arrow of the combo box.

You should see the PICDEM FS USB 0 (BOOT) option, select it (see also screenshot). After selection, it should update the status bar, it will depict the version number (1.20) of the firmware.

When using the bootloader, you need to add the following setting when compiling a JAL file in cooperation with the bootloader:

-loader18 –no-fuse

The JAL compiler will generate special startup and interrupt code if the loader18 option is specified, the no-fuse is used to avoid overwriting wrong fuses which can mess up the bootloader (although the PDFSUSB will also emit a warning, and ask for confirmation when overwriting the fuses)

So far for part1, next blog(s) will discuss how to use the board as a USB<->RS-232 convert, use it as a USB driven I2C master or slave device and show how to make a small daughter board to capture and generate remote control infrared signals.

Hope you like it, feeback is always welcome…

Albert Faber & Richard Zengerink


  1. So, it will become something like Arduino? Why not having sockets for I/O ports for external connection, having the possibility to use the board for large areas of applications?

    I dislike the development boards which have fixed pin assignments (I mean, which are not configurable - impossible to use pin X because is set only as output, and driving a LED and can't be disconnected via a jumper)

    Anyway, I like what you started.

  2. Very nice job ! I like that !
    But I agree with funwlw65, development boards aren't enough configurable. What about using something like Arduino ? All pins from the PIC are available through connectors, and you can plug daughter boards (shield) on it. In this case, the daughter board would be dedicated to development. You still can plug any daughter board specialized in what you need.


  3. I would like this to be continued.. I want to learn "USB"

  4. It is possible to adapt your boot loader for 18F2550 but without the need of having a start button?

  5. I've thought about this issue as well, there are some solution, eacht with its own drawbacks.
    The main issue is the code size that's left, the current bootloader has to fit within the 2048 bytes, there are some bytes left, but it is pretty tight.

    Possible solutions are:
    1) At startup, check if bootloader software is active (needs some special bootloader SW on the host pc, but I've the source code so it is easy to change), when it times out, jump to the user app; possible issues are:
    When starting trough: how to make sure that all registers and HW are in the reset state

    2) Reserve one byte in EEPROM (or maybe even better, use the ID locations, not all PICs have EEPROM), which indicates if the bootloader needs to be started or jump directly to the user code. However this requires that the user app always should have the ability write this EEPROM /ID location and forse a reset. This can be accomplished if we have a JALuino "runtime kernel" that always should be linked in with the user app,

    I think option 2 is the most feasible, the only drawback is that if the user downloads the wrong hex file (i.e. without the JALuino kernel) you're not been able to download another kernel, so maybe an "emergency" boot switch can be added, but this will add some resitrictions on this pin usage, the pin must be held high when switch is not pressed), or add some checks on the HOST PC bootloader SW to vailidate that the Jaluino kernel is part of the hex file

  6. Hi,

    Can you tell me what programmer to use to connect to the board? Also, is WinPic an option as program software?

    Thanx, Rick

  7. Hi Rick,
    Yes you can use an standard ISCP PIC programmer

  8. Thanx for replying Albert.
    Unfortunitly i counted about 20 programmers online, all for different types of PIC's and more. Most of these have other pinnames than the 18F14K50.
    Than the software, most can use a wide range of hardware but what to choose?

    Can you be more specific, lead me to a link or something?
    Really want to create the hardware myself.

    Thanx, Rick

  9. Would this board work?

    "Low Pin count USB development kit" made by Microchip.

    It is about $40.

  10. I tought the PIC18F14K50 could be programmed directly via its own USB port. Is an external programmer still needed ?

  11. Every PIC is an empty box, no software inside, no bootloader. Microchip don't sell them with boootloader inside. You need an external programmer.


  12. Thanks Vasi, I understand. I'm ordering a Pickit 2 programmer on eBay and some of the parts for this project from Mouser Electronics. I'm still mystified by the "program" pushbutton.

  13. The bootloader will start using "Program" switch. In this blog Albert is explaining how you will upload your application using bootloader:

    "The code is compiled with jalv2 using the -loader18 -no-fuse. After compilation, you can reset the PIC 18f14k50 USB Interface Board and holding (same time - my note) down the program button. Now the PDFSUSB application can be used to download the HEX file, after download reset the board. If everything went OK, it should recognize the USB-CDC device and ask for drivers (Windows only), select the driver (which can be downloaded from"

  14. At reset time, I think the bootloader will test if "Program" button is hold down. If not, the bootloader will launch the user application (if any). If not, it will enter in boot mode and will wait for PDFSUSB application to send your program. After that, you need to press (for short time) only Reset button to start your application.

    My board don't have a Program button, and is using another bootloader, with autostart function, written by Albert, so I can be wrong about the functionality of this bootloader.

  15. I'd like to use one of the analog inputs to send analog data to a host PC. How do I accomplish that ?

  16. It involve using ADC library and USB Serial library...
    Look at ADC examples and at USB Serial examples and put them together. So... you are using this board... this mean you will have Independent analog pins...

    -- start example:
    include 18f14k50 -- target PICmicro
    pragma target clock 48_000_000 -- oscillator frequency
    --No fuses here, you are using a bootloader
    --use following parameters to your compiler:
    -- -loader18 -no-fuse

    -- include libraries
    include usb_serial
    include format

    -- now configure ADC
    const bit ADC_HIGH_RESOLUTION = true
    const byte ADC_NVREF = 0
    include adc
    pin_C4_direction = output
    pin_C6_direction = output
    pin_C2_direction = input
    set_analog_pin(5) -- is connected to a potmeter on the board

    var word measure

    forever loop
    measure = adc_read(5)
    format_word_dec(usb_serial_data, measure, 4, 0)
    usb_serial_data = 13
    usb_serial_data = 10
    end loop
    -- end example

    Not tested of course, I don't have that board...

  17. That's great Vasi.I'm begining to get the idea ! That brings the data into the Jal terminal.
    Now here's the next question: How do I get the data into a C# application I'm writing with Visual C# Express ? (Let's assume it's a rudimentary data logger application).

  18. Does a Bootloader for the 18F14k50 exist with the Autostart function? My project will not have any buttons, so I will not be able to put it into 'program mode' this way.

  19. You can compile it from sources. The botloader with autostart function have sources included. See it in SVN from

    Look for examples for 18F4550 microcontroller. The source have definitions also for your microcontroller.

  20. For readers, I answered to T_Rex in another article.

  21. Hi Vasi,
    I think you gave very good support and answers, maybe I should be even add more detailed explanations in the future so more people can work with it. It might be a good idea to grab all USB related blogs and comments and write a new manual/tutorial

  22. Thank you Albert, my knowledge is still low in USB area.

    Yes, I would like to see/have an USB manual. These days, the main attraction for a compiler/language are USB libraries so it will be very helpful. I tested many languages with USB support and read a lot of related topics on their forums. The main problem with many commercial languages is that they don't have a relocatable USB code. I mean, if you have an USB Serial application written from 0x00 flash address, it works ok but don't when you try to use it with an USB bootloader. I can enumerate at least three commercial languages and also the free SDCC compiler having problems with some USB CDC stack.

    So, your libraries are great and I try to spread the news as best I can.


  23. hi,You have a very good blog that the main thing a lot of interesting and useful! usb protection , thanks

  24. Hello,
    Where can i get the files and MCHPUSB Custom and some other files, since
    they are no more found on google groups.

  25. You can find them in this archive:

  26. Hi,

    Per the schematic, is RC2 the "official" program pin for SW2, if one were to use the Microchip bootloader mentioned in you article?


  27. The PCB drawing (18F14K50_usb_io_board_PCB.pdf)I have downloaded from your website is apparently corrupted. Please assist. Thank you.