Getting started with PIC18F Microcontrollers

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;
} while(1);}


For more detail: Getting started with PIC18F Microcontrollers

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:

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.