LED Blinking PIC16F877 Code + Proteus Simulation using xc8
This post is all about how to blink an LED using PIC16F877 an 8 bit microcontroller from microchip. This is very basic tutorial for beginners. Code example is provided in download link below.
In this post I assumed that you must know following if not then please read them before proceeding further:
1. How to use MPLAB X IDE (Click here).
2. How to set Configuration bits in code (Click here).
You may download code, schematic and Proteus simulation from the download section at the bottom of this page. I am using MPLAB X IDE, XC8 Compiler.
I used PIC16F877 with PIN RB0 connected to an LED. MCLR is connected to 5VDC which means Controller is in Normal Operating mode (see datasheet for further details). Proteus simulation shows that LED is toggling after one second as I am using building delay functions I have set Crystal frequency 10MHz. The circuit is shown in figure 1.
|Figure: 1. LED Blinking Proteus Simulation.|
This is the main code file showing the configuration bits area at the top and the main function in which I first make this pin as digital output by clearing tristate register then I toggled PIN RB0 (Remember this controller dose not have Latch register named LAT see datasheet for more details) after one second time delay. As shown in code. Remember using __delay_ms() function you must have to define operating frequency #define _XTAL_FREQ at top of main function otherwise it would give an error.
|Figure: 2. Code Example Mplab X IDE and XC8 compiler.|
You may download Code which is written in C language. Using MPLAB X IDE and compiler xc8 for 8 bit Microcontrollers. Click here
- GPS interfacing with PICmicrocontroller.
- How to interface 4x4 Keypad with PIC.
- Two wirelessly communicating Circuitsusing Xbee
- How to get interrupt on change oflogic on Pins (Input Change Notification).
- Over Voltage Protection
- Step by step home made PCB tutorial
- How to measure Negative and Positivetemperature using LM35
- AC Voltmeter RMS + Peak voltage
For all topics Click here
All the text and graphics contained on this page 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 2014 IbrahimLabs. All rights reserved.