Blink LED with PIC16F877A
In this tutorial, i will take you through the process of blinking an LED with PIC16F877A and i hope you have gone through my previous post on Getting started with MikroC pro for PIC Compiler if not, click here
A light-emitting diode (LED) is a semiconductor light source that emits light when current flows through it. LEDs are used in many electronic devices as indicator lamps, in automobiles as rear-window and brake lights, and on billboards and signs as alphanumeric displays or even full-colour posters.
There are two ways of connecting the LED with PIC16F877A which are:
- Current sinking mode
- Current souring mode
Materials Required:
PIC16F877A
22pf capacitors
10k resistor
330R resistor
LED
Crystal Oscillator
Connect the above circuit on your bread board and upload the code below into the microcontroller.
CODE:
/*
Name : BLINKING LEDWITH PIC16F877A
Author : DANIEL OLUWOLE
: (C) 2020 DANITRONICS.
: danitronics7@gmail.com, danieloluwole51@yahoo.com
: Mobile: +234 8188508765.
Notes this programme switches ON and OFF an LED connected to PORTD.0 every second.
Compiler : MikroC Pro for PIC
Target : PIC16F877A
*/
void main() { //program begins here
TRISD.B0 = 0; //set bit 0 of PORTD as output
do{
PORTD.B0 = 1; // turn ON LED on bit 0 of PORTD
delay_ms(1000); // wait for 1 second
PORTD.B0 = 0; // turn OFF LED on bit 0 of PORTD
delay_ms(1000); //wait for 1 second
} while(1) ; // loop this forever
}
Our next tutorial focuses on interfacing the PIC16F877A with a Switch.
0 Comments