Getting started with PIC18F Microcontrollers

Summary of Getting started with PIC18F Microcontrollers


Summary: This article introduces using the StartUSB for PIC development board with the PIC18F2550 to move from PIC16F to enhanced PIC18F series. It explains board features (USB bootloader, miniUSB, crystal, LEDs, prototyping pads), required software (mikroC Pro for PIC and mikroBootloader), and provides a first test Hello World program that blinks two onboard LEDs alternately every 500 ms.

Parts used in the StartUSB for PIC project:

  • StartUSB for PIC development board (with PIC18F2550)
  • PIC18F2550 microcontroller (onboard)
  • miniUSB connector (onboard)
  • 8.0 MHz crystal oscillator (onboard)
  • Power indicator LED (onboard)
  • Two additional user LEDs connected to RA1 and RB1 (onboard)
  • Jumpers for LED connections (onboard)
  • Prototyping pads/areas (onboard)
  • mikroBootloader PC application (software)
  • mikroC Pro for PIC compiler (software)
After writing quite a bit of experimental tutorials on PIC16F series of microcontrollers, I thought of moving forward to the enhanced-range family of PIC microcontrollers, the PIC18F, which was introduced by Microchip in late 90s. Although PIC16F series are excellent general purpose microcontrollers, certain limitations have emerged, such as, they have limited program and data memory, their stack size is small, and all the interrupt sources have to share a single interrupt vector. Their limited instruction set also doesn’t provide direct support for more advanced peripherals interfaces like USB and CAN. The basis of the PIC18F Series is to address the issues that limit the PIC16F series. The PIC18F series of microcontrollers has larger instruction set, more memory, bigger stack, more external interrupts, higher speed, enhanced I/O port architecture, and many more features that we will be exploring in upcoming tutorials. I have decided that I am not going to spend much time on soldering and making my own prototyping board for PIC18F microcontroller as I did for PIC16F. I am going to use StartUSB for PIC board from mikroElektronika for writing these tutorials.
Getting started with PIC18F Microcontrollers

So what is StartUSB for PIC?

StartUSB for PIC is a small development board featuring PIC18F2550 microcontroller with fast USB 2.0 support. It features connection pads for all MCU pins, as well as two additional prototyping areas for placing additional components. The biggest advantage of this board is that the microcontroller comes preprogrammed with fast USB bootloader, and so there is no need of any external programmer. You can transfer your application related HEX file from PC to PIC’s program memory using mikroBootloader. MikroBootloader is the PC application developed by mikroElektronika for their USB HID Bootloader. On board miniUSB connector, oscillator (8.0 MHz crystal), reset circuit, power indicator LED, as well as two additional LEDs provide all you need for quick start. The two additional LEDs are connected to RA1 and RB1 pins of PIC18F2550 through jumpers. The picture above shows the StartUSB for PIC board with all the components and additional prototyping areas.

Today’s tutorial is important because we will discuss about a complete setup for StartUSB for PIC board that will let you start your journey into the world of PIC18F series microcontrollers. The first thing you need to install is mikroC Pro for PIC, which is a C compiler developed by mikroElektronika for PIC12, PIC16, and PIC18 series microcontrollers. You can download the demo version of this software that will allow you to compile programs up to 2 K of program words. Once you installed the compiler, download the mikroBootloader, which is PC’s application to communicate with the bootloader program stored inside the PIC18F2550 microcontroller on the StartUSB board.

The user’s manual for StartUSB board provides the circuit diagram of the board and instructions on how to connect it to PC for downloading the application HEX file using mikroBootloader. Please read these details in the manuals before proceeding forward.

Testing the board with “Hello World”

We will begin our journey with a simple test program that will make sure everything is setup correctly and we will be ready for doing more advanced experiments with PIC18F2550. This program will flash the two on-board LEDs (connected to RA1 and RB1 pins) alternately with 500 ms duration. In mikroC Pro for PIC, applications are developed in the form of projects. If you haven’t used mikroC Pro for PIC before, the document ‘Creating first project in mikroC Pro for PIC‘ from mikroElektronika will guide you to create your first project. While following those steps, select the microcontroller as PIC18F2550 and the device clock as 8.0 MHz. In the main program window, type in the following program.

/*
Test program for StartUSB for PIC board
Description : Two on board LEDs are flashed alternately in 500 ms
MCU: PIC18F2550, External crystal = 8.0 MHz, Actual Clock from PLL = 48.0 MHz
*/
//Define LED connections

Getting started with PIC18F Microcontrollers schematicsbit LED1 at RA1_bit;

sbit LED2 at RB1_bit;
void main() {
CMCON = 0×07;   // Disable comparators
ADCON1 = 0x0F;  // Disable Analog functions
TRISA = 0×00;
TRISB = 0×00;
LED1 = 0;
LED2 = 1;
do {
LED1 = ~LED1;
LED2 = ~LED2;
Delay_ms(500);
} while(1);}

 

For more detail: Getting started with PIC18F Microcontrollers

Quick Solutions to Questions related to StartUSB for PIC:

  • What is StartUSB for PIC?
    StartUSB for PIC is a small development board featuring the PIC18F2550 microcontroller with fast USB 2.0 support, onboard bootloader, miniUSB connector, oscillator, LEDs, and prototyping areas.
  • Do I need an external programmer to program the PIC18F2550 on StartUSB for PIC?
    No, the microcontroller comes preprogrammed with a fast USB bootloader so no external programmer is needed.
  • How do I transfer a HEX file to the StartUSB for PIC board?
    You transfer the application HEX file from PC to PIC program memory using the mikroBootloader PC application.
  • Which compiler is recommended for developing applications for StartUSB for PIC?
    mikroC Pro for PIC is recommended; it supports PIC12, PIC16, and PIC18 series.
  • What clock settings should I select when creating a project for PIC18F2550 in mikroC Pro for PIC?
    Select microcontroller PIC18F2550 and device clock as 8.0 MHz (external crystal).
  • Which pins are the two on-board LEDs connected to?
    The two additional LEDs are connected to RA1 and RB1 pins of PIC18F2550 through jumpers.
  • What does the provided Hello World test program do?
    The test program flashes the two on-board LEDs alternately with 500 ms duration.
  • What configuration settings are used in the example program to disable analog and comparator functions?
    The example sets CMCON = 0x07 to disable comparators and ADCON1 = 0x0F to disable analog functions.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter