Microchip PIC18F27J53 Generic HID USB Project

For various projects I have settled on using the PIC18F27J53 microprocessor. It is an 8 bit PIC microprocessor which runs at 48 MHz (12 MIPS), has 128 kB of memory and has a built in USB transceiver. This chip should provide more than enough flexibility for all of the projects that I have in mind.

The code here should give you a start in getting a PIC18 device talking to a Mac OS X computer via USB.

My first goal was to get the USB interface working. For the microprocessor code, I am using the Microchip Application Library, which can be downloaded directly from microchip.com. The microprocessor code is based on the PIC18F demo code found at waitingforfriday.com/index.php/Building_a_PIC18F_USB_device and the USB demo files included with the Microchip Application Library. I have reworked a lot of the code in these demo to work with the PIC18F27J53 microprocessor, simply the code down to the bare essentials, and to use ascii characters for the control characters.

Download the Generic USB HID PIC18F27J53 Code

To get the code to compile you will need to have installed: MPLab, C18 compiler, and the Microchip Application Library. When you first load the MPLab project you will need to add the Microchip Application Library to the include search path. In MPLab 8, this is found under the Project->Build Options->Project file menu item. Under the directories tab, select ‘Include Search Path’ and add the directory for the include files for the application library. In my case, this is E:\Microchip Solutions v2011-12-05\Microchip\Include. You will also need to link in the usb_device.c and usb_function_hid.c files. You may also want to change the compiler mode to use the large memory model, otherwise you may get warnings when using string literals if you don’t cast them as  (const rom far char *).

For the host side, in this case Mac OS X, you will need to install Xcode before getting started, a free download from the Mac App Store. The code here is based off the code found here, again with several changes and simplifications.  To get the code running, simply add the two files to a new Xcode project and add the IOKit framework. The program presents you with a command prompt. At this prompt pressing ‘a’ will read the LED status (defined in hardwareProfile.h as LATA<3>), ‘A’ will toggle the LED, and ‘d’ will return the debug buffer.

Download the Generic HID Mac code

 

A useful tool included with Xcode is the USB prober, use spotlight to find it. This tool details all of the connected USB devices. I typically have it open, just to make sure that the device is properly enumerating.

Generic HID Mac

Generic HID PIC18F27J53

2 thoughts on “Microchip PIC18F27J53 Generic HID USB Project

  1. Thanks so much for a good working code example for this PIC. Made all the little adjustments that you mentioned and it built and works properly. Now the hard part for me is going to be changing it to send/receive data from windows based system.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">