Programming PIC Microcontroller Via USB
by Lithium-ion in Circuits > Microcontrollers
41 Views, 1 Favorites, 0 Comments
Programming PIC Microcontroller Via USB
.png)
Is the part 3 in the getting started with PIC series, I am here with a programming tutorial, without using a PIC KIT.
Supplies
Project Requirements:
PICKIT 3
PICKIT 3 software : For burning bootloader
Mikrobootloader Software : For Programming through USB
PICDUINO board from PCBWAY
USB type C cable
Story:

In the previous tutorial I have designed a PICDUINO board, all the hardware files are shared in that previous article. Today is the day to program this board through the USB port. I have used a PIC18F2550 which is an 8 bit microcontroller similar to an Arduino. It directly supports USB protocol without any interlink chip in between. Which is a great feature of it. Today we will use this feature and program the chip with a blink code. Choosing a blink sketch makes the process easy to learn.
Let me warn you one thing before getting started, that we can not directly use the USB to program the IC, for this we have to first burn the IC with a USB bootloader. Which is basically the same process carried out in the getting started tutorial with PIC kit 3. I will provide all the files, details and programming software links. Because we are new to PIC, I am here to just make the process easier for you.
This PIC series is sponsored by PCBWAY, A reliable and affordable PCB/PCBA manufacturer from CHINA. PCBWAY is one stop solution for all the prototyping needs. As the series continues we will order our development board from PCBWAY.
Uploading the USB Bootloader in PICDUINO:


Download the USB bootloader hex file from here, Connect the PICDUINO with PICKIT 3 using the wired diagram given here. Write the hex file in the program memory of PIC18F2550. To know the full process of writing a hex file to IC, see our getting started with PIC tutorial from here. After successfully writing the bootloader file in the chip now, we can program the chip using USB only. There is no need for PICKIT anymore. Let’s make a hex file of blink code and program it via USB.
Program for Blink in Assembly Language:
Now we need a compiler which converts this code (low level language) into machine level code (HEX format) . The proper procedure and software for this is given below. Download the HEX file from here.
Getting Hex File:




For the compiling of the code, and to convert the same into HEX. I am using MikroC Pro software. This one supports the whole family of PIC and is very easy to learn in the first go, if you are a beginner. Let’s convert the code into HEX in 4 steps.
- Download the software, make a new folder and set up a project in that as a standard project.
- Change the CPU clock as per the max clock the IC can work on, see in datasheet.
- Go to the edit project section, under the project tools menu. Under the general output setting tick export as hex.
- Build the file, It will make some at the project location in the same folder. We only need the Hex file to copy it from there to a safe location. And that is all what we need from the compiler.
Programming Via USB:




Here is the time for Mikrobootloader software, which basically acts as an interpreter for the USB device, and after selecting the HEX file we can directly upload the file. Here is the 5 step process: Download the Mikrobootloader software from here .
Step 1. Establish USB link: Connect your board to your PC. When the device is recognized by your OS the gray USB icon will turn red, indicating that the USB link is successfully established. You have 5s to proceed to the next step. If you wait too long the device will disconnect.
Step 2. Connect with MCU: Click on the Connect button within 5s. The chip automatically enters the Bootloader mode and is ready for further instructions. If your USB link disconnects, just reset the chip to reestablish the link. Then proceed with step 2 again.
Step 3. Choose HEX file: Time to choose blink.hex file, Load the program you want to upload into the chip by clicking on the Browse for HEX button or simply drag and drop your HEX on to mikroBootloader window. You’ll be notified in the History Window that the file is opened.
Step 4. Start Bootloader: Start bootloader by clicking on the Begin uploading button. You can monitor the bootloading process in the progress bar. After the process is completed, a new message window will inform you of the bootloading success.
Step 5. Reset chip: Bootloader firmware will automatically reset the MCU, after which you should wait 5s for your newly loaded program to start.
Working:


I follow all the steps. It will automatically detect the chip. And after uploading it will show “successfully uploaded”. In this way you can program your PICDUINO now. Which is a way easier method to program a microcontroller. Usually factor made chips do not come with pre-programmed USB bootloaders, hence there is always a need for PICKIT. Yet there are some cheaper options and clone boards available in the market. PICKIT 2 is open sourced, and the next tutorial is based on the same. So that we can make our own PICKIT 2 and program any chip in future.
Get your hands on custom PCB, from PCBWAY. Sign-up now using this link and get free PCB coupons for your first order. Explore PCB, PCBA, FLEX, STENCIL, CNC, 3D PRINTING and much more.