This post will provide a tutorial of how to blink LEDs connected with pins of PIC32. As we have 32bit microcontroller from Microchip. The reason why I wrote this post is to make you get started with PIC32. And never forget that every controller programing starts with a sample code of toggling PINS. I still check the hardware and programing by toggling all Pins at first (I think is a good practice). If you are familiar with other PIC baseline microcontrollers and worked on XC compilers series then you may skip this.
You may download code and schematic from the download section at the bottom of this page. I am using MPLAB X IDE, XC32 Compiler. This code is written in C Language and will work on all PIC32 (32bit microcontroller by Microchip) by slightly changing the code according to their features.
In this post I supposed that you know following if not then please read them before proceeding further in this post.
As this controller is not available for simulation in Proteus, therefore I go for practical simulation. So this is my custom designed PIC32 I/O board with necessary components on board and has a very small footprint as compare to my pervious DsPIC33 I/O board. I am using PIC32MX460F256L in this particular example. In this PIC32 I/O board I have five LEDs connected with the PortB0 ~ PortB4. A simple animation is shown in the following figure 1.
|Figure 1. Practical Simulation.|
As mentioned earlier in this post the code is written in C language using MPLAB X IDE and XC compiler and can be downloaded from the downloads section at the bottom of this page. In the following figure 2. We have a main C file in which I first initialize these 5 pins as output by clearing the Tristate register. Then I write 1 to these five pins. In a while loop I turn ON three Red LEDs and put two Blue LEDs OFF, by writing 1 and 0 to their corresponding pins respectively. After this I have a constant general delay. Remember my PIC32 is running at 80MHz that’s why delay is quite large as compared to DsPIC33. After this delay I Toggle the states of these five pins. This create a pattern for LEDs as shown in animation shown earlier in this post.
|Figure 2. Main Function.|
The schematic is also available in download section with code. In this schematic some of the basic connections recommended for running this code. The schematic is shown in following figure 3.
|Figure 3. Schematic PIC32 Led Blinking.|
You can download Code (MPLAB X and XC32 compiler Schematic is also given). Click here
For all topics Click here:
That’s all for this post hope you will learn please comment if you have any questions for upcoming posts please subscribe or follow.
All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission.
© Copyright 2013 IbrahimLabs. All rights reserved.