Sie sind auf Seite 1von 10

Interfacing PIC16F887

to LED

Submitted to: Submitted by:


Dr. Mona Bhatnagar Shweta Goyal
Roll No.: 3025
LED Interfacing with Microcontroller

Interfacing comprises of hardware (Interface device) and Software (source code


to communicate i.e. driver).

LED is connected to Microcontroller port which is programmed inside to make


LED ON or OFF or blink or dim.

The driver software can be developed using any programming language like
Assembly, C etc.

Anode is connected through a resistor to GND & the Cathode is connected to


the Microcontroller pin. So when the Port Pin is HIGH the LED is OFF & ON
when LOW.

The resistor is important in LED interfacing to limit the flowing current and
avoid damaging the LED and/or MCU.
Interfacing LED with PIC16F887
The PIC16F Development Board has eight numbers of point LEDs, connected with I/O Port lines (PORTx.0 –
PORTx.7) to make port pins high. Here, we have connected LEDs with PORT B.

PIC CONNECTIONS:

LED.0 PORTx.0
LED.1 PORTx.1 Connect Any one PORT from LED’s will be turned
PORTA, PORTB, PORTC, ON and OFF at 500ms
LED.2 PORTx.2 PORTD with JP3 (LED interval.
LED.3 PORTx.3 Section) via FRC cable

LED.4 PORTx.4
LED.5 PORTx.5
LED.6 PORTx.6
LED.7 PORTx.7
CIRCUIT DIAGRAM:
The Interfacing LED with PIC16F877A program is very simple and straight forward, that uses a delay procedure loop
based software.

C PROGRAM CODE :

To compile this C code, we use MPLAB XDE software which


compiles this code in machine readable form called HEX code.

The HEX code is stored into the MCU in a place called Flash
memory.
CODE EXPLAINATION:
// library file

• This defines the oscillator frequency. The value 8000000 means its frequency is 8MHz.
• Assembly code is processed line by line. The speed at which is line is processed is the microcontroller's instruction cycle.

• TRI-State Register/ Data Direction Register.


• ‘0x’ represents hexadecimal number system. 0x00 makes all pins of Port B as output.
• It is an 8-bit register that determines the direction of GPIO pins i.e. general purpose Input/Output. Logic 1 at a
particular bit of TRIS register makes the corresponding pin ‘Input’ while Logic 0 at a particular bit makes the
corresponding pin ‘Output.’
• PORTB is also a register like TRISB. This register is used to read/write the data from/to port pins.
• It passes the value out of port B. This means PORTB=0x00 will give low output from each eight line of port B.
• This is equivalent to clearing of port B at the start from any stray values.

• The while loop will execute infinite times. The LEDs connected to PORTB will keep on blinking with 1 second delay
(1s=1000ms). This process is repeated until the program is aborted.
• This causes the blinking of the LED. The speed of the Blinking LED can be increased or decreased by varying the
delay value.

0xff will give high output from each eight line of Port B. This will assign input HIGH to Port B.
To have a delay of 1000ms. So high logic will pass from port B pins for 1000ms.

• This line will make the output from port B get down to 0V, i.e. logic ‘0’. It is to be considered that until the value in
PORTB is changed, the output from the port will also not change.
• So the output will drop from 5V (logic 1) to 0V (logic 0) only when this line is executed.

Again delay of 1000ms.


End
The HEX file generated is stored in the location Your Project Folder >> dist >> default >> production in MPLAB

Exporting Hex File


The above generated hex file does not contain Configuration Bits, we should use the Export option in MPLAB to export
the hex file with configuration bits.
• Click on File >> Export.
• Click OK.
• Give the file name and Click Save.
• Now burn this exported hex file to the microcontroller.

Output:
LED will be turned OFF and ON in the interval of 1 sec.
THE END

Das könnte Ihnen auch gefallen