Pic USB Application

Pic USB Application

ABSTRACT

This article is an introduction to designing a USB PIC based device. It is based on the C# API. The article will demonstrate how to use a PIC18F4550 to produce a USB full speed 2.0 Device which will perform basic input/output operations, whilst communicating with a C#.Net application via the microchip drivers.

Overview

It is important to consider how the overall system is going to work, and how the different components interact with each other to complete the overall task which in this case is a rather trivial one. At the basic level we are going to use the on board USB interface on the PIC to communicate with PC. Once the pic is connected to the PC, We shall be using the standard microchip drivers to communicate with the device. This forms a data channel from Windows to a segment of code in the PIC. The final link in the chain is the code at both ends of the channel, which can be customized to produce the functionality required.

Hardware

The basic hardware design can be seen picture. you'll find a normal USB connector only has 4 pins available, The hardware on Board 2 A/D port, 2 Bottom switch, 3 leds.

PIC Software

The example PIC complete code in this article can be download here . Extract the zip file into C language. To compile the PIC Source code with CCS All being well the code should have compiled successfully, however if it is unsuccessful please go back and check all the project and include paths are setup correctly. (Any other strange errors please let us know)

You should now be able to test the code, to do this program the hardware using your favor ate PIC programmer, and connect it to your test PC (warning check the hardware first, there is a risk of causing damage to the PC), all being well the PC should request for the drivers for a "PIC18F4550 Family Device", you can now either skip to the Driver section or keep reading if you want to understand how to add in extra functionality to the device.

Windows Drivers

Now you've built the hardware, compiled the source, you are ready to go. All being well when you connect the PIC to the PC, windows should request the drivers, if not go back and check the hardware and that the PIC programmed correctly. The drivers we shall be using are the standard Microchip ones, and modified some one. These changed to alter the icon, change the device class etc... However this isn't the place to explain all that, all being well a new article might come out containing this information. The drivers can be found below, or in the complete code at the start of the article. Hopefully you shouldn't have any issues installing these (as long as windows ask's for them, you should be in the clear), so I'll assume you are all technically competent enough to do this (as you are designing USB stuff after all!!).Once the drivers are installed correctly, after connected to the pic ready led should be on alternatively to indicate the connection has been established.

Application Code

The application code can be found download page. The application was developed using C# 2010; In order to run the code (or compile it for that matter) you will also require the .NET Frame work to be installed. The code should be pretty self explanatory however I will go over the general concepts.

Example Application

The idea program is to create a simple way of controlling 3 LED's, A/D attached on Board, The application consists of three main parts, the mpusbapi.dll, USB interface class and the main form. The DLL (located in the debug directory) acts an interface between the application and windows driver, therefore do not modify this, and just ensure that it is located in the directory of the program.

Again, it is no warranty on that and it is not encouraged use it for commercial purpose. You may distribute it or modify it. If you see any bugs with my code or have better idea to improve, please post in this section.



User Comments

No Posts found !

Login to Post a Comment.