Disclaimer:The following are my notes. As I am learning electronics, I am making my notes available. I hope they will be of benefit. However, I do not guarantee the accuracy of my work. I recommend the reader exercise critical thinking.
|
18F Firmware
PIC18F4550 Firmware
Please review the PIC18 Setup
page before reading this page.
This page will cover the creation of the firmware for the REPING program
REPING: A Linux server program constructs a packet of data and sends it to the
PIC18F4550 microcontroller using USB communications.
The microcontroller reverse the order of the bytes in the packet and
send the new packet back to the server.
I call this program "reping".
USB API and Sample Code
The installation of the Microchip MCHPFSUSB v2.1
framework creates many source directories.
Locate these two directories on your system:
- \Microchip Solutions\Microchip
This directory contains the actual Framework API code.
- \Microchip Solutions\USB Device - MCHPUSB - Generic Driver Demo\Generic Driver Demo - Firmware
This directory contains example firmware code.
Create a new directory called REPING for the new project.
Copy the directory \Microchip Solutions\Microchip into the REPING project directory.
Navigate to the \Microchip Solutions\USB Device - MCHPUSB - Generic Driver Demo\Generic Driver Demo - Firmware" directory. Copy the following files into the REPING directory.
- HardwareProfile.h
- main.c
- usb_config.h
- user.h
- user.c
- usb_descriptors.c
- rm18f4550.lkr
New Project
Within the MPLAB IDE (I'm using version 8), create a new project. The following table
list the settings to customize for this project.
Description |
How to ... |
Create a new project |
Project / New
Enter "REPING" for the Project Name
Select the REPING directory for the Project Directory
|
Configure the project for the PIC18F4550 |
Configure / Select Device...
Select PIC18F4550
|
Configure the project for the C compiler. |
Project / Select Language Toolsuite...
Select Microchip C18 Toolsuite
|
Make sure the compiler will search the C:\MCC18\lib directory. |
Project / Set Language Tool Locations...
From the list of Registered Tools, navigate into
Microchip C18 Toolsuite
Default Search Paths & Directories
Set the Library Search path $(LIBDIR) to "C:\MCC18\lib".
|
Configure the compiler to search our Microchip\Include directory. |
Project / Build Options...project
Select the Directories tab.
From the Show directories for drop-down box,
select Include Search Path .
Press New and enter the path "Microchip\Include"
From the Show directories for drop-down box,
select Library Search Path .
Press New and enter the path "C:\MCC18\lib"
|
Adding Files
Select View/Project to see the various parts of the project.
Earlier, we copied some file into the REPING project directory.
Now, we need to add these files to the project.
- Right click on the
Sources icon and select Add Files... .
Navigate to the REPING directory and add all the "*.c" files we copied earlier.
- Right click on the
Header Files icon and select Add Files... .
Add all of the "*.h" files we copied earlier.
- Right click on the
Linker icon and select Add Files... .
Add the rm18f4550.lkr file we copied earlier.
WARNING: If you don't use the linker file from the demo directory,
the program will not function!!!
- Right click on the
Sources icon and select Add Files... .
Navigate to the directory \Microchip\USB and add the file usb_device.c
Customizing
I had a lot of trouble reading the example code due to the many compiler directives.
Since we are using a custom board, most of the settings in the Hardware.h file don't really apply.
I replaced the contents of my Hardware.h file with the following:
Hardware.h
The main.c program has a configuration section marked by /** CONFIGURATION **/ .
This section attempts to determin the configuration for the board.
This configuration section can be replaced with the following:
main.c: /** Configuration **/
The user.c file is heavily modified. Here is the complete user.c file.
user.c
|